From 484dacf303c4c673a9f037f5b523347593fb46ce Mon Sep 17 00:00:00 2001 From: Nathan Breit Date: Wed, 17 Sep 2014 21:24:59 +0800 Subject: [PATCH] Altering precision_recall_fscore_support docstring If the labels are unsorted and precision_recall_fscore_support is used with multilabel classifications it will raise an exception. E.g.: ``` sklearn.metrics.precision_recall_fscore_support( [(1,2)], [(3,4)], labels=[4, 1, 2, 3] ) ``` raises ``` /usr/local/lib/python2.7/dist-packages/sklearn/metrics/classification.pyc in precision_recall_fscore_support(y_true, y_pred, beta, labels, pos_label, average, warn_for, sample_weight) 945 elif label_order is not None: 946 indices = np.searchsorted(labels, label_order) --> 947 precision = precision[indices] 948 recall = recall[indices] 949 f_score = f_score[indices] IndexError: index 4 is out of bounds for size 4 ``` Also, AFAICT the labels do not need to be integers. --- sklearn/metrics/classification.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearn/metrics/classification.py b/sklearn/metrics/classification.py index 7540a93f05d6b..cf05d0dfc7d82 100644 --- a/sklearn/metrics/classification.py +++ b/sklearn/metrics/classification.py @@ -742,7 +742,7 @@ def precision_recall_fscore_support(y_true, y_pred, beta=1.0, labels=None, The strength of recall versus precision in the F-score. labels : array - Integer array of labels. + Sorted array of labels. pos_label : str or int, 1 by default If ``average`` is not ``None`` and the classification target is binary,