@@ -501,15 +501,19 @@ def f1_score(y_true, y_pred, labels=None, pos_label=1, average='binary',
501501 Integer array of labels.
502502
503503 pos_label : str or int, 1 by default
504- If ``average`` is not ``None`` and the classification target is binary,
505- only this class's scores will be returned.
504+ The class to report if ``average='binary'``. Until version 0.18 it is
505+ necessary to set ``pos_label=None`` if seeking to use another averaging
506+ method over binary targets.
506507
507- average : one of [None, 'micro', 'macro', 'samples', 'weighted']
508+ average : string, [None, 'binary' (default), 'micro', 'macro', 'samples', \
509+ 'weighted']
508510 This parameter is required for multiclass/multilabel targets.
509- If ``None``, the scores for each class are returned. Otherwise,
510- unless ``pos_label`` is given in binary classification, this
511+ If ``None``, the scores for each class are returned. Otherwise, this
511512 determines the type of averaging performed on the data:
512513
514+ ``'binary'``:
515+ Only report results for the class specified by ``pos_label``.
516+ This is applicable only if targets (``y_{true,pred}``) are binary.
513517 ``'micro'``:
514518 Calculate metrics globally by counting the total true positives,
515519 false negatives and false positives.
@@ -526,6 +530,10 @@ def f1_score(y_true, y_pred, labels=None, pos_label=1, average='binary',
526530 meaningful for multilabel classification where this differs from
527531 :func:`accuracy_score`).
528532
533+ Note that if ``pos_label`` is given in binary classification with
534+ `average != 'binary'`, only that positive class is reported. This
535+ behavior is deprecated and will change in version 0.18.
536+
529537 sample_weight : array-like of shape = [n_samples], optional
530538 Sample weights.
531539
@@ -588,15 +596,19 @@ def fbeta_score(y_true, y_pred, beta, labels=None, pos_label=1,
588596 Integer array of labels.
589597
590598 pos_label : str or int, 1 by default
591- If ``average`` is not ``None`` and the classification target is binary,
592- only this class's scores will be returned.
599+ The class to report if ``average='binary'``. Until version 0.18 it is
600+ necessary to set ``pos_label=None`` if seeking to use another averaging
601+ method over binary targets.
593602
594- average : one of [None, 'micro', 'macro', 'samples', 'weighted']
603+ average : string, [None, 'binary' (default), 'micro', 'macro', 'samples', \
604+ 'weighted']
595605 This parameter is required for multiclass/multilabel targets.
596- If ``None``, the scores for each class are returned. Otherwise,
597- unless ``pos_label`` is given in binary classification, this
606+ If ``None``, the scores for each class are returned. Otherwise, this
598607 determines the type of averaging performed on the data:
599608
609+ ``'binary'``:
610+ Only report results for the class specified by ``pos_label``.
611+ This is applicable only if targets (``y_{true,pred}``) are binary.
600612 ``'micro'``:
601613 Calculate metrics globally by counting the total true positives,
602614 false negatives and false positives.
@@ -613,6 +625,10 @@ def fbeta_score(y_true, y_pred, beta, labels=None, pos_label=1,
613625 meaningful for multilabel classification where this differs from
614626 :func:`accuracy_score`).
615627
628+ Note that if ``pos_label`` is given in binary classification with
629+ `average != 'binary'`, only that positive class is reported. This
630+ behavior is deprecated and will change in version 0.18.
631+
616632 sample_weight : array-like of shape = [n_samples], optional
617633 Sample weights.
618634
@@ -748,14 +764,18 @@ def precision_recall_fscore_support(y_true, y_pred, beta=1.0, labels=None,
748764 Integer array of labels.
749765
750766 pos_label : str or int, 1 by default
751- If ``average`` is not ``None`` and the classification target is binary,
752- only this class's scores will be returned.
767+ The class to report if ``average='binary'``. Until version 0.18 it is
768+ necessary to set ``pos_label=None`` if seeking to use another averaging
769+ method over binary targets.
753770
754- average : string, [None (default), 'micro', 'macro', 'samples', 'weighted']
755- If ``None``, the scores for each class are returned. Otherwise,
756- unless ``pos_label`` is given in binary classification , this
771+ average : string, [None (default), 'binary', ' micro', 'macro', 'samples', \
772+ 'weighted']
773+ If ``None``, the scores for each class are returned. Otherwise , this
757774 determines the type of averaging performed on the data:
758775
776+ ``'binary'``:
777+ Only report results for the class specified by ``pos_label``.
778+ This is applicable only if targets (``y_{true,pred}``) are binary.
759779 ``'micro'``:
760780 Calculate metrics globally by counting the total true positives,
761781 false negatives and false positives.
@@ -772,6 +792,10 @@ def precision_recall_fscore_support(y_true, y_pred, beta=1.0, labels=None,
772792 meaningful for multilabel classification where this differs from
773793 :func:`accuracy_score`).
774794
795+ Note that if ``pos_label`` is given in binary classification with
796+ `average != 'binary'`, only that positive class is reported. This
797+ behavior is deprecated and will change in version 0.18.
798+
775799 warn_for : tuple or set, for internal use
776800 This determines which warnings will be made in the case that this
777801 function is being used to return only one of its metrics.
@@ -832,11 +856,11 @@ def precision_recall_fscore_support(y_true, y_pred, beta=1.0, labels=None,
832856
833857 y_type , y_true , y_pred = _check_targets (y_true , y_pred )
834858
835- if average == 'binary' and y_type != 'binary' :
859+ if average == 'binary' and ( y_type != 'binary' or pos_label is None ) :
836860 warnings .warn ('The default `weighted` averaging is deprecated, '
837861 'and from version 0.18, use of precision, recall or '
838- 'F-score with multiclass or multilabel data will result '
839- 'in an exception. '
862+ 'F-score with multiclass or multilabel data or '
863+ 'pos_label=None will result in an exception. '
840864 'Please set an explicit value for `average`, one of '
841865 '%s. In cross validation use, for instance, '
842866 'scoring="f1_weighted" instead of scoring="f1".'
@@ -898,14 +922,12 @@ def precision_recall_fscore_support(y_true, y_pred, beta=1.0, labels=None,
898922 ### Select labels to keep ###
899923
900924 if y_type == 'binary' and average is not None and pos_label is not None :
901- if average != 'binary' and label_order is not None \
902- and len (label_order ) == 2 :
903- warnings .warn ('In the future, providing two `labels` values, as '
904- 'well as `average!=`binary`` will average over '
905- 'those labels. For now, please use `labels=None` '
906- 'with `pos_label` to evaluate precision, recall and '
907- 'F-score for the positive label only.' ,
908- FutureWarning )
925+ if average != 'binary' :
926+ warnings .warn ('From version 0.18, binary input will not be '
927+ 'handled specially when using averaged '
928+ 'precision/recall/F-score. '
929+ 'Please use average=\' binary\' to report only the '
930+ 'positive class performance.' , DeprecationWarning )
909931 if pos_label not in labels :
910932 if len (labels ) == 1 :
911933 # Only negative labels
@@ -953,6 +975,7 @@ def precision_recall_fscore_support(y_true, y_pred, beta=1.0, labels=None,
953975 weights = None
954976
955977 if average is not None :
978+ assert average != 'binary' or len (precision ) == 1
956979 precision = np .average (precision , weights = weights )
957980 recall = np .average (recall , weights = weights )
958981 f_score = np .average (f_score , weights = weights )
@@ -990,15 +1013,19 @@ def precision_score(y_true, y_pred, labels=None, pos_label=1,
9901013 Integer array of labels.
9911014
9921015 pos_label : str or int, 1 by default
993- If ``average`` is not ``None`` and the classification target is binary,
994- only this class's scores will be returned.
1016+ The class to report if ``average='binary'``. Until version 0.18 it is
1017+ necessary to set ``pos_label=None`` if seeking to use another averaging
1018+ method over binary targets.
9951019
996- average : one of [None, 'micro', 'macro', 'samples', 'weighted']
1020+ average : string, [None, 'binary' (default), 'micro', 'macro', 'samples', \
1021+ 'weighted']
9971022 This parameter is required for multiclass/multilabel targets.
998- If ``None``, the scores for each class are returned. Otherwise,
999- unless ``pos_label`` is given in binary classification, this
1023+ If ``None``, the scores for each class are returned. Otherwise, this
10001024 determines the type of averaging performed on the data:
10011025
1026+ ``'binary'``:
1027+ Only report results for the class specified by ``pos_label``.
1028+ This is applicable only if targets (``y_{true,pred}``) are binary.
10021029 ``'micro'``:
10031030 Calculate metrics globally by counting the total true positives,
10041031 false negatives and false positives.
@@ -1015,6 +1042,10 @@ def precision_score(y_true, y_pred, labels=None, pos_label=1,
10151042 meaningful for multilabel classification where this differs from
10161043 :func:`accuracy_score`).
10171044
1045+ Note that if ``pos_label`` is given in binary classification with
1046+ `average != 'binary'`, only that positive class is reported. This
1047+ behavior is deprecated and will change in version 0.18.
1048+
10181049 sample_weight : array-like of shape = [n_samples], optional
10191050 Sample weights.
10201051
@@ -1073,15 +1104,19 @@ def recall_score(y_true, y_pred, labels=None, pos_label=1, average='binary',
10731104 Integer array of labels.
10741105
10751106 pos_label : str or int, 1 by default
1076- If ``average`` is not ``None`` and the classification target is binary,
1077- only this class's scores will be returned.
1107+ The class to report if ``average='binary'``. Until version 0.18 it is
1108+ necessary to set ``pos_label=None`` if seeking to use another averaging
1109+ method over binary targets.
10781110
1079- average : one of [None, 'micro', 'macro', 'samples', 'weighted']
1111+ average : string, [None, 'binary' (default), 'micro', 'macro', 'samples', \
1112+ 'weighted']
10801113 This parameter is required for multiclass/multilabel targets.
1081- If ``None``, the scores for each class are returned. Otherwise,
1082- unless ``pos_label`` is given in binary classification, this
1114+ If ``None``, the scores for each class are returned. Otherwise, this
10831115 determines the type of averaging performed on the data:
10841116
1117+ ``'binary'``:
1118+ Only report results for the class specified by ``pos_label``.
1119+ This is applicable only if targets (``y_{true,pred}``) are binary.
10851120 ``'micro'``:
10861121 Calculate metrics globally by counting the total true positives,
10871122 false negatives and false positives.
@@ -1098,6 +1133,10 @@ def recall_score(y_true, y_pred, labels=None, pos_label=1, average='binary',
10981133 meaningful for multilabel classification where this differs from
10991134 :func:`accuracy_score`).
11001135
1136+ Note that if ``pos_label`` is given in binary classification with
1137+ `average != 'binary'`, only that positive class is reported. This
1138+ behavior is deprecated and will change in version 0.18.
1139+
11011140 sample_weight : array-like of shape = [n_samples], optional
11021141 Sample weights.
11031142
0 commit comments