@@ -503,15 +503,19 @@ def f1_score(y_true, y_pred, labels=None, pos_label=1, average='binary',
503
503
Integer array of labels.
504
504
505
505
pos_label : str or int, 1 by default
506
- If ``average`` is not ``None`` and the classification target is binary,
507
- only this class's scores will be returned.
506
+ The class to report if ``average='binary'``. Until version 0.18 it is
507
+ necessary to set ``pos_label=None`` if seeking to use another averaging
508
+ method over binary targets.
508
509
509
- average : one of [None, 'micro', 'macro', 'samples', 'weighted']
510
+ average : string, [None, 'binary' (default), 'micro', 'macro', 'samples', \
511
+ 'weighted']
510
512
This parameter is required for multiclass/multilabel targets.
511
- If ``None``, the scores for each class are returned. Otherwise,
512
- unless ``pos_label`` is given in binary classification, this
513
+ If ``None``, the scores for each class are returned. Otherwise, this
513
514
determines the type of averaging performed on the data:
514
515
516
+ ``'binary'``:
517
+ Only report results for the class specified by ``pos_label``.
518
+ This is applicable only if targets (``y_{true,pred}``) are binary.
515
519
``'micro'``:
516
520
Calculate metrics globally by counting the total true positives,
517
521
false negatives and false positives.
@@ -528,6 +532,10 @@ def f1_score(y_true, y_pred, labels=None, pos_label=1, average='binary',
528
532
meaningful for multilabel classification where this differs from
529
533
:func:`accuracy_score`).
530
534
535
+ Note that if ``pos_label`` is given in binary classification with
536
+ `average != 'binary'`, only that positive class is reported. This
537
+ behavior is deprecated and will change in version 0.18.
538
+
531
539
sample_weight : array-like of shape = [n_samples], optional
532
540
Sample weights.
533
541
@@ -590,15 +598,19 @@ def fbeta_score(y_true, y_pred, beta, labels=None, pos_label=1,
590
598
Integer array of labels.
591
599
592
600
pos_label : str or int, 1 by default
593
- If ``average`` is not ``None`` and the classification target is binary,
594
- only this class's scores will be returned.
601
+ The class to report if ``average='binary'``. Until version 0.18 it is
602
+ necessary to set ``pos_label=None`` if seeking to use another averaging
603
+ method over binary targets.
595
604
596
- average : one of [None, 'micro', 'macro', 'samples', 'weighted']
605
+ average : string, [None, 'binary' (default), 'micro', 'macro', 'samples', \
606
+ 'weighted']
597
607
This parameter is required for multiclass/multilabel targets.
598
- If ``None``, the scores for each class are returned. Otherwise,
599
- unless ``pos_label`` is given in binary classification, this
608
+ If ``None``, the scores for each class are returned. Otherwise, this
600
609
determines the type of averaging performed on the data:
601
610
611
+ ``'binary'``:
612
+ Only report results for the class specified by ``pos_label``.
613
+ This is applicable only if targets (``y_{true,pred}``) are binary.
602
614
``'micro'``:
603
615
Calculate metrics globally by counting the total true positives,
604
616
false negatives and false positives.
@@ -615,6 +627,10 @@ def fbeta_score(y_true, y_pred, beta, labels=None, pos_label=1,
615
627
meaningful for multilabel classification where this differs from
616
628
:func:`accuracy_score`).
617
629
630
+ Note that if ``pos_label`` is given in binary classification with
631
+ `average != 'binary'`, only that positive class is reported. This
632
+ behavior is deprecated and will change in version 0.18.
633
+
618
634
sample_weight : array-like of shape = [n_samples], optional
619
635
Sample weights.
620
636
@@ -750,14 +766,18 @@ def precision_recall_fscore_support(y_true, y_pred, beta=1.0, labels=None,
750
766
Integer array of labels.
751
767
752
768
pos_label : str or int, 1 by default
753
- If ``average`` is not ``None`` and the classification target is binary,
754
- only this class's scores will be returned.
769
+ The class to report if ``average='binary'``. Until version 0.18 it is
770
+ necessary to set ``pos_label=None`` if seeking to use another averaging
771
+ method over binary targets.
755
772
756
- average : string, [None (default), 'micro', 'macro', 'samples', 'weighted']
757
- If ``None``, the scores for each class are returned. Otherwise,
758
- unless ``pos_label`` is given in binary classification , this
773
+ average : string, [None (default), 'binary', ' micro', 'macro', 'samples', \
774
+ 'weighted']
775
+ If ``None``, the scores for each class are returned. Otherwise , this
759
776
determines the type of averaging performed on the data:
760
777
778
+ ``'binary'``:
779
+ Only report results for the class specified by ``pos_label``.
780
+ This is applicable only if targets (``y_{true,pred}``) are binary.
761
781
``'micro'``:
762
782
Calculate metrics globally by counting the total true positives,
763
783
false negatives and false positives.
@@ -774,6 +794,10 @@ def precision_recall_fscore_support(y_true, y_pred, beta=1.0, labels=None,
774
794
meaningful for multilabel classification where this differs from
775
795
:func:`accuracy_score`).
776
796
797
+ Note that if ``pos_label`` is given in binary classification with
798
+ `average != 'binary'`, only that positive class is reported. This
799
+ behavior is deprecated and will change in version 0.18.
800
+
777
801
warn_for : tuple or set, for internal use
778
802
This determines which warnings will be made in the case that this
779
803
function is being used to return only one of its metrics.
@@ -834,11 +858,11 @@ def precision_recall_fscore_support(y_true, y_pred, beta=1.0, labels=None,
834
858
835
859
y_type , y_true , y_pred = _check_targets (y_true , y_pred )
836
860
837
- if average == 'binary' and y_type != 'binary' :
861
+ if average == 'binary' and ( y_type != 'binary' or pos_label is None ) :
838
862
warnings .warn ('The default `weighted` averaging is deprecated, '
839
863
'and from version 0.18, use of precision, recall or '
840
- 'F-score with multiclass or multilabel data will result '
841
- 'in an exception. '
864
+ 'F-score with multiclass or multilabel data or '
865
+ 'pos_label=None will result in an exception. '
842
866
'Please set an explicit value for `average`, one of '
843
867
'%s. In cross validation use, for instance, '
844
868
'scoring="f1_weighted" instead of scoring="f1".'
@@ -900,14 +924,12 @@ def precision_recall_fscore_support(y_true, y_pred, beta=1.0, labels=None,
900
924
### Select labels to keep ###
901
925
902
926
if y_type == 'binary' and average is not None and pos_label is not None :
903
- if average != 'binary' and label_order is not None \
904
- and len (label_order ) == 2 :
905
- warnings .warn ('In the future, providing two `labels` values, as '
906
- 'well as `average!=`binary`` will average over '
907
- 'those labels. For now, please use `labels=None` '
908
- 'with `pos_label` to evaluate precision, recall and '
909
- 'F-score for the positive label only.' ,
910
- FutureWarning )
927
+ if average != 'binary' :
928
+ warnings .warn ('From version 0.18, binary input will not be '
929
+ 'handled specially when using averaged '
930
+ 'precision/recall/F-score. '
931
+ 'Please use average=\' binary\' to report only the '
932
+ 'positive class performance.' , DeprecationWarning )
911
933
if pos_label not in labels :
912
934
if len (labels ) == 1 :
913
935
# Only negative labels
@@ -955,6 +977,7 @@ def precision_recall_fscore_support(y_true, y_pred, beta=1.0, labels=None,
955
977
weights = None
956
978
957
979
if average is not None :
980
+ assert average != 'binary' or len (precision ) == 1
958
981
precision = np .average (precision , weights = weights )
959
982
recall = np .average (recall , weights = weights )
960
983
f_score = np .average (f_score , weights = weights )
@@ -992,15 +1015,19 @@ def precision_score(y_true, y_pred, labels=None, pos_label=1,
992
1015
Integer array of labels.
993
1016
994
1017
pos_label : str or int, 1 by default
995
- If ``average`` is not ``None`` and the classification target is binary,
996
- only this class's scores will be returned.
1018
+ The class to report if ``average='binary'``. Until version 0.18 it is
1019
+ necessary to set ``pos_label=None`` if seeking to use another averaging
1020
+ method over binary targets.
997
1021
998
- average : one of [None, 'micro', 'macro', 'samples', 'weighted']
1022
+ average : string, [None, 'binary' (default), 'micro', 'macro', 'samples', \
1023
+ 'weighted']
999
1024
This parameter is required for multiclass/multilabel targets.
1000
- If ``None``, the scores for each class are returned. Otherwise,
1001
- unless ``pos_label`` is given in binary classification, this
1025
+ If ``None``, the scores for each class are returned. Otherwise, this
1002
1026
determines the type of averaging performed on the data:
1003
1027
1028
+ ``'binary'``:
1029
+ Only report results for the class specified by ``pos_label``.
1030
+ This is applicable only if targets (``y_{true,pred}``) are binary.
1004
1031
``'micro'``:
1005
1032
Calculate metrics globally by counting the total true positives,
1006
1033
false negatives and false positives.
@@ -1017,6 +1044,10 @@ def precision_score(y_true, y_pred, labels=None, pos_label=1,
1017
1044
meaningful for multilabel classification where this differs from
1018
1045
:func:`accuracy_score`).
1019
1046
1047
+ Note that if ``pos_label`` is given in binary classification with
1048
+ `average != 'binary'`, only that positive class is reported. This
1049
+ behavior is deprecated and will change in version 0.18.
1050
+
1020
1051
sample_weight : array-like of shape = [n_samples], optional
1021
1052
Sample weights.
1022
1053
@@ -1075,15 +1106,19 @@ def recall_score(y_true, y_pred, labels=None, pos_label=1, average='binary',
1075
1106
Integer array of labels.
1076
1107
1077
1108
pos_label : str or int, 1 by default
1078
- If ``average`` is not ``None`` and the classification target is binary,
1079
- only this class's scores will be returned.
1109
+ The class to report if ``average='binary'``. Until version 0.18 it is
1110
+ necessary to set ``pos_label=None`` if seeking to use another averaging
1111
+ method over binary targets.
1080
1112
1081
- average : one of [None, 'micro', 'macro', 'samples', 'weighted']
1113
+ average : string, [None, 'binary' (default), 'micro', 'macro', 'samples', \
1114
+ 'weighted']
1082
1115
This parameter is required for multiclass/multilabel targets.
1083
- If ``None``, the scores for each class are returned. Otherwise,
1084
- unless ``pos_label`` is given in binary classification, this
1116
+ If ``None``, the scores for each class are returned. Otherwise, this
1085
1117
determines the type of averaging performed on the data:
1086
1118
1119
+ ``'binary'``:
1120
+ Only report results for the class specified by ``pos_label``.
1121
+ This is applicable only if targets (``y_{true,pred}``) are binary.
1087
1122
``'micro'``:
1088
1123
Calculate metrics globally by counting the total true positives,
1089
1124
false negatives and false positives.
@@ -1100,6 +1135,10 @@ def recall_score(y_true, y_pred, labels=None, pos_label=1, average='binary',
1100
1135
meaningful for multilabel classification where this differs from
1101
1136
:func:`accuracy_score`).
1102
1137
1138
+ Note that if ``pos_label`` is given in binary classification with
1139
+ `average != 'binary'`, only that positive class is reported. This
1140
+ behavior is deprecated and will change in version 0.18.
1141
+
1103
1142
sample_weight : array-like of shape = [n_samples], optional
1104
1143
Sample weights.
1105
1144
0 commit comments