8000 [MRG+1] more explicit error message when multiple scores passed (#11008) · scikit-learn/scikit-learn@7124d87 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7124d87

Browse files
minggliglemaitre
authored andcommitted
[MRG+1] more explicit error message when multiple scores passed (#11008)
1 parent f1aedf6 commit 7124d87

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

doc/whats_new/v0.20.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ Preprocessing
9191

9292
- Added :class:`MICEImputer`, which is a strategy for imputing missing
9393
values by modeling each feature with missing values as a function of
94-
other features in a round-robin fashion. :issue:`8478` by
94+
other features in a round-robin fashion. :issue:`8478` by
9595
:user:`Sergey Feldman <sergeyf>`.
9696

97-
- Updated :class:`preprocessing.MinMaxScaler` to pass through NaN values. :issue:`10404`
98-
by :user:`Lucija Gregov <LucijaGregov>`.
97+
- Updated :class:`preprocessing.MinMaxScaler` to pass through NaN values. :issue:`10404`
98+
by :user:`Lucija Gregov <LucijaGregov>`.
9999

100100
Model evaluation
101101

@@ -414,6 +414,12 @@ Preprocessing
414414
``inverse_transform`` on unseen labels. :issue:`9816` by :user:`Charlie Newey
415415
<newey01c>`.
416416

417+
Model evaluation and meta-estimators
418+
419+
- Add improved error message in :func:`model_selection.cross_val_score` when
420+
multiple metrics are passed in ``scoring`` keyword.
421+
:issue:`11006` by :user:`Ming Li <minggli>`.
422+
417423
Datasets
418424

419425
- Fixed a bug in :func:`dataset.load_boston` which had a wrong data point.

sklearn/metrics/scorer.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# License: Simplified BSD
2020

2121
from abc import ABCMeta, abstractmethod
22+
from collections import Iterable
2223
import warnings
2324

2425
import numpy as np
@@ -300,6 +301,10 @@ def check_scoring(estimator, scoring=None, allow_none=False):
300301
"If no scoring is specified, the estimator passed should "
301302
"have a 'score' method. The estimator %r does not."
302303
% estimator)
304+
elif isinstance(scoring, Iterable):
305+
raise ValueError("For evaluating multiple scores, use "
306+
"sklearn.model_selection.cross_validate instead. "
307+
"{0} was passed.".format(scoring))
303308
else:
304309
raise ValueError("scoring value should either be a callable, string or"
305310
" None. %r was passed" % scoring)

sklearn/model_selection/tests/test_search.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,10 +1217,10 @@ def test_fit_grid_point():
12171217
assert_equal(n_test_samples, test.size)
12181218

12191219
# Should raise an error upon multimetric scorer
1220-
assert_raise_message(ValueError, "scoring value should either be a "
1221-
"callable, string or None.", fit_grid_point, X, y,
1222-
svc, params, train, test, {'score': scorer},
1223-
verbose=True)
1220+
assert_raise_message(ValueError, "For evaluating multiple scores, use "
1221+
"sklearn.model_selection.cross_validate instead.",
1222+
fit_grid_point, X, y, svc, params, train, test,
1223+
{'score': scorer}, verbose=True)
12241224

12251225

12261226
def test_pickle():

0 commit comments

Comments
 (0)
0