Skip to content
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

MNT Update deprecation message in RegressorMixin.score to tell users how to avoid the warning #13477

Merged
merged 2 commits into from Mar 29, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 10 additions & 7 deletions sklearn/base.py
Expand Up @@ -366,9 +366,10 @@ def score(self, X, y, sample_weight=None):
``multioutput='uniform_average'`` from version 0.23 to keep consistent
with `metrics.r2_score`. This will influence the ``score`` method of
all the multioutput regressors (except for
`multioutput.MultiOutputRegressor`). To use the new default, please
either call `metrics.r2_score` directly or make a custom scorer with
`metrics.make_scorer`.
`multioutput.MultiOutputRegressor`). To specify the default value
manually and avoid the warning, please either call `metrics.r2_score`
directly or make a custom scorer with `metrics.make_scorer` (the
built-in scorer ``'r2'`` uses ``multioutput='uniform_average'``).
"""

from .metrics import r2_score
Expand All @@ -380,10 +381,12 @@ def score(self, X, y, sample_weight=None):
warnings.warn("The default value of multioutput (not exposed in "
"score method) will change from 'variance_weighted' "
"to 'uniform_average' in 0.23 to keep consistent "
"with 'metrics.r2_score'. To use the new default, "
"please either call 'metrics.r2_score' directly or "
"make a custom scorer with 'metrics.make_scorer'.",
FutureWarning)
"with 'metrics.r2_score'. To specify the default "
"value manually and avoid the warning, please "
"either call 'metrics.r2_score' directly or make a "
"custom scorer with 'metrics.make_scorer' (the "
"built-in scorer 'r2' uses "
"multioutput='uniform_average').", FutureWarning)
return r2_score(y, y_pred, sample_weight=sample_weight,
multioutput='variance_weighted')

Expand Down
9 changes: 6 additions & 3 deletions sklearn/tests/test_base.py
Expand Up @@ -502,7 +502,10 @@ def test_regressormixin_score_multioutput():
msg = ("The default value of multioutput (not exposed in "
"score method) will change from 'variance_weighted' "
"to 'uniform_average' in 0.23 to keep consistent "
"with 'metrics.r2_score'. To use the new default, "
"please either call 'metrics.r2_score' directly or "
"make a custom scorer with 'metrics.make_scorer'.")
"with 'metrics.r2_score'. To specify the default "
"value manually and avoid the warning, please "
"either call 'metrics.r2_score' directly or make a "
"custom scorer with 'metrics.make_scorer' (the "
"built-in scorer 'r2' uses "
"multioutput='uniform_average').")
assert_warns_message(FutureWarning, msg, reg.score, X, y)