10000 MNT improve UnsetMetadataPassedError error message and fix disable metadata routing in examples by StefanieSenger · Pull Request #31069 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

MNT improve UnsetMetadataPassedError error message and fix disable metadata routing in examples #31069

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/metadata_routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ should be passed to the estimator's scorer or not::
[sample_weight] are passed but are not explicitly set as requested or not
requested for LogisticRegression.score, which is used within GridSearchCV.fit.
Call `LogisticRegression.set_score_request({metadata}=True/False)` for each metadata
you want to request/ignore.
you want to request/ignore. See the Metadata Routing User guide
<https://scikit-learn.org/stable/metadata_routing.html> for more information.

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

Expand Down
3 changes: 3 additions & 0 deletions examples/model_selection/plot_cost_sensitive_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,3 +689,6 @@ def business_metric(y_true, y_pred, amount):
# historical data (offline evaluation) should ideally be confirmed by A/B testing
# on live data (online evaluation). Note however that A/B testing models is
# beyond the scope of the scikit-learn library itself.

# At the end, we disable the configuration flag for metadata routing::
sklearn.set_config(enable_metadata_routing=False)
26 changes: 13 additions & 13 deletions examples/release_highlights/plot_release_highlights_1_6_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,20 @@
# a validation set. We can now have a pipeline which will transform the validation set
# and pass it to the estimator::
#
# sklearn.set_config(enable_metadata_routing=True)
# est_gs = GridSearchCV(
# Pipeline(
# (
# StandardScaler(),
# EstimatorWithValidationSet(...).set_fit_request(X_val=True, y_val=True),
# with sklearn.config_context(enable_metadata_routing=True):
# est_gs = GridSearchCV(
# Pipeline(
# (
# StandardScaler(),
# EstimatorWithValidationSet(...).set_fit_request(X_val=True, y_val=True),
# ),
# # telling pipeline to transform these inputs up to the step which is
# # requesting them.
# transform_input=["X_val"],
# ),
# # telling pipeline to transform these inputs up to the step which is
# # requesting them.
# transform_input=["X_val"],
# ),
# param_grid={"estimatorwithvalidationset__param_to_optimize": list(range(5))},
# cv=5,
# ).fit(X, y, X_val=X_val, y_val=y_val)
# param_grid={"estimatorwithvalidationset__param_to_optimize": list(range(5))},
# cv=5,
# ).fit(X, y, X_val=X_val, y_val=y_val)
#
# In the above code, the key parts are the call to `set_fit_request` to specify that
# `X_val` and `y_val` are required by the `EstimatorWithValidationSet.fit` method, and
Expand Down
7 changes: 5 additions & 2 deletions sklearn/utils/_metadata_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,10 @@ def _route_params(self, params, parent, caller):
f" {self.owner}.{self.method}, which is used within"
f" {parent}.{caller}. Call `{self.owner}"
+ set_requests_on
+ "` for each metadata you want to request/ignore."
+ "` for each metadata you want to request/ignore. See the"
" Metadata Routing User guide"
" <https://scikit-learn.org/stable/metadata_routing.html> for more"
" information."
)
raise UnsetMetadataPassedError(
message=message,
Expand Down Expand Up @@ -1384,7 +1387,7 @@ def __init_subclass__(cls, **kwargs):

for method in SIMPLE_METHODS:
mmr = getattr(requests, method)
# set ``set_{method}_request``` methods
# set ``set_{method}_request`` methods
if not len(mmr.requests):
continue
setattr(
Expand Down
2 changes: 1 addition & 1 deletion sklearn/utils/multiclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def is_multilabel(y):
Returns
-------
out : bool
Return ``True``, if ``y`` is in a multilabel format, else ```False``.
Return ``True``, if ``y`` is in a multilabel format, else ``False``.

Examples
--------
Expand Down
0