Skip to content

Commit efe2b76

Browse files
MNT improve UnsetMetadataPassedError error message and fix disable metadata routing in examples (#31069)
1 parent 42a7d0c commit efe2b76

File tree

5 files changed

+24
-17
lines changed

5 files changed

+24
-17
lines changed

doc/metadata_routing.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ should be passed to the estimator's scorer or not::
248248
[sample_weight] are passed but are not explicitly set as requested or not
249249
requested for LogisticRegression.score, which is used within GridSearchCV.fit.
250250
Call `LogisticRegression.set_score_request({metadata}=True/False)` for each metadata
251-
you want to request/ignore.
251+
you want to request/ignore. See the Metadata Routing User guide
252+
<https://scikit-learn.org/stable/metadata_routing.html> for more information.
252253

253254
The issue can be fixed by explicitly setting the request value::
254255

examples/model_selection/plot_cost_sensitive_learning.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,3 +689,6 @@ def business_metric(y_true, y_pred, amount):
689689
# historical data (offline evaluation) should ideally be confirmed by A/B testing
690690
# on live data (online evaluation). Note however that A/B testing models is
691691
# beyond the scope of the scikit-learn library itself.
692+
693+
# At the end, we disable the configuration flag for metadata routing::
694+
sklearn.set_config(enable_metadata_routing=False)

examples/release_highlights/plot_release_highlights_1_6_0.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,20 @@
6969
# a validation set. We can now have a pipeline which will transform the validation set
7070
# and pass it to the estimator::
7171
#
72-
# sklearn.set_config(enable_metadata_routing=True)
73-
# est_gs = GridSearchCV(
74-
# Pipeline(
75-
# (
76-
# StandardScaler(),
77-
# EstimatorWithValidationSet(...).set_fit_request(X_val=True, y_val=True),
72+
# with sklearn.config_context(enable_metadata_routing=True):
73+
# est_gs = GridSearchCV(
74+
# Pipeline(
75+
# (
76+
# StandardScaler(),
77+
# EstimatorWithValidationSet(...).set_fit_request(X_val=True, y_val=True),
78+
# ),
79+
# # telling pipeline to transform these inputs up to the step which is
80+
# # requesting them.
81+
# transform_input=["X_val"],
7882
# ),
79-
# # telling pipeline to transform these inputs up to the step which is
80-
# # requesting them.
81-
# transform_input=["X_val"],
82-
# ),
83-
# param_grid={"estimatorwithvalidationset__param_to_optimize": list(range(5))},
84-
# cv=5,
85-
# ).fit(X, y, X_val=X_val, y_val=y_val)
83+
# param_grid={"estimatorwithvalidationset__param_to_optimize": list(range(5))},
84+
# cv=5,
85+
# ).fit(X, y, X_val=X_val, y_val=y_val)
8686
#
8787
# In the above code, the key parts are the call to `set_fit_request` to specify that
8888
# `X_val` and `y_val` are required by the `EstimatorWithValidationSet.fit` method, and

sklearn/utils/_metadata_requests.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,10 @@ def _route_params(self, params, parent, caller):
458458
f" {self.owner}.{self.method}, which is used within"
459459
f" {parent}.{caller}. Call `{self.owner}"
460460
+ set_requests_on
461-
+ "` for each metadata you want to request/ignore."
461+
+ "` for each metadata you want to request/ignore. See the"
462+
" Metadata Routing User guide"
463+
" <https://scikit-learn.org/stable/metadata_routing.html> for more"
464+
" information."
462465
)
463466
raise UnsetMetadataPassedError(
464467
message=message,
@@ -1384,7 +1387,7 @@ def __init_subclass__(cls, **kwargs):
13841387

13851388
for method in SIMPLE_METHODS:
13861389
mmr = getattr(requests, method)
1387-
# set ``set_{method}_request``` methods
1390+
# set ``set_{method}_request`` methods
13881391
if not len(mmr.requests):
13891392
continue
13901393
setattr(

sklearn/utils/multiclass.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def is_multilabel(y):
137137
Returns
138138
-------
139139
out : bool
140-
Return ``True``, if ``y`` is in a multilabel format, else ```False``.
140+
Return ``True``, if ``y`` is in a multilabel format, else ``False``.
141141
142142
Examples
143143
--------

0 commit comments

Comments
 (0)