Skip to content

Commit

Permalink
MNT Update deprecation message in RegressorMixin.score to tell users …
Browse files Browse the repository at this point in the history
…how to avoid the warning (scikit-learn#13477)
  • Loading branch information
qinhanmin2014 authored and Xing committed Apr 28, 2019
1 parent 00ad8c1 commit a11c28e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
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)

0 comments on commit a11c28e

Please sign in to comment.