Skip to content

Commit

Permalink
Merge pull request #309 from arteymix/deprecate-res-in-plot-decision-…
Browse files Browse the repository at this point in the history
…regions

plot_decision_regions: Deprecated 'res'
  • Loading branch information
rasbt committed Dec 23, 2017
2 parents 1880299 + ef64a6a commit 3774e14
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 93 deletions.
3 changes: 2 additions & 1 deletion docs/sources/CHANGELOG.md
Expand Up @@ -20,7 +20,8 @@ The CHANGELOG for the current development version is available at

##### Changes

- -
- The `plot_decision_regions` function now automatically determines the optimal setting based on the feature dimensions and supports anti-aliasing. The old `res` parameter has been deprecated. ([#309](https://github.com/rasbt/mlxtend/pull/309) by [Guillaume Poirier-Morency](https://github.com/arteymix))

##### Bug Fixes

- -
Expand Down
97 changes: 42 additions & 55 deletions docs/sources/user_guide/plotting/plot_decision_regions.ipynb

Large diffs are not rendered by default.

23 changes: 13 additions & 10 deletions docs/sources/user_guide/plotting/plot_learning_curves.ipynb

Large diffs are not rendered by default.

38 changes: 21 additions & 17 deletions mlxtend/plotting/decision_regions.py
Expand Up @@ -10,6 +10,7 @@
import matplotlib.pyplot as plt
import numpy as np
from ..utils import check_Xy
import warnings


def get_feature_range_mask(X, filler_feature_values=None,
Expand Down Expand Up @@ -44,7 +45,8 @@ def plot_decision_regions(X, y, clf,
filler_feature_ranges=None,
ax=None,
X_highlight=None,
res=0.02, legend=1,
res=None,
legend=1,
hide_spines=True,
markers='s^oxv<>',
colors='red,blue,limegreen,gray,cyan'):
Expand Down Expand Up @@ -81,11 +83,13 @@ def plot_decision_regions(X, y, clf,
one if ax=None.
X_highlight : array-like, shape = [n_samples, n_features] (default: None)
An array with data points that are used to highlight samples in `X`.
res : float or array-like, shape = (2,) (default: 0.02)
Grid width. If float, same resolution is used for both the x- and
y-axis. If array-like, the first item is used on the x-axis, the
second is used on the y-axis. Lower values increase the resolution but
slow down the plotting.
res : float or array-like, shape = (2,) (default: None)
This parameter was used to define the grid width,
but it has been deprecated in favor of
determining the number of points given the figure DPI and size
automatically for optimal results and computational efficiency.
To increase the resolution, it's is recommended to use to provide
a `dpi argument via matplotlib, e.g., `plt.figure(dpi=600)`.
hide_spines : bool (default: True)
Hide axis spines if True.
legend : int (default: 1)
Expand All @@ -108,14 +112,12 @@ def plot_decision_regions(X, y, clf,
if ax is None:
ax = plt.gca()

if isinstance(res, float):
xres, yres = res, res
else:
try:
xres, yres = res
except ValueError:
raise ValueError('Unable to unpack res. Expecting '
'array-like input of length 2.')
if res is not None:
warnings.warn("The 'res' parameter has been deprecated."
"To increase the resolution, it's is recommended"
"to use to provide a `dpi argument via matplotlib,"
"e.g., `plt.figure(dpi=600)`.",
DeprecationWarning)

plot_testdata = True
if not isinstance(X_highlight, np.ndarray):
Expand Down Expand Up @@ -185,8 +187,9 @@ def plot_decision_regions(X, y, clf,
else:
y_min, y_max = X[:, y_index].min() - 1, X[:, y_index].max() + 1

xx, yy = np.meshgrid(np.arange(x_min, x_max, xres),
np.arange(y_min, y_max, yres))
xnum, ynum = plt.gcf().dpi * plt.gcf().get_size_inches()
xx, yy = np.meshgrid(np.linspace(x_min, x_max, num=xnum),
np.linspace(y_min, y_max, num=ynum))

if dim == 1:
X_predict = np.array([xx.ravel()]).T
Expand All @@ -204,7 +207,8 @@ def plot_decision_regions(X, y, clf,
ax.contourf(xx, yy, Z,
alpha=0.3,
colors=colors,
levels=np.arange(Z.max() + 2) - 0.5)
levels=np.arange(Z.max() + 2) - 0.5,
antialiased=True)

ax.axis(xmin=xx.min(), xmax=xx.max(), y_min=yy.min(), y_max=yy.max())

Expand Down
10 changes: 0 additions & 10 deletions mlxtend/plotting/tests/test_decision_regions.py
Expand Up @@ -79,13 +79,3 @@ def test_y_ary_dim():
'y must be a 1D array',
plot_decision_regions,
X[:, :2], y[:, np.newaxis], sr)


def test_res_fail_if_3d():
sr.fit(X[:, :2], y)
assert_raises(ValueError,
'Unable to unpack res. Expecting array-like input of '
'length 2.',
plot_decision_regions,
X[:, :2], y, sr,
res=(1, 2, 3))

0 comments on commit 3774e14

Please sign in to comment.