We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
ax param ignored in feature_correlation quick method
**Describe the bug**
When using matplotlib subplots create 2 plots of feature correlations side by side, the ax parameter seems to be ignored  and two images are created.

![image1](https://user-images.githubusercontent.com/3305726/109315893-cc35c400-7829-11eb-8453-de098ae7f375.png)
![image2](https://user-images.githubusercontent.com/3305726/109315930-d3f56880-7829-11eb-9f3f-75b4977dcac4.png)

**To Reproduce**

```python
import numpy as np
from sklearn import datasets
import matplotlib.pyplot as plt
from yellowbrick.target.feature_correlation import feature_correlation

#Load the diabetes dataset
data = datasets.load_iris()
X, y = data['data'], data['target']

features = np.array(data['feature_names'])

_, axes = plt.subplots(ncols=2, figsize=(18, 6))

feature_correlation(X, y, labels=features, method='pearson', ax=axes[0])
feature_correlation(X, y, labels=features, method='mutual_info-classification', ax=axes[1])

plt.tight_layout()
```

**Expected behavior**
The expected behaviour would be the plots side by side in a single image.


**Desktop (please complete the following information):**
 - OS: macOS
 - Python Version: Python 3.7.10 (Google Colab)
 - Yellowbrick Version: 1.3.post1

**Additional context**
I can confirm it happens also locally with `Yellowbrick 1.3.post1` running using command line and using jupyter notebooks


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `yellowbrick/target/feature_correlation.py`
Content:
```
1 # yellowbrick.classifier.feature_correlation
2 # Feature correlation to dependent variable visualizer.
3 #
4 # Author    Zijie (ZJ) Poh
5 # Created:  Wed Jul 29 15:30:40 2018 -0700
6 #
7 # Copyright (C) 2018 The scikit-yb developers
8 # For license information, see LICENSE.txt
9 #
10 # ID: feature_correlation.py [33aec16] 8103276+zjpoh@users.noreply.github.com $
11 
12 """
13 Feature Correlation to Dependent Variable Visualizer.
14 """
15 
16 ##########################################################################
17 # Imports
18 ##########################################################################
19 
20 import numpy as np
21 
22 from yellowbrick.utils import is_dataframe
23 from yellowbrick.target.base import TargetVisualizer
24 from yellowbrick.exceptions import YellowbrickValueError, YellowbrickWarning
25 
26 from sklearn.feature_selection import mutual_info_classif
27 from sklearn.feature_selection import mutual_info_regression
28 
29 from scipy.stats import pearsonr
30 
31 ##########################################################################
32 # Supported Correlation Computations
33 ##########################################################################
34 
35 CORRELATION_LABELS = {
36     "pearson": "Pearson Correlation",
37     "mutual_info-regression": "Mutual Information",
38     "mutual_info-classification": "Mutual Information",
39 }
40 
41 CORRELATION_METHODS = {
42     "mutual_info-regression": mutual_info_regression,
43     "mutual_info-classification": mutual_info_classif,
44 }
45 
46 ##########################################################################
47 # Class Feature Correlation
48 ##########################################################################
49 
50 
51 class FeatureCorrelation(TargetVisualizer):
52     """
53     Displays the correlation between features and dependent variables.
54 
55     This visualizer can be used side-by-side with
56     ``yellowbrick.features.JointPlotVisualizer`` that plots a feature
57     against the target and shows the distribution of each via a
58     histogram on each axis.
59 
60     Parameters
61     ----------
62     ax : matplotlib Axes, default: None
63         The axis to plot the figure on. If None is passed in the current axes
64         will be used (or generated if required).
65 
66     method : str, default: 'pearson'
67         The method to calculate correlation between features and target.
68         Options include:
69 
70             - 'pearson', which uses ``scipy.stats.pearsonr``
71             - 'mutual_info-regression', which uses ``mutual_info-regression``
72               from ``sklearn.feature_selection``
73             - 'mutual_info-classification', which uses ``mutual_info_classif``
74               from ``sklearn.feature_selection``
75 
76     labels : list, default: None
77         A list of feature names to use. If a DataFrame is passed to fit and
78         features is None, feature names are selected as the column names.
79 
80     sort : boolean, default: False
81         If false, the features are are not sorted in the plot; otherwise
82         features are sorted in ascending order of correlation.
83 
84     feature_index : list,
85         A list of feature index to include in the plot.
86 
87     feature_names : list of feature names
88         A list of feature names to include in the plot.
89         Must have labels or the fitted data is a DataFrame with column names.
90         If feature_index is provided, feature_names will be ignored.
91 
92     color: string
93         Specify color for barchart
94 
95     kwargs : dict
96         Keyword arguments that are passed to the base class and may influence
97         the visualization as defined in other Visualizers.
98 
99     Attributes
100     ----------
101     features_ : np.array
102         The feature labels
103 
104     scores_ : np.array
105         Correlation between features and dependent variable.
106 
107     Examples
108     --------
109 
110     >>> viz = FeatureCorrelation()
111     >>> viz.fit(X, y)
112     >>> viz.show()
113     """
114 
115     def __init__(
116         self,
117         ax=None,
118         method="pearson",
119         labels=None,
120         sort=False,
121         feature_index=None,
122         feature_names=None,
123         color=None,
124         **kwargs
125     ):
126         super(FeatureCorrelation, self).__init__(ax=None, **kwargs)
127 
128         self.correlation_labels = CORRELATION_LABELS
129         self.correlation_methods = CORRELATION_METHODS
130 
131         if method not in self.correlation_labels:
132             raise YellowbrickValueError(
133                 "Method {} not implement; choose from {}".format(
134                     method, ", ".join(self.correlation_labels)
135                 )
136             )
137 
138         # Parameters
139         self.sort = sort
140         self.color = color
141         self.method = method
142         self.labels = labels
143         self.feature_index = feature_index
144         self.feature_names = feature_names
145 
146     def fit(self, X, y, **kwargs):
147         """
148         Fits the estimator to calculate feature correlation to
149         dependent variable.
150 
151         Parameters
152         ----------
153         X : ndarray or DataFrame of shape n x m
154             A matrix of n instances with m features
155 
156         y : ndarray or Series of length n
157             An array or series of target or class values
158 
159         kwargs : dict
160             Keyword arguments passed to the fit method of the estimator.
161 
162         Returns
163         -------
164         self : visualizer
165             The fit method must always return self to support pipelines.
166         """
167         self._create_labels_for_features(X)
168 
169         self._select_features_to_plot(X)
170 
171         # Calculate Features correlation with target variable
172         if self.method == "pearson":
173             self.scores_ = np.array(
174                 [pearsonr(x, y, **kwargs)[0] for x in np.asarray(X).T]
175             )
176         else:
177             self.scores_ = np.array(
178                 self.correlation_methods[self.method](X, y, **kwargs)
179             )
180 
181         # If feature indices are given, plot only the given features
182         if self.feature_index:
183             self.scores_ = self.scores_[self.feature_index]
184             self.features_ = self.features_[self.feature_index]
185 
186         # Sort features by correlation
187         if self.sort:
188             sort_idx = np.argsort(self.scores_)
189             self.scores_ = self.scores_[sort_idx]
190             self.features_ = self.features_[sort_idx]
191 
192         self.draw()
193         return self
194 
195     def draw(self):
196         """
197         Draws the feature correlation to dependent variable, called from fit.
198         """
199         pos = np.arange(self.scores_.shape[0]) + 0.5
200 
201         self.ax.barh(pos, self.scores_, color=self.color)
202 
203         # Set the labels for the bars
204         self.ax.set_yticks(pos)
205         self.ax.set_yticklabels(self.features_)
206 
207         return self.ax
208 
209     def finalize(self):
210         """
211         Finalize the drawing setting labels and title.
212         """
213         self.set_title("Features correlation with dependent variable")
214 
215         self.ax.set_xlabel(self.correlation_labels[self.method])
216 
217         self.ax.grid(False, axis="y")
218 
219     def _create_labels_for_features(self, X):
220         """
221         Create labels for the features
222 
223         NOTE: this code is duplicated from MultiFeatureVisualizer
224         """
225         if self.labels is None:
226             # Use column names if a dataframe
227             if is_dataframe(X):
228                 self.features_ = np.array(X.columns)
229             # Otherwise use the column index as the labels
230             else:
231                 _, ncols = X.shape
232                 self.features_ = np.arange(0, ncols)
233         else:
234             self.features_ = np.array(self.labels)
235 
236     def _select_features_to_plot(self, X):
237         """
238         Select features to plot.
239 
240         feature_index is always used as the filter and
241         if filter_names is supplied, a new feature_index
242         is computed from those names.
243         """
244         if self.feature_index:
245             if self.feature_names:
246                 raise YellowbrickWarning(
247                     "Both feature_index and feature_names "
248                     "are specified. feature_names is ignored"
249                 )
250             if min(self.feature_index) < 0 or max(self.feature_index) >= X.shape[1]:
251                 raise YellowbrickValueError("Feature index is out of range")
252         elif self.feature_names:
253             self.feature_index = []
254             features_list = self.features_.tolist()
255             for feature_name in self.feature_names:
256                 try:
257                     self.feature_index.append(features_list.index(feature_name))
258                 except ValueError:
259                     raise YellowbrickValueError("{} not in labels".format(feature_name))
260 
261 
262 ##########################################################################
263 # Quick Method
264 ##########################################################################
265 
266 
267 def feature_correlation(
268     X,
269     y,
270     ax=None,
271     method="pearson",
272     labels=None,
273     sort=False,
274     feature_index=None,
275     feature_names=None,
276     color=None,
277     show=True,
278     **kwargs
279 ):
280     """
281     Displays the correlation between features and dependent variables.
282 
283     This visualizer can be used side-by-side with
284     yellowbrick.features.JointPlotVisualizer that plots a feature
285     against the target and shows the distribution of each via a
286     histogram on each axis.
287 
288     Parameters
289     ----------
290     X : ndarray or DataFrame of shape n x m
291         A matrix of n instances with m features
292 
293     y : ndarray or Series of length n
294         An array or series of target or class values
295 
296     ax : matplotlib Axes, default: None
297         The axis to plot the figure on. If None is passed in the current axes
298         will be used (or generated if required).
299 
300     method : str, default: 'pearson'
301         The method to calculate correlation between features and target.
302         Options include:
303 
304             - 'pearson', which uses ``scipy.stats.pearsonr``
305             - 'mutual_info-regression', which uses ``mutual_info-regression``
306               from ``sklearn.feature_selection``
307             - 'mutual_info-classification', which uses ``mutual_info_classif``
308               from ``sklearn.feature_selection``
309 
310     labels : list, default: None
311         A list of feature names to use. If a DataFrame is passed to fit and
312         features is None, feature names are selected as the column names.
313 
314     sort : boolean, default: False
315         If false, the features are are not sorted in the plot; otherwise
316         features are sorted in ascending order of correlation.
317 
318     feature_index : list,
319         A list of feature index to include in the plot.
320 
321     feature_names : list of feature names
322         A list of feature names to include in the plot.
323         Must have labels or the fitted data is a DataFrame with column names.
324         If feature_index is provided, feature_names will be ignored.
325 
326     color: string
327         Specify color for barchart
328 
329     show: bool, default: True
330         If True, calls ``show()``, which in turn calls ``plt.show()`` however you cannot
331         call ``plt.savefig`` from this signature, nor ``clear_figure``. If False, simply
332         calls ``finalize()``
333 
334     kwargs : dict
335         Keyword arguments that are passed to the base class and may influence
336         the visualization as defined in other Visualizers.
337 
338     Returns
339     -------
340     visualizer : FeatureCorrelation
341         Returns the fitted visualizer.
342     """
343 
344     # Instantiate the visualizer
345     visualizer = FeatureCorrelation(
346         ax=ax,
347         method=method,
348         labels=labels,
349         sort=sort,
350         color=color,
351         feature_index=feature_index,
352         feature_names=feature_names,
353         **kwargs
354     )
355 
356     # Fit and transform the visualizer (calls draw)
357     visualizer.fit(X, y, **kwargs)
358     if show:
359         visualizer.show()
360     else:
361         visualizer.finalize()
362 
363     # Return the visualizer
364     return visualizer
365
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/yellowbrick/target/feature_correlation.py b/yellowbrick/target/feature_correlation.py
--- a/yellowbrick/target/feature_correlation.py
+++ b/yellowbrick/target/feature_correlation.py
@@ -123,7 +123,7 @@
         color=None,
         **kwargs
     ):
-        super(FeatureCorrelation, self).__init__(ax=None, **kwargs)
+        super(FeatureCorrelation, self).__init__(ax, **kwargs)
 
         self.correlation_labels = CORRELATION_LABELS
         self.correlation_methods = CORRELATION_METHODS

{"golden_diff": "diff --git a/yellowbrick/target/feature_correlation.py b/yellowbrick/target/feature_correlation.py\n--- a/yellowbrick/target/feature_correlation.py\n+++ b/yellowbrick/target/feature_correlation.py\n@@ -123,7 +123,7 @@\n         color=None,\n         **kwargs\n     ):\n-        super(FeatureCorrelation, self).__init__(ax=None, **kwargs)\n+        super(FeatureCorrelation, self).__init__(ax, **kwargs)\n \n         self.correlation_labels = CORRELATION_LABELS\n         self.correlation_methods = CORRELATION_METHODS\n", "issue": "ax param ignored in feature_correlation quick method\n**Describe the bug**\r\nWhen using matplotlib subplots create 2 plots of feature correlations side by side, the ax parameter seems to be ignored  and two images are created.\r\n\r\n![image1](https://user-images.githubusercontent.com/3305726/109315893-cc35c400-7829-11eb-8453-de098ae7f375.png)\r\n![image2](https://user-images.githubusercontent.com/3305726/109315930-d3f56880-7829-11eb-9f3f-75b4977dcac4.png)\r\n\r\n**To Reproduce**\r\n\r\n```python\r\nimport numpy as np\r\nfrom sklearn import datasets\r\nimport matplotlib.pyplot as plt\r\nfrom yellowbrick.target.feature_correlation import feature_correlation\r\n\r\n#Load the diabetes dataset\r\ndata = datasets.load_iris()\r\nX, y = data['data'], data['target']\r\n\r\nfeatures = np.array(data['feature_names'])\r\n\r\n_, axes = plt.subplots(ncols=2, figsize=(18, 6))\r\n\r\nfeature_correlation(X, y, labels=features, method='pearson', ax=axes[0])\r\nfeature_correlation(X, y, labels=features, method='mutual_info-classification', ax=axes[1])\r\n\r\nplt.tight_layout()\r\n```\r\n\r\n**Expected behavior**\r\nThe expected behaviour would be the plots side by side in a single image.\r\n\r\n\r\n**Desktop (please complete the following information):**\r\n - OS: macOS\r\n - Python Version: Python 3.7.10 (Google Colab)\r\n - Yellowbrick Version: 1.3.post1\r\n\r\n**Additional context**\r\nI can confirm it happens also locally with `Yellowbrick 1.3.post1` running using command line and using jupyter notebooks\r\n\n", "before_files": [{"content": "# yellowbrick.classifier.feature_correlation\n# Feature correlation to dependent variable visualizer.\n#\n# Author    Zijie (ZJ) Poh\n# Created:  Wed Jul 29 15:30:40 2018 -0700\n#\n# Copyright (C) 2018 The scikit-yb developers\n# For license information, see LICENSE.txt\n#\n# ID: feature_correlation.py [33aec16] 8103276+zjpoh@users.noreply.github.com $\n\n\"\"\"\nFeature Correlation to Dependent Variable Visualizer.\n\"\"\"\n\n##########################################################################\n# Imports\n##########################################################################\n\nimport numpy as np\n\nfrom yellowbrick.utils import is_dataframe\nfrom yellowbrick.target.base import TargetVisualizer\nfrom yellowbrick.exceptions import YellowbrickValueError, YellowbrickWarning\n\nfrom sklearn.feature_selection import mutual_info_classif\nfrom sklearn.feature_selection import mutual_info_regression\n\nfrom scipy.stats import pearsonr\n\n##########################################################################\n# Supported Correlation Computations\n##########################################################################\n\nCORRELATION_LABELS = {\n    \"pearson\": \"Pearson Correlation\",\n    \"mutual_info-regression\": \"Mutual Information\",\n    \"mutual_info-classification\": \"Mutual Information\",\n}\n\nCORRELATION_METHODS = {\n    \"mutual_info-regression\": mutual_info_regression,\n    \"mutual_info-classification\": mutual_info_classif,\n}\n\n##########################################################################\n# Class Feature Correlation\n##########################################################################\n\n\nclass FeatureCorrelation(TargetVisualizer):\n    \"\"\"\n    Displays the correlation between features and dependent variables.\n\n    This visualizer can be used side-by-side with\n    ``yellowbrick.features.JointPlotVisualizer`` that plots a feature\n    against the target and shows the distribution of each via a\n    histogram on each axis.\n\n    Parameters\n    ----------\n    ax : matplotlib Axes, default: None\n        The axis to plot the figure on. If None is passed in the current axes\n        will be used (or generated if required).\n\n    method : str, default: 'pearson'\n        The method to calculate correlation between features and target.\n        Options include:\n\n            - 'pearson', which uses ``scipy.stats.pearsonr``\n            - 'mutual_info-regression', which uses ``mutual_info-regression``\n              from ``sklearn.feature_selection``\n            - 'mutual_info-classification', which uses ``mutual_info_classif``\n              from ``sklearn.feature_selection``\n\n    labels : list, default: None\n        A list of feature names to use. If a DataFrame is passed to fit and\n        features is None, feature names are selected as the column names.\n\n    sort : boolean, default: False\n        If false, the features are are not sorted in the plot; otherwise\n        features are sorted in ascending order of correlation.\n\n    feature_index : list,\n        A list of feature index to include in the plot.\n\n    feature_names : list of feature names\n        A list of feature names to include in the plot.\n        Must have labels or the fitted data is a DataFrame with column names.\n        If feature_index is provided, feature_names will be ignored.\n\n    color: string\n        Specify color for barchart\n\n    kwargs : dict\n        Keyword arguments that are passed to the base class and may influence\n        the visualization as defined in other Visualizers.\n\n    Attributes\n    ----------\n    features_ : np.array\n        The feature labels\n\n    scores_ : np.array\n        Correlation between features and dependent variable.\n\n    Examples\n    --------\n\n    >>> viz = FeatureCorrelation()\n    >>> viz.fit(X, y)\n    >>> viz.show()\n    \"\"\"\n\n    def __init__(\n        self,\n        ax=None,\n        method=\"pearson\",\n        labels=None,\n        sort=False,\n        feature_index=None,\n        feature_names=None,\n        color=None,\n        **kwargs\n    ):\n        super(FeatureCorrelation, self).__init__(ax=None, **kwargs)\n\n        self.correlation_labels = CORRELATION_LABELS\n        self.correlation_methods = CORRELATION_METHODS\n\n        if method not in self.correlation_labels:\n            raise YellowbrickValueError(\n                \"Method {} not implement; choose from {}\".format(\n                    method, \", \".join(self.correlation_labels)\n                )\n            )\n\n        # Parameters\n        self.sort = sort\n        self.color = color\n        self.method = method\n        self.labels = labels\n        self.feature_index = feature_index\n        self.feature_names = feature_names\n\n    def fit(self, X, y, **kwargs):\n        \"\"\"\n        Fits the estimator to calculate feature correlation to\n        dependent variable.\n\n        Parameters\n        ----------\n        X : ndarray or DataFrame of shape n x m\n            A matrix of n instances with m features\n\n        y : ndarray or Series of length n\n            An array or series of target or class values\n\n        kwargs : dict\n            Keyword arguments passed to the fit method of the estimator.\n\n        Returns\n        -------\n        self : visualizer\n            The fit method must always return self to support pipelines.\n        \"\"\"\n        self._create_labels_for_features(X)\n\n        self._select_features_to_plot(X)\n\n        # Calculate Features correlation with target variable\n        if self.method == \"pearson\":\n            self.scores_ = np.array(\n                [pearsonr(x, y, **kwargs)[0] for x in np.asarray(X).T]\n            )\n        else:\n            self.scores_ = np.array(\n                self.correlation_methods[self.method](X, y, **kwargs)\n            )\n\n        # If feature indices are given, plot only the given features\n        if self.feature_index:\n            self.scores_ = self.scores_[self.feature_index]\n            self.features_ = self.features_[self.feature_index]\n\n        # Sort features by correlation\n        if self.sort:\n            sort_idx = np.argsort(self.scores_)\n            self.scores_ = self.scores_[sort_idx]\n            self.features_ = self.features_[sort_idx]\n\n        self.draw()\n        return self\n\n    def draw(self):\n        \"\"\"\n        Draws the feature correlation to dependent variable, called from fit.\n        \"\"\"\n        pos = np.arange(self.scores_.shape[0]) + 0.5\n\n        self.ax.barh(pos, self.scores_, color=self.color)\n\n        # Set the labels for the bars\n        self.ax.set_yticks(pos)\n        self.ax.set_yticklabels(self.features_)\n\n        return self.ax\n\n    def finalize(self):\n        \"\"\"\n        Finalize the drawing setting labels and title.\n        \"\"\"\n        self.set_title(\"Features correlation with dependent variable\")\n\n        self.ax.set_xlabel(self.correlation_labels[self.method])\n\n        self.ax.grid(False, axis=\"y\")\n\n    def _create_labels_for_features(self, X):\n        \"\"\"\n        Create labels for the features\n\n        NOTE: this code is duplicated from MultiFeatureVisualizer\n        \"\"\"\n        if self.labels is None:\n            # Use column names if a dataframe\n            if is_dataframe(X):\n                self.features_ = np.array(X.columns)\n            # Otherwise use the column index as the labels\n            else:\n                _, ncols = X.shape\n                self.features_ = np.arange(0, ncols)\n        else:\n            self.features_ = np.array(self.labels)\n\n    def _select_features_to_plot(self, X):\n        \"\"\"\n        Select features to plot.\n\n        feature_index is always used as the filter and\n        if filter_names is supplied, a new feature_index\n        is computed from those names.\n        \"\"\"\n        if self.feature_index:\n            if self.feature_names:\n                raise YellowbrickWarning(\n                    \"Both feature_index and feature_names \"\n                    \"are specified. feature_names is ignored\"\n                )\n            if min(self.feature_index) < 0 or max(self.feature_index) >= X.shape[1]:\n                raise YellowbrickValueError(\"Feature index is out of range\")\n        elif self.feature_names:\n            self.feature_index = []\n            features_list = self.features_.tolist()\n            for feature_name in self.feature_names:\n                try:\n                    self.feature_index.append(features_list.index(feature_name))\n                except ValueError:\n                    raise YellowbrickValueError(\"{} not in labels\".format(feature_name))\n\n\n##########################################################################\n# Quick Method\n##########################################################################\n\n\ndef feature_correlation(\n    X,\n    y,\n    ax=None,\n    method=\"pearson\",\n    labels=None,\n    sort=False,\n    feature_index=None,\n    feature_names=None,\n    color=None,\n    show=True,\n    **kwargs\n):\n    \"\"\"\n    Displays the correlation between features and dependent variables.\n\n    This visualizer can be used side-by-side with\n    yellowbrick.features.JointPlotVisualizer that plots a feature\n    against the target and shows the distribution of each via a\n    histogram on each axis.\n\n    Parameters\n    ----------\n    X : ndarray or DataFrame of shape n x m\n        A matrix of n instances with m features\n\n    y : ndarray or Series of length n\n        An array or series of target or class values\n\n    ax : matplotlib Axes, default: None\n        The axis to plot the figure on. If None is passed in the current axes\n        will be used (or generated if required).\n\n    method : str, default: 'pearson'\n        The method to calculate correlation between features and target.\n        Options include:\n\n            - 'pearson', which uses ``scipy.stats.pearsonr``\n            - 'mutual_info-regression', which uses ``mutual_info-regression``\n              from ``sklearn.feature_selection``\n            - 'mutual_info-classification', which uses ``mutual_info_classif``\n              from ``sklearn.feature_selection``\n\n    labels : list, default: None\n        A list of feature names to use. If a DataFrame is passed to fit and\n        features is None, feature names are selected as the column names.\n\n    sort : boolean, default: False\n        If false, the features are are not sorted in the plot; otherwise\n        features are sorted in ascending order of correlation.\n\n    feature_index : list,\n        A list of feature index to include in the plot.\n\n    feature_names : list of feature names\n        A list of feature names to include in the plot.\n        Must have labels or the fitted data is a DataFrame with column names.\n        If feature_index is provided, feature_names will be ignored.\n\n    color: string\n        Specify color for barchart\n\n    show: bool, default: True\n        If True, calls ``show()``, which in turn calls ``plt.show()`` however you cannot\n        call ``plt.savefig`` from this signature, nor ``clear_figure``. If False, simply\n        calls ``finalize()``\n\n    kwargs : dict\n        Keyword arguments that are passed to the base class and may influence\n        the visualization as defined in other Visualizers.\n\n    Returns\n    -------\n    visualizer : FeatureCorrelation\n        Returns the fitted visualizer.\n    \"\"\"\n\n    # Instantiate the visualizer\n    visualizer = FeatureCorrelation(\n        ax=ax,\n        method=method,\n        labels=labels,\n        sort=sort,\n        color=color,\n        feature_index=feature_index,\n        feature_names=feature_names,\n        **kwargs\n    )\n\n    # Fit and transform the visualizer (calls draw)\n    visualizer.fit(X, y, **kwargs)\n    if show:\n        visualizer.show()\n    else:\n        visualizer.finalize()\n\n    # Return the visualizer\n    return visualizer\n", "path": "yellowbrick/target/feature_correlation.py"}], "after_files": [{"content": "# yellowbrick.classifier.feature_correlation\n# Feature correlation to dependent variable visualizer.\n#\n# Author    Zijie (ZJ) Poh\n# Created:  Wed Jul 29 15:30:40 2018 -0700\n#\n# Copyright (C) 2018 The scikit-yb developers\n# For license information, see LICENSE.txt\n#\n# ID: feature_correlation.py [33aec16] 8103276+zjpoh@users.noreply.github.com $\n\n\"\"\"\nFeature Correlation to Dependent Variable Visualizer.\n\"\"\"\n\n##########################################################################\n# Imports\n##########################################################################\n\nimport numpy as np\n\nfrom yellowbrick.utils import is_dataframe\nfrom yellowbrick.target.base import TargetVisualizer\nfrom yellowbrick.exceptions import YellowbrickValueError, YellowbrickWarning\n\nfrom sklearn.feature_selection import mutual_info_classif\nfrom sklearn.feature_selection import mutual_info_regression\n\nfrom scipy.stats import pearsonr\n\n##########################################################################\n# Supported Correlation Computations\n##########################################################################\n\nCORRELATION_LABELS = {\n    \"pearson\": \"Pearson Correlation\",\n    \"mutual_info-regression\": \"Mutual Information\",\n    \"mutual_info-classification\": \"Mutual Information\",\n}\n\nCORRELATION_METHODS = {\n    \"mutual_info-regression\": mutual_info_regression,\n    \"mutual_info-classification\": mutual_info_classif,\n}\n\n##########################################################################\n# Class Feature Correlation\n##########################################################################\n\n\nclass FeatureCorrelation(TargetVisualizer):\n    \"\"\"\n    Displays the correlation between features and dependent variables.\n\n    This visualizer can be used side-by-side with\n    ``yellowbrick.features.JointPlotVisualizer`` that plots a feature\n    against the target and shows the distribution of each via a\n    histogram on each axis.\n\n    Parameters\n    ----------\n    ax : matplotlib Axes, default: None\n        The axis to plot the figure on. If None is passed in the current axes\n        will be used (or generated if required).\n\n    method : str, default: 'pearson'\n        The method to calculate correlation between features and target.\n        Options include:\n\n            - 'pearson', which uses ``scipy.stats.pearsonr``\n            - 'mutual_info-regression', which uses ``mutual_info-regression``\n              from ``sklearn.feature_selection``\n            - 'mutual_info-classification', which uses ``mutual_info_classif``\n              from ``sklearn.feature_selection``\n\n    labels : list, default: None\n        A list of feature names to use. If a DataFrame is passed to fit and\n        features is None, feature names are selected as the column names.\n\n    sort : boolean, default: False\n        If false, the features are are not sorted in the plot; otherwise\n        features are sorted in ascending order of correlation.\n\n    feature_index : list,\n        A list of feature index to include in the plot.\n\n    feature_names : list of feature names\n        A list of feature names to include in the plot.\n        Must have labels or the fitted data is a DataFrame with column names.\n        If feature_index is provided, feature_names will be ignored.\n\n    color: string\n        Specify color for barchart\n\n    kwargs : dict\n        Keyword arguments that are passed to the base class and may influence\n        the visualization as defined in other Visualizers.\n\n    Attributes\n    ----------\n    features_ : np.array\n        The feature labels\n\n    scores_ : np.array\n        Correlation between features and dependent variable.\n\n    Examples\n    --------\n\n    >>> viz = FeatureCorrelation()\n    >>> viz.fit(X, y)\n    >>> viz.show()\n    \"\"\"\n\n    def __init__(\n        self,\n        ax=None,\n        method=\"pearson\",\n        labels=None,\n        sort=False,\n        feature_index=None,\n        feature_names=None,\n        color=None,\n        **kwargs\n    ):\n        super(FeatureCorrelation, self).__init__(ax, **kwargs)\n\n        self.correlation_labels = CORRELATION_LABELS\n        self.correlation_methods = CORRELATION_METHODS\n\n        if method not in self.correlation_labels:\n            raise YellowbrickValueError(\n                \"Method {} not implement; choose from {}\".format(\n                    method, \", \".join(self.correlation_labels)\n                )\n            )\n\n        # Parameters\n        self.sort = sort\n        self.color = color\n        self.method = method\n        self.labels = labels\n        self.feature_index = feature_index\n        self.feature_names = feature_names\n\n    def fit(self, X, y, **kwargs):\n        \"\"\"\n        Fits the estimator to calculate feature correlation to\n        dependent variable.\n\n        Parameters\n        ----------\n        X : ndarray or DataFrame of shape n x m\n            A matrix of n instances with m features\n\n        y : ndarray or Series of length n\n            An array or series of target or class values\n\n        kwargs : dict\n            Keyword arguments passed to the fit method of the estimator.\n\n        Returns\n        -------\n        self : visualizer\n            The fit method must always return self to support pipelines.\n        \"\"\"\n        self._create_labels_for_features(X)\n\n        self._select_features_to_plot(X)\n\n        # Calculate Features correlation with target variable\n        if self.method == \"pearson\":\n            self.scores_ = np.array(\n                [pearsonr(x, y, **kwargs)[0] for x in np.asarray(X).T]\n            )\n        else:\n            self.scores_ = np.array(\n                self.correlation_methods[self.method](X, y, **kwargs)\n            )\n\n        # If feature indices are given, plot only the given features\n        if self.feature_index:\n            self.scores_ = self.scores_[self.feature_index]\n            self.features_ = self.features_[self.feature_index]\n\n        # Sort features by correlation\n        if self.sort:\n            sort_idx = np.argsort(self.scores_)\n            self.scores_ = self.scores_[sort_idx]\n            self.features_ = self.features_[sort_idx]\n\n        self.draw()\n        return self\n\n    def draw(self):\n        \"\"\"\n        Draws the feature correlation to dependent variable, called from fit.\n        \"\"\"\n        pos = np.arange(self.scores_.shape[0]) + 0.5\n\n        self.ax.barh(pos, self.scores_, color=self.color)\n\n        # Set the labels for the bars\n        self.ax.set_yticks(pos)\n        self.ax.set_yticklabels(self.features_)\n\n        return self.ax\n\n    def finalize(self):\n        \"\"\"\n        Finalize the drawing setting labels and title.\n        \"\"\"\n        self.set_title(\"Features correlation with dependent variable\")\n\n        self.ax.set_xlabel(self.correlation_labels[self.method])\n\n        self.ax.grid(False, axis=\"y\")\n\n    def _create_labels_for_features(self, X):\n        \"\"\"\n        Create labels for the features\n\n        NOTE: this code is duplicated from MultiFeatureVisualizer\n        \"\"\"\n        if self.labels is None:\n            # Use column names if a dataframe\n            if is_dataframe(X):\n                self.features_ = np.array(X.columns)\n            # Otherwise use the column index as the labels\n            else:\n                _, ncols = X.shape\n                self.features_ = np.arange(0, ncols)\n        else:\n            self.features_ = np.array(self.labels)\n\n    def _select_features_to_plot(self, X):\n        \"\"\"\n        Select features to plot.\n\n        feature_index is always used as the filter and\n        if filter_names is supplied, a new feature_index\n        is computed from those names.\n        \"\"\"\n        if self.feature_index:\n            if self.feature_names:\n                raise YellowbrickWarning(\n                    \"Both feature_index and feature_names \"\n                    \"are specified. feature_names is ignored\"\n                )\n            if min(self.feature_index) < 0 or max(self.feature_index) >= X.shape[1]:\n                raise YellowbrickValueError(\"Feature index is out of range\")\n        elif self.feature_names:\n            self.feature_index = []\n            features_list = self.features_.tolist()\n            for feature_name in self.feature_names:\n                try:\n                    self.feature_index.append(features_list.index(feature_name))\n                except ValueError:\n                    raise YellowbrickValueError(\"{} not in labels\".format(feature_name))\n\n\n##########################################################################\n# Quick Method\n##########################################################################\n\n\ndef feature_correlation(\n    X,\n    y,\n    ax=None,\n    method=\"pearson\",\n    labels=None,\n    sort=False,\n    feature_index=None,\n    feature_names=None,\n    color=None,\n    show=True,\n    **kwargs\n):\n    \"\"\"\n    Displays the correlation between features and dependent variables.\n\n    This visualizer can be used side-by-side with\n    yellowbrick.features.JointPlotVisualizer that plots a feature\n    against the target and shows the distribution of each via a\n    histogram on each axis.\n\n    Parameters\n    ----------\n    X : ndarray or DataFrame of shape n x m\n        A matrix of n instances with m features\n\n    y : ndarray or Series of length n\n        An array or series of target or class values\n\n    ax : matplotlib Axes, default: None\n        The axis to plot the figure on. If None is passed in the current axes\n        will be used (or generated if required).\n\n    method : str, default: 'pearson'\n        The method to calculate correlation between features and target.\n        Options include:\n\n            - 'pearson', which uses ``scipy.stats.pearsonr``\n            - 'mutual_info-regression', which uses ``mutual_info-regression``\n              from ``sklearn.feature_selection``\n            - 'mutual_info-classification', which uses ``mutual_info_classif``\n              from ``sklearn.feature_selection``\n\n    labels : list, default: None\n        A list of feature names to use. If a DataFrame is passed to fit and\n        features is None, feature names are selected as the column names.\n\n    sort : boolean, default: False\n        If false, the features are are not sorted in the plot; otherwise\n        features are sorted in ascending order of correlation.\n\n    feature_index : list,\n        A list of feature index to include in the plot.\n\n    feature_names : list of feature names\n        A list of feature names to include in the plot.\n        Must have labels or the fitted data is a DataFrame with column names.\n        If feature_index is provided, feature_names will be ignored.\n\n    color: string\n        Specify color for barchart\n\n    show: bool, default: True\n        If True, calls ``show()``, which in turn calls ``plt.show()`` however you cannot\n        call ``plt.savefig`` from this signature, nor ``clear_figure``. If False, simply\n        calls ``finalize()``\n\n    kwargs : dict\n        Keyword arguments that are passed to the base class and may influence\n        the visualization as defined in other Visualizers.\n\n    Returns\n    -------\n    visualizer : FeatureCorrelation\n        Returns the fitted visualizer.\n    \"\"\"\n\n    # Instantiate the visualizer\n    visualizer = FeatureCorrelation(\n        ax=ax,\n        method=method,\n        labels=labels,\n        sort=sort,\n        color=color,\n        feature_index=feature_index,\n        feature_names=feature_names,\n        **kwargs\n    )\n\n    # Fit and transform the visualizer (calls draw)\n    visualizer.fit(X, y, **kwargs)\n    if show:\n        visualizer.show()\n    else:\n        visualizer.finalize()\n\n    # Return the visualizer\n    return visualizer\n", "path": "yellowbrick/target/feature_correlation.py"}]}