From f99fd0dd291851672d90a019c0f4b90b8a090ceb Mon Sep 17 00:00:00 2001
From: Joel Nothman <joel.nothman@gmail.com>
Date: Tue, 11 Jul 2017 01:31:10 +1000
Subject: [PATCH] More informative error message for classification metrics
 given regression output (#9275)

---
 sklearn/metrics/classification.py            | 4 ++--
 sklearn/metrics/tests/test_classification.py | 3 ++-
 sklearn/metrics/tests/test_common.py         | 3 ++-
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/sklearn/metrics/classification.py b/sklearn/metrics/classification.py
index e5ab5b49fc..09aa4d87b8 100644
--- a/sklearn/metrics/classification.py
+++ b/sklearn/metrics/classification.py
@@ -77,8 +77,8 @@ def _check_targets(y_true, y_pred):
         y_type = set(["multiclass"])
 
     if len(y_type) > 1:
-        raise ValueError("Can't handle mix of {0} and {1}"
-                         "".format(type_true, type_pred))
+        raise ValueError("Classification metrics can't handle a mix of {0} "
+                         "and {1} targets".format(type_true, type_pred))
 
     # We can't have more than one value on y_type => The set is no more needed
     y_type = y_type.pop()
diff --git a/sklearn/metrics/tests/test_classification.py b/sklearn/metrics/tests/test_classification.py
index e2acf1de59..4d6b87f701 100644
--- a/sklearn/metrics/tests/test_classification.py
+++ b/sklearn/metrics/tests/test_classification.py
@@ -1344,7 +1344,8 @@ def test__check_targets():
             if type1 != type2:
                 assert_raise_message(
                     ValueError,
-                    "Can't handle mix of {0} and {1}".format(type1, type2),
+                    "Classification metrics can't handle a mix of {0} and {1} "
+                    "targets".format(type1, type2),
                     _check_targets, y1, y2)
 
             else:
diff --git a/sklearn/metrics/tests/test_common.py b/sklearn/metrics/tests/test_common.py
index d0b855d278..5f775aaf9a 100644
--- a/sklearn/metrics/tests/test_common.py
+++ b/sklearn/metrics/tests/test_common.py
@@ -636,7 +636,8 @@ def test_inf_nan_input():
     for metric in CLASSIFICATION_METRICS.values():
         for y_true, y_score in invalids:
             assert_raise_message(ValueError,
-                                 "Can't handle mix of binary and continuous",
+                                 "Classification metrics can't handle a mix "
+                                 "of binary and continuous targets",
                                  metric, y_true, y_score)
 
 
-- 
GitLab