From cd5317a110149182cc7790107931937b5855dd43 Mon Sep 17 00:00:00 2001 From: AMDonati Date: Sat, 29 Sep 2018 15:09:21 -0400 Subject: [PATCH] ck estimator is classifier & num_classes>=2 in score.py --- sklearn/metrics/scorer.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sklearn/metrics/scorer.py b/sklearn/metrics/scorer.py index 2661a379b4e53..f8b678ae62a5d 100644 --- a/sklearn/metrics/scorer.py +++ b/sklearn/metrics/scorer.py @@ -183,7 +183,12 @@ def __call__(self, clf, X, y, sample_weight=None): y_pred = clf.predict_proba(X) if y_type == "binary": - y_pred = y_pred[:, 1] + if y_pred.shape[1]==2: + y_pred = y_pred[:, 1] + else: + raise ValueError('The output of the prediction is a vector, which is incompatible with a classifierself.' + 'Check that the estimator is a classifier and the number of classes in the dataset is 2 or more.') + elif isinstance(y_pred, list): y_pred = np.vstack([p[:, -1] for p in y_pred]).T