Skip to content

PRs to include in 1.0.rc2 #21008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Sep 14, 2021
5 changes: 0 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,6 @@ workflows:
- doc-min-dependencies:
requires:
- lint
- pypy3:
filters:
branches:
only:
- 0.20.X
- deploy:
requires:
- doc
Expand Down
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ env:
- OPENBLAS_NUM_THREADS=2
- SKLEARN_BUILD_PARALLEL=3
- SKLEARN_SKIP_NETWORK_TESTS=1
- PYTHONUNBUFFERED=1
# Custom environment variables for the ARM wheel builder
- CIBW_BUILD_VERBOSITY=1
- CIBW_TEST_REQUIRES="pytest pytest-xdist threadpoolctl"
- CIBW_TEST_COMMAND="bash {project}/build_tools/travis/test_wheels.sh"
- CIBW_ENVIRONMENT="CPU_COUNT=2
- CIBW_ENVIRONMENT="CPU_COUNT=6
OMP_NUM_THREADS=2
OPENBLAS_NUM_THREADS=2
SKLEARN_BUILD_PARALLEL=3
SKLEARN_SKIP_NETWORK_TESTS=1"
SKLEARN_BUILD_PARALLEL=10
SKLEARN_SKIP_NETWORK_TESTS=1
PYTHONUNBUFFERED=1"

jobs:
include:
Expand Down
6 changes: 2 additions & 4 deletions build_tools/travis/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
# defined in the ".travis.yml" file. In particular, it is
# important that we call to the right installation script.

set -e

if [[ $BUILD_WHEEL == true ]]; then
source build_tools/travis/install_wheels.sh
source build_tools/travis/install_wheels.sh || travis_terminate 1
else
source build_tools/travis/install_main.sh
source build_tools/travis/install_main.sh || travis_terminate 1
fi
6 changes: 2 additions & 4 deletions build_tools/travis/install_wheels.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/bin/bash

set -e

python -m pip install cibuildwheel
python -m cibuildwheel --output-dir wheelhouse
python -m pip install cibuildwheel || travis_terminate $?
python -m cibuildwheel --output-dir wheelhouse || travis_terminate $?
2 changes: 0 additions & 2 deletions build_tools/travis/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
# continuous deployment jobs, we have to execute the scripts for
# testing the continuous integration jobs.

set -e

if [[ $BUILD_WHEEL != true ]]; then
# This trick will make Travis terminate the continuation of the pipeline
bash build_tools/travis/test_script.sh || travis_terminate 1
Expand Down
8 changes: 4 additions & 4 deletions build_tools/travis/test_wheels.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash

set -e
pip install --upgrade pip || travis_terminate $?
pip install pytest pytest-xdist || travis_terminate $?

# Faster run of the source code tests
pytest -n $CPU_COUNT --pyargs sklearn
python -m pytest -n $CPU_COUNT --pyargs sklearn || travis_terminate $?

# Test that there are no links to system libraries
python -m threadpoolctl -i sklearn
python -m threadpoolctl -i sklearn || travis_terminate $?
8 changes: 4 additions & 4 deletions doc/developers/plotting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ Plotting with Multiple Axes
---------------------------

Some of the plotting tools like
:func:`~sklearn.inspection.plot_partial_dependence` and
:class:`~sklearn.inspection.PartialDependenceDisplay` support plottong on
:func:`~sklearn.inspection.PartialDependenceDisplay.from_estimator` and
:class:`~sklearn.inspection.PartialDependenceDisplay` support plotting on
multiple axes. Two different scenarios are supported:

1. If a list of axes is passed in, `plot` will check if the number of axes is
Expand All @@ -87,8 +87,8 @@ be placed. In this case, we suggest using matplotlib's
By default, the `ax` keyword in `plot` is `None`. In this case, the single
axes is created and the gridspec api is used to create the regions to plot in.

See for example, :func:`~sklearn.inspection.plot_partial_dependence` which
plots multiple lines and contours using this API. The axes defining the
See for example, :func:`~sklearn.inspection.PartialDependenceDisplay.from_estimator
which plots multiple lines and contours using this API. The axes defining the
bounding box is saved in a `bounding_ax_` attribute. The individual axes
created are stored in an `axes_` ndarray, corresponding to the axes position on
the grid. Positions that are not used are set to `None`. Furthermore, the
Expand Down
16 changes: 8 additions & 8 deletions doc/modules/partial_dependence.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,20 @@ independent of the house age, whereas for values less than 2 there is a strong
dependence on age.

The :mod:`sklearn.inspection` module provides a convenience function
:func:`plot_partial_dependence` to create one-way and two-way partial
:func:`~PartialDependenceDisplay.from_estimator` to create one-way and two-way partial
dependence plots. In the below example we show how to create a grid of
partial dependence plots: two one-way PDPs for the features ``0`` and ``1``
and a two-way PDP between the two features::

>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier
>>> from sklearn.inspection import plot_partial_dependence
>>> from sklearn.inspection import PartialDependenceDisplay

>>> X, y = make_hastie_10_2(random_state=0)
>>> clf = GradientBoostingClassifier(n_estimators=100, learning_rate=1.0,
... max_depth=1, random_state=0).fit(X, y)
>>> features = [0, 1, (0, 1)]
>>> plot_partial_dependence(clf, X, features)
>>> PartialDependenceDisplay.from_estimator(clf, X, features)
<...>

You can access the newly created figure and Axes objects using ``plt.gcf()``
Expand All @@ -82,7 +82,7 @@ the PDPs should be created via the ``target`` argument::
>>> mc_clf = GradientBoostingClassifier(n_estimators=10,
... max_depth=1).fit(iris.data, iris.target)
>>> features = [3, 2, (3, 2)]
>>> plot_partial_dependence(mc_clf, X, features, target=0)
>>> PartialDependenceDisplay.from_estimator(mc_clf, X, features, target=0)
<...>

The same parameter ``target`` is used to specify the target in multi-output
Expand Down Expand Up @@ -138,20 +138,20 @@ and the house price in the PD line. However, the ICE lines show that there
are some exceptions, where the house price remains constant in some ranges of
the median income.

The :mod:`sklearn.inspection` module's :func:`plot_partial_dependence`
The :mod:`sklearn.inspection` module's :meth:`PartialDependenceDisplay.from_estimator`
convenience function can be used to create ICE plots by setting
``kind='individual'``. In the example below, we show how to create a grid of
ICE plots:

>>> from sklearn.datasets import make_hastie_10_2
>>> from sklearn.ensemble import GradientBoostingClassifier
>>> from sklearn.inspection import plot_partial_dependence
>>> from sklearn.inspection import PartialDependenceDisplay

>>> X, y = make_hastie_10_2(random_state=0)
>>> clf = GradientBoostingClassifier(n_estimators=100, learning_rate=1.0,
... max_depth=1, random_state=0).fit(X, y)
>>> features = [0, 1]
>>> plot_partial_dependence(clf, X, features,
>>> PartialDependenceDisplay.from_estimator(clf, X, features,
... kind='individual')
<...>

Expand All @@ -160,7 +160,7 @@ feature of interest. Hence, it is recommended to use ICE plots alongside
PDPs. They can be plotted together with
``kind='both'``.

>>> plot_partial_dependence(clf, X, features,
>>> PartialDependenceDisplay.from_estimator(clf, X, features,
... kind='both')
<...>

Expand Down
13 changes: 12 additions & 1 deletion doc/whats_new/v1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,11 @@ Changelog
:func:`~sklearn.inspection.permutation_importance`.
:pr:`19411` by :user:`Simona Maggio <simonamaggio>`.

- |API| :class:`inspection.PartialDependenceDisplay` exposes a class method:
:func:`~inspection.PartialDependenceDisplay.from_estimator`.
:func:`inspection.plot_partial_dependence` is deprecated in favor of the
class method and will be removed in 1.2. :pr:`20959` by `Thomas Fan`_.

:mod:`sklearn.kernel_approximation`
...................................

Expand Down Expand Up @@ -703,6 +708,9 @@ Changelog
- |Enhancement| warn only once in the main process for per-split fit failures
in cross-validation. :pr:`20619` by :user:`Loïc Estève <lesteve>`

- |Enhancement| The :class:`model_selection.BaseShuffleSplit` base class is
now public. :pr:`20056` by :user:`pabloduque0`.

- |Fix| Avoid premature overflow in :func:`model_selection.train_test_split`.
:pr:`20904` by :user:`Tomasz Jakubek <t-jakubek>`.

Expand Down Expand Up @@ -821,6 +829,9 @@ Changelog
`n_features_in_` and will be removed in 1.2. :pr:`20240` by
:user:`Jérémie du Boisberranger <jeremiedbb>`.

- |Fix| :class:`preprocessing.FunctionTransformer` does not set `n_features_in_`
based on the input to `inverse_transform`. :pr:`20961` by `Thomas Fan`_.

:mod:`sklearn.svm`
...................

Expand Down Expand Up @@ -895,7 +906,7 @@ Changelog
warning was previously raised in resampling utilities and functions using
those utilities (e.g. :func:`model_selection.train_test_split`,
:func:`model_selection.cross_validate`,
:func:`model_seleection.cross_val_score`,
:func:`model_selection.cross_val_score`,
:func:`model_selection.cross_val_predict`).
:pr:`20673` by :user:`Joris Van den Bossche <jorisvandenbossche>`.

Expand Down
6 changes: 3 additions & 3 deletions examples/ensemble/plot_monotonic_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<https://xgboost.readthedocs.io/en/latest/tutorials/monotonic.html>`_.
"""
from sklearn.ensemble import HistGradientBoostingRegressor
from sklearn.inspection import plot_partial_dependence
from sklearn.inspection import PartialDependenceDisplay
import numpy as np
import matplotlib.pyplot as plt

Expand All @@ -43,7 +43,7 @@
# Without any constraint
gbdt = HistGradientBoostingRegressor()
gbdt.fit(X, y)
disp = plot_partial_dependence(
disp = PartialDependenceDisplay.from_estimator(
gbdt,
X,
features=[0, 1],
Expand All @@ -55,7 +55,7 @@
gbdt = HistGradientBoostingRegressor(monotonic_cst=[1, -1])
gbdt.fit(X, y)

plot_partial_dependence(
PartialDependenceDisplay.from_estimator(
gbdt,
X,
features=[0, 1],
Expand Down
8 changes: 4 additions & 4 deletions examples/inspection/plot_partial_dependence.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@

import matplotlib.pyplot as plt
from sklearn.inspection import partial_dependence
from sklearn.inspection import plot_partial_dependence
from sklearn.inspection import PartialDependenceDisplay

print("Computing partial dependence plots...")
tic = time()
features = ["MedInc", "AveOccup", "HouseAge", "AveRooms"]
display = plot_partial_dependence(
display = PartialDependenceDisplay.from_estimator(
est,
X_train,
features,
Expand Down Expand Up @@ -166,7 +166,7 @@

print("Computing partial dependence plots...")
tic = time()
display = plot_partial_dependence(
display = PartialDependenceDisplay.from_estimator(
est,
X_train,
features,
Expand Down Expand Up @@ -229,7 +229,7 @@
print("Computing partial dependence plots...")
tic = time()
_, ax = plt.subplots(ncols=3, figsize=(9, 4))
display = plot_partial_dependence(
display = PartialDependenceDisplay.from_estimator(
est,
X_train,
features,
Expand Down
23 changes: 11 additions & 12 deletions examples/miscellaneous/plot_partial_dependence_visualization_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import make_pipeline
from sklearn.tree import DecisionTreeRegressor
from sklearn.inspection import plot_partial_dependence
from sklearn.inspection import PartialDependenceDisplay


# %%
Expand All @@ -49,22 +49,22 @@
#
# We plot partial dependence curves for features "age" and "bmi" (body mass
# index) for the decision tree. With two features,
# :func:`~sklearn.inspection.plot_partial_dependence` expects to plot two
# curves. Here the plot function place a grid of two plots using the space
# :func:`~sklearn.inspection.PartialDependenceDisplay.from_estimator` expects to plot
# two curves. Here the plot function place a grid of two plots using the space
# defined by `ax` .
fig, ax = plt.subplots(figsize=(12, 6))
ax.set_title("Decision Tree")
tree_disp = plot_partial_dependence(tree, X, ["age", "bmi"], ax=ax)
tree_disp = PartialDependenceDisplay.from_estimator(tree, X, ["age", "bmi"], ax=ax)

# %%
# The partial depdendence curves can be plotted for the multi-layer perceptron.
# In this case, `line_kw` is passed to
# :func:`~sklearn.inspection.plot_partial_dependence` to change the color of
# the curve.
# :func:`~sklearn.inspection.PartialDependenceDisplay.from_estimator` to change the
# color of the curve.
fig, ax = plt.subplots(figsize=(12, 6))
ax.set_title("Multi-layer Perceptron")
mlp_disp = plot_partial_dependence(mlp, X, ["age", "bmi"], ax=ax,
line_kw={"color": "red"})
mlp_disp = PartialDependenceDisplay.from_estimator(mlp, X, ["age", "bmi"], ax=ax,
line_kw={"color": "red"})

# %%
# Plotting partial dependence of the two models together
Expand Down Expand Up @@ -129,7 +129,6 @@
# Here, we plot the partial dependence curves for a single feature, "age", on
# the same axes. In this case, `tree_disp.axes_` is passed into the second
# plot function.
tree_disp = plot_partial_dependence(tree, X, ["age"])
mlp_disp = plot_partial_dependence(mlp, X, ["age"],
ax=tree_disp.axes_,
line_kw={"color": "red"})
tree_disp = PartialDependenceDisplay.from_estimator(tree, X, ["age"])
mlp_disp = PartialDependenceDisplay.from_estimator(
mlp, X, ["age"], ax=tree_disp.axes_, line_kw={"color": "red"})
19 changes: 11 additions & 8 deletions sklearn/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -980,8 +980,8 @@ class CalibrationDisplay:
y_prob : ndarray of shape (n_samples,)
Probability estimates for the positive class, for each sample.

name : str, default=None
Name for labeling curve.
estimator_name : str, default=None
Name of estimator. If None, the estimator name is not shown.

Attributes
----------
Expand Down Expand Up @@ -1022,11 +1022,11 @@ class CalibrationDisplay:
<...>
"""

def __init__(self, prob_true, prob_pred, y_prob, *, name=None):
def __init__(self, prob_true, prob_pred, y_prob, *, estimator_name=None):
self.prob_true = prob_true
self.prob_pred = prob_pred
self.y_prob = y_prob
self.name = name
self.estimator_name = estimator_name

def plot(self, *, ax=None, name=None, ref_line=True, **kwargs):
"""Plot visualization.
Expand All @@ -1041,7 +1041,8 @@ def plot(self, *, ax=None, name=None, ref_line=True, **kwargs):
created.

name : str, default=None
Name for labeling curve.
Name for labeling curve. If `None`, use `estimator_name` if
not `None`, otherwise no labeling is shown.

ref_line : bool, default=True
If `True`, plots a reference line representing a perfectly
Expand All @@ -1061,8 +1062,7 @@ def plot(self, *, ax=None, name=None, ref_line=True, **kwargs):
if ax is None:
fig, ax = plt.subplots()

name = self.name if name is None else name
self.name = name
name = self.estimator_name if name is None else name

line_kwargs = {}
if name is not None:
Expand Down Expand Up @@ -1298,6 +1298,9 @@ def from_predictions(
prob_true, prob_pred = calibration_curve(
y_true, y_prob, n_bins=n_bins, strategy=strategy
)
name = name if name is not None else "Classifier"

disp = cls(prob_true=prob_true, prob_pred=prob_pred, y_prob=y_prob, name=name)
disp = cls(
prob_true=prob_true, prob_pred=prob_pred, y_prob=y_prob, estimator_name=name
)
return disp.plot(ax=ax, ref_line=ref_line, **kwargs)
4 changes: 2 additions & 2 deletions sklearn/cluster/_affinity_propagation.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class AffinityPropagation(ClusterMixin, BaseEstimator):
Parameters
----------
damping : float, default=0.5
Damping factor (between 0.5 and 1) is the extent to
Damping factor in the range `[0.5, 1.0)` is the extent to
which the current value is maintained relative to
incoming values (weighted 1 - damping). This in order
to avoid numerical oscillations when updating these
Expand Down Expand Up @@ -469,7 +469,7 @@ def fit(self, X, y=None):
target_type=numbers.Real,
min_val=0.5,
max_val=1,
closed="right",
include_boundaries="left",
)
check_scalar(self.max_iter, "max_iter", target_type=numbers.Integral, min_val=1)
check_scalar(
Expand Down
2 changes: 1 addition & 1 deletion sklearn/inspection/_partial_dependence.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def partial_dependence(

See Also
--------
plot_partial_dependence : Plot Partial Dependence.
PartialDependenceDisplay.from_estimator : Plot Partial Dependence.
PartialDependenceDisplay : Partial Dependence visualization.

Examples
Expand Down
Loading