Skip to content

Commit 1837ae8

Browse files
committed
Merge branch 'main' into submodule
2 parents 12d45d3 + 4af3087 commit 1837ae8

File tree

23 files changed

+249
-255
lines changed

23 files changed

+249
-255
lines changed

.github/workflows/publish_pypi.yml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ on:
1313
jobs:
1414
publish:
1515
runs-on: ubuntu-latest
16+
permissions:
17+
# IMPORTANT: this permission is mandatory for trusted publishing
18+
id-token: write
1619
steps:
1720
- uses: actions/checkout@v3
1821
- uses: actions/setup-python@v4
@@ -35,15 +38,10 @@ jobs:
3538
run: |
3639
python build_tools/github/check_wheels.py
3740
- name: Publish package to TestPyPI
38-
uses: pypa/gh-action-pypi-publish@v1.4.1
41+
uses: pypa/gh-action-pypi-publish@v1.8.5
3942
with:
40-
user: __token__
41-
password: ${{ secrets.TEST_PYPI_TOKEN }}
4243
repository_url: https://test.pypi.org/legacy/
4344
if: ${{ github.event.inputs.pypi_repo == 'testpypi' }}
4445
- name: Publish package to PyPI
45-
uses: pypa/gh-action-pypi-publish@v1.4.1
46-
with:
47-
user: __token__
48-
password: ${{ secrets.PYPI_TOKEN }}
46+
uses: pypa/gh-action-pypi-publish@v1.8.5
4947
if: ${{ github.event.inputs.pypi_repo == 'pypi' }}

doc/modules/impute.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ neighbors of samples with missing values::
226226
Missing value estimation methods for DNA microarrays, BIOINFORMATICS
227227
Vol. 17 no. 6, 2001 Pages 520-525.
228228
229-
Keeping the number of features constants
230-
========================================
229+
Keeping the number of features constant
230+
=======================================
231231

232232
By default, the scikit-learn imputers will drop fully empty features, i.e.
233233
columns containing only missing values. For instance::

doc/modules/model_evaluation.rst

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,11 @@ Usage examples:
115115
>>> clf = svm.SVC(random_state=0)
116116
>>> cross_val_score(clf, X, y, cv=5, scoring='recall_macro')
117117
array([0.96..., 0.96..., 0.96..., 0.93..., 1. ])
118-
>>> model = svm.SVC()
119-
>>> cross_val_score(model, X, y, cv=5, scoring='wrong_choice')
120-
Traceback (most recent call last):
121-
ValueError: 'wrong_choice' is not a valid scoring value. Use
122-
sklearn.metrics.get_scorer_names() to get valid options.
123118

124119
.. note::
125120

126-
The values listed by the ``ValueError`` exception correspond to the
127-
functions measuring prediction accuracy described in the following
128-
sections. You can retrieve the names of all available scorers by calling
121+
If a wrong scoring name is passed, an ``InvalidParameterError`` is raised.
122+
You can retrieve the names of all available scorers by calling
129123
:func:`~sklearn.metrics.get_scorer_names`.
130124

131125
.. currentmodule:: sklearn.metrics

sklearn/calibration.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#
88
# License: BSD 3 clause
99

10-
from numbers import Integral
10+
from numbers import Integral, Real
1111
import warnings
1212
from inspect import signature
1313
from functools import partial
@@ -35,7 +35,13 @@
3535

3636
from .utils.multiclass import check_classification_targets
3737
from .utils.parallel import delayed, Parallel
38-
from .utils._param_validation import StrOptions, HasMethods, Hidden
38+
from .utils._param_validation import (
39+
StrOptions,
40+
HasMethods,
41+
Hidden,
42+
validate_params,
43+
Interval,
44+
)
3945
from .utils._plotting import _BinaryClassifierCurveDisplayMixin
4046
from .utils.validation import (
4147
_check_fit_params,
@@ -903,6 +909,15 @@ def predict(self, T):
903909
return expit(-(self.a_ * T + self.b_))
904910

905911

912+
@validate_params(
913+
{
914+
"y_true": ["array-like"],
915+
"y_prob": ["array-like"],
916+
"pos_label": [Real, str, "boolean", None],
917+
"n_bins": [Interval(Integral, 1, None, closed="left")],
918+
"strategy": [StrOptions({"uniform", "quantile"})],
919+
}
920+
)
906921
def calibration_curve(
907922
y_true,
908923
y_prob,
@@ -928,7 +943,7 @@ def calibration_curve(
928943
y_prob : array-like of shape (n_samples,)
929944
Probabilities of the positive class.
930945
931-
pos_label : int or str, default=None
946+
pos_label : int, float, bool or str, default=None
932947
The label of the positive class.
933948
934949
.. versionadded:: 1.1
@@ -1042,7 +1057,7 @@ class CalibrationDisplay(_BinaryClassifierCurveDisplayMixin):
10421057
estimator_name : str, default=None
10431058
Name of estimator. If None, the estimator name is not shown.
10441059
1045-
pos_label : str or int, default=None
1060+
pos_label : int, float, bool or str, default=None
10461061
The positive class when computing the calibration curve.
10471062
By default, `estimators.classes_[1]` is considered as the
10481063
positive class.
@@ -1208,7 +1223,7 @@ def from_estimator(
12081223
- `'quantile'`: The bins have the same number of samples and depend
12091224
on predicted probabilities.
12101225
1211-
pos_label : str or int, default=None
1226+
pos_label : int, float, bool or str, default=None
12121227
The positive class when computing the calibration curve.
12131228
By default, `estimators.classes_[1]` is considered as the
12141229
positive class.
@@ -1326,7 +1341,7 @@ def from_predictions(
13261341
- `'quantile'`: The bins have the same number of samples and depend
13271342
on predicted probabilities.
13281343
1329-
pos_label : str or int, default=None
1344+
pos_label : int, float, bool or str, default=None
13301345
The positive class when computing the calibration curve.
13311346
By default, `estimators.classes_[1]` is considered as the
13321347
positive class.

sklearn/datasets/_base.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,11 @@ def load_sample_images():
12751275
return Bunch(images=images, filenames=filenames, DESCR=descr)
12761276

12771277

1278+
@validate_params(
1279+
{
1280+
"image_name": [StrOptions({"china.jpg", "flower.jpg"})],
1281+
}
1282+
)
12781283
def load_sample_image(image_name):
12791284
"""Load the numpy array of a single sample image.
12801285

sklearn/datasets/tests/test_base.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,6 @@ def test_load_sample_image():
222222
warnings.warn("Could not load sample images, PIL is not available.")
223223

224224

225-
def test_load_missing_sample_image_error():
226-
pytest.importorskip("PIL")
227-
with pytest.raises(AttributeError):
228-
load_sample_image("blop.jpg")
229-
230-
231225
def test_load_diabetes_raw():
232226
"""Test to check that we load a scaled version by default but that we can
233227
get an unscaled version when setting `scaled=False`."""

sklearn/feature_selection/_sequential.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ class SequentialFeatureSelector(SelectorMixin, MetaEstimatorMixin, BaseEstimator
3939
n_features_to_select : "auto", int or float, default='warn'
4040
If `"auto"`, the behaviour depends on the `tol` parameter:
4141
42-
- if `tol` is not `None`, then features are selected until the score
43-
improvement does not exceed `tol`.
42+
- if `tol` is not `None`, then features are selected while the score
43+
change does not exceed `tol`.
4444
- otherwise, half of the features are selected.
4545
4646
If integer, the parameter is the absolute number of features to select.
@@ -53,7 +53,7 @@ class SequentialFeatureSelector(SelectorMixin, MetaEstimatorMixin, BaseEstimator
5353
The default changed from `None` to `"warn"` in 1.1 and will become
5454
`"auto"` in 1.3. `None` and `'warn'` will be removed in 1.3.
5555
To keep the same behaviour as `None`, set
56-
`n_features_to_select="auto" and `tol=None`.
56+
`n_features_to_select="auto"` and `tol=None`.
5757
5858
tol : float, default=None
5959
If the score is not incremented by at least `tol` between two

sklearn/inspection/_partial_dependence.py

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@
2222
from ..utils import _get_column_indices
2323
from ..utils.validation import check_is_fitted
2424
from ..utils import Bunch
25+
from ..utils._param_validation import (
26+
HasMethods,
27+
Integral,
28+
Interval,
29+
StrOptions,
30+
validate_params,
31+
)
2532
from ..tree import DecisionTreeRegressor
2633
from ..ensemble import RandomForestRegressor
2734
from ..exceptions import NotFittedError
@@ -223,6 +230,24 @@ def _partial_dependence_brute(est, grid, features, X, response_method):
223230
return averaged_predictions, predictions
224231

225232

233+
@validate_params(
234+
{
235+
"estimator": [
236+
HasMethods(["fit", "predict"]),
237+
HasMethods(["fit", "predict_proba"]),
238+
HasMethods(["fit", "decision_function"]),
239+
],
240+
"X": ["array-like", "sparse matrix"],
241+
"features": ["array-like", Integral, str],
242+
"categorical_features": ["array-like", None],
243+
"feature_names": ["array-like", None],
244+
"response_method": [StrOptions({"auto", "predict_proba", "decision_function"})],
245+
"percentiles": [tuple],
246+
"grid_resolution": [Interval(Integral, 1, None, closed="left")],
247+
"method": [StrOptions({"auto", "recursion", "brute"})],
248+
"kind": [StrOptions({"average", "individual", "both"})],
249+
}
250+
)
226251
def partial_dependence(
227252
estimator,
228253
X,
@@ -268,13 +293,13 @@ def partial_dependence(
268293
:term:`predict_proba`, or :term:`decision_function`.
269294
Multioutput-multiclass classifiers are not supported.
270295
271-
X : {array-like or dataframe} of shape (n_samples, n_features)
296+
X : {array-like, sparse matrix or dataframe} of shape (n_samples, n_features)
272297
``X`` is used to generate a grid of values for the target
273298
``features`` (where the partial dependence will be evaluated), and
274299
also to generate values for the complement features when the
275300
`method` is 'brute'.
276301
277-
features : array-like of {int, str}
302+
features : array-like of {int, str, bool} or int or str
278303
The feature (e.g. `[0]`) or pair of interacting features
279304
(e.g. `[(0, 1)]`) for which the partial dependency should be computed.
280305
@@ -425,27 +450,12 @@ def partial_dependence(
425450
if not (hasattr(X, "__array__") or sparse.issparse(X)):
426451
X = check_array(X, force_all_finite="allow-nan", dtype=object)
427452

428-
accepted_responses = ("auto", "predict_proba", "decision_function")
429-
if response_method not in accepted_responses:
430-
raise ValueError(
431-
"response_method {} is invalid. Accepted response_method names "
432-
"are {}.".format(response_method, ", ".join(accepted_responses))
433-
)
434-
435453
if is_regressor(estimator) and response_method != "auto":
436454
raise ValueError(
437455
"The response_method parameter is ignored for regressors and "
438456
"must be 'auto'."
439457
)
440458

441-
accepted_methods = ("brute", "recursion", "auto")
442-
if method not in accepted_methods:
443-
raise ValueError(
444-
"method {} is invalid. Accepted method names are {}.".format(
445-
method, ", ".join(accepted_methods)
446-
)
447-
)
448-
449459
if kind != "average":
450460
if method == "recursion":
451461
raise ValueError(

sklearn/inspection/_plot/tests/test_plot_partial_dependence.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -611,16 +611,6 @@ def test_plot_partial_dependence_dataframe(pyplot, clf_diabetes, diabetes):
611611
{"features": [1], "categorical_features": [1], "kind": "individual"},
612612
"It is not possible to display individual effects",
613613
),
614-
(
615-
dummy_classification_data,
616-
{"features": [1], "kind": "foo"},
617-
"Values provided to `kind` must be one of",
618-
),
619-
(
620-
dummy_classification_data,
621-
{"features": [0, 1], "kind": ["foo", "individual"]},
622-
"Values provided to `kind` must be one of",
623-
),
624614
],
625615
)
626616
def test_plot_partial_dependence_error(pyplot, data, params, err_msg):

sklearn/inspection/tests/test_partial_dependence.py

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -510,31 +510,6 @@ def fit(self, X, y):
510510
{"features": [0], "response_method": "predict_proba", "method": "auto"},
511511
"'recursion' method, the response_method must be 'decision_function'",
512512
),
513-
(
514-
GradientBoostingClassifier(random_state=0),
515-
{"features": [0], "response_method": "blahblah"},
516-
"response_method blahblah is invalid. Accepted response_method",
517-
),
518-
(
519-
NoPredictProbaNoDecisionFunction(),
520-
{"features": [0], "response_method": "auto"},
521-
"The estimator has no predict_proba and no decision_function method",
522-
),
523-
(
524-
NoPredictProbaNoDecisionFunction(),
525-
{"features": [0], "response_method": "predict_proba"},
526-
"The estimator has no predict_proba method.",
527-
),
528-
(
529-
NoPredictProbaNoDecisionFunction(),
530-
{"features": [0], "response_method": "decision_function"},
531-
"The estimator has no decision_function method.",
532-
),
533-
(
534-
LinearRegression(),
535-
{"features": [0], "method": "blahblah"},
536-
"blahblah is invalid. Accepted method names are brute, recursion, auto",
537-
),
538513
(
539514
LinearRegression(),
540515
{"features": [0], "method": "recursion", "kind": "individual"},
@@ -560,24 +535,6 @@ def test_partial_dependence_error(estimator, params, err_msg):
560535
partial_dependence(estimator, X, **params)
561536

562537

563-
@pytest.mark.parametrize(
564-
"with_dataframe, err_msg",
565-
[
566-
(True, "Only array-like or scalar are supported"),
567-
(False, "Only array-like or scalar are supported"),
568-
],
569-
)
570-
def test_partial_dependence_slice_error(with_dataframe, err_msg):
571-
X, y = make_classification(random_state=0)
572-
if with_dataframe:
573-
pd = pytest.importorskip("pandas")
574-
X = pd.DataFrame(X)
575-
estimator = LogisticRegression().fit(X, y)
576-
577-
with pytest.raises(TypeError, match=err_msg):
578-
partial_dependence(estimator, X, features=slice(0, 2, 1))
579-
580-
581538
@pytest.mark.parametrize(
582539
"estimator", [LinearRegression(), GradientBoostingClassifier(random_state=0)]
583540
)

0 commit comments

Comments
 (0)