From d20cb6d381ffd95fe563b53745f36e5beab41931 Mon Sep 17 00:00:00 2001 From: Ming Li Date: Sun, 22 Apr 2018 08:45:26 +0100 Subject: [PATCH 1/6] more explicit error message when mulitple scores passed to cross_val_score --- sklearn/metrics/scorer.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sklearn/metrics/scorer.py b/sklearn/metrics/scorer.py index 05231826a8998..b7fcf3c41b06a 100644 --- a/sklearn/metrics/scorer.py +++ b/sklearn/metrics/scorer.py @@ -300,6 +300,10 @@ def check_scoring(estimator, scoring=None, allow_none=False): "If no scoring is specified, the estimator passed should " "have a 'score' method. The estimator %r does not." % estimator) + elif isinstance(scoring, (list, tuple, set, dict)): + raise ValueError("For evaluating multiple scores, use " + "sklearn.model_selection.cross_validate instead. " + "{0} was passed.".format(scoring)) else: raise ValueError("scoring value should either be a callable, string or" " None. %r was passed" % scoring) From 91f19da1ae47f7110bec646c36b96176c65e2423 Mon Sep 17 00:00:00 2001 From: Ming Li Date: Sun, 22 Apr 2018 09:45:31 +0100 Subject: [PATCH 2/6] update error message in test_search.py --- sklearn/model_selection/tests/test_search.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sklearn/model_selection/tests/test_search.py b/sklearn/model_selection/tests/test_search.py index 19b1466799b8f..8bb60afe4a456 100644 --- a/sklearn/model_selection/tests/test_search.py +++ b/sklearn/model_selection/tests/test_search.py @@ -1217,10 +1217,10 @@ def test_fit_grid_point(): assert_equal(n_test_samples, test.size) # Should raise an error upon multimetric scorer - assert_raise_message(ValueError, "scoring value should either be a " - "callable, string or None.", fit_grid_point, X, y, - svc, params, train, test, {'score': scorer}, - verbose=True) + assert_raise_message(ValueError, "For evaluating multiple scores, use " + "sklearn.model_selection.cross_validate instead.", + fit_grid_point, X, y, svc, params, train, test, + {'score': scorer}, verbose=True) def test_pickle(): From 015557d51d082d4c4fa181c3190c407a8febdaa0 Mon Sep 17 00:00:00 2001 From: Ming Li Date: Sun, 22 Apr 2018 10:41:28 +0100 Subject: [PATCH 3/6] use collections.Iterable since string type already checked. --- sklearn/metrics/scorer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sklearn/metrics/scorer.py b/sklearn/metrics/scorer.py index b7fcf3c41b06a..c13d59a8daa2b 100644 --- a/sklearn/metrics/scorer.py +++ b/sklearn/metrics/scorer.py @@ -19,6 +19,7 @@ # License: Simplified BSD from abc import ABCMeta, abstractmethod +from collections import Iterable import warnings import numpy as np @@ -300,7 +301,7 @@ def check_scoring(estimator, scoring=None, allow_none=False): "If no scoring is specified, the estimator passed should " "have a 'score' method. The estimator %r does not." % estimator) - elif isinstance(scoring, (list, tuple, set, dict)): + elif isinstance(scoring, Iterable): raise ValueError("For evaluating multiple scores, use " "sklearn.model_selection.cross_validate instead. " "{0} was passed.".format(scoring)) From d311945ec3db46080c93726d524e216b507f8a12 Mon Sep 17 00:00:00 2001 From: Ming Li Date: Sun, 22 Apr 2018 11:06:49 +0100 Subject: [PATCH 4/6] whatsnew entry --- doc/whats_new/v0.20.rst | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/doc/whats_new/v0.20.rst b/doc/whats_new/v0.20.rst index 03396a7d086cc..2d6285f0c2743 100644 --- a/doc/whats_new/v0.20.rst +++ b/doc/whats_new/v0.20.rst @@ -91,11 +91,11 @@ Preprocessing - Added :class:`MICEImputer`, which is a strategy for imputing missing values by modeling each feature with missing values as a function of - other features in a round-robin fashion. :issue:`8478` by + other features in a round-robin fashion. :issue:`8478` by :user:`Sergey Feldman `. -- Updated :class:`preprocessing.MinMaxScaler` to pass through NaN values. :issue:`10404` - by :user:`Lucija Gregov `. +- Updated :class:`preprocessing.MinMaxScaler` to pass through NaN values. :issue:`10404` + by :user:`Lucija Gregov `. Model evaluation @@ -204,6 +204,10 @@ Model evaluation and meta-estimators return estimators fitted on each split. :issue:`9686` by :user:`Aurélien Bellet `. +- Add improved error message in :func:`model_selection.cross_val_score` when + multiple metrics are passed in ``scoring`` keyword. + :issue:`11006` by :user:`Ming Li `. + Decomposition and manifold learning - Speed improvements for both 'exact' and 'barnes_hut' methods in From 8118bafeb3cb3ea21b271ef8e90205912f4b0e7e Mon Sep 17 00:00:00 2001 From: Ming Li Date: Sun, 22 Apr 2018 12:54:48 +0100 Subject: [PATCH 5/6] moved to bugfix section --- doc/whats_new/v0.20.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/whats_new/v0.20.rst b/doc/whats_new/v0.20.rst index 2d6285f0c2743..29b400fa0d74d 100644 --- a/doc/whats_new/v0.20.rst +++ b/doc/whats_new/v0.20.rst @@ -204,10 +204,6 @@ Model evaluation and meta-estimators return estimators fitted on each split. :issue:`9686` by :user:`Aurélien Bellet `. -- Add improved error message in :func:`model_selection.cross_val_score` when - multiple metrics are passed in ``scoring`` keyword. - :issue:`11006` by :user:`Ming Li `. - Decomposition and manifold learning - Speed improvements for both 'exact' and 'barnes_hut' methods in @@ -418,6 +414,10 @@ Preprocessing ``inverse_transform`` on unseen labels. :issue:`9816` by :user:`Charlie Newey `. +- Add improved error message in :func:`model_selection.cross_val_score` when + multiple metrics are passed in ``scoring`` keyword. + :issue:`11006` by :user:`Ming Li `. + Datasets - Fixed a bug in :func:`dataset.load_boston` which had a wrong data point. From deb5925eac7dc8e8832f2f186b9a7fea4ced238b Mon Sep 17 00:00:00 2001 From: Ming Li Date: Sun, 22 Apr 2018 12:59:08 +0100 Subject: [PATCH 6/6] add subsection --- doc/whats_new/v0.20.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/whats_new/v0.20.rst b/doc/whats_new/v0.20.rst index 29b400fa0d74d..482fa41f8f422 100644 --- a/doc/whats_new/v0.20.rst +++ b/doc/whats_new/v0.20.rst @@ -414,6 +414,8 @@ Preprocessing ``inverse_transform`` on unseen labels. :issue:`9816` by :user:`Charlie Newey `. +Model evaluation and meta-estimators + - Add improved error message in :func:`model_selection.cross_val_score` when multiple metrics are passed in ``scoring`` keyword. :issue:`11006` by :user:`Ming Li `.