From 9ef5963591bcd674d91754a7611adf8cc48815f6 Mon Sep 17 00:00:00 2001 From: Lucy Liu Date: Fri, 10 Nov 2023 17:31:38 +1100 Subject: [PATCH 1/2] dep pos_label None --- sklearn/metrics/_classification.py | 33 +++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/sklearn/metrics/_classification.py b/sklearn/metrics/_classification.py index 1e18c0b3617bb..05e12eb4e3447 100644 --- a/sklearn/metrics/_classification.py +++ b/sklearn/metrics/_classification.py @@ -770,6 +770,10 @@ def jaccard_score( For multiclass or multilabel targets, set `labels=[pos_label]` and `average != 'binary'` to report metrics for one label only. + .. versionchanged:: 1.4 + Deprecated `None` as an option, since v0.18 `pos_label` is ignored + when `average` is not 'binary'. + average : {'micro', 'macro', 'samples', 'weighted', \ 'binary'} or None, default='binary' If ``None``, the scores for each class are returned. Otherwise, this @@ -1155,6 +1159,10 @@ def f1_score( For multiclass or multilabel targets, set `labels=[pos_label]` and `average != 'binary'` to report metrics for one label only. + .. versionchanged:: 1.4 + Deprecated `None` as an option, since v0.18 `pos_label` is ignored + when `average` is not 'binary'. + average : {'micro', 'macro', 'samples', 'weighted', 'binary'} or None, \ default='binary' This parameter is required for multiclass/multilabel targets. @@ -1349,6 +1357,10 @@ def fbeta_score( For multiclass or multilabel targets, set `labels=[pos_label]` and `average != 'binary'` to report metrics for one label only. + .. versionchanged:: 1.4 + Deprecated `None` as an option, since v0.18 `pos_label` is ignored + when `average` is not 'binary'. + average : {'micro', 'macro', 'samples', 'weighted', 'binary'} or None, \ default='binary' This parameter is required for multiclass/multilabel targets. @@ -1546,7 +1558,13 @@ def _check_set_wise_labels(y_true, y_pred, average, labels, pos_label): "Target is %s but average='binary'. Please " "choose another average setting, one of %r." % (y_type, average_options) ) - elif pos_label not in (None, 1): + elif pos_label is None: + warnings.warn( + "The None option for 'pos_label' was deprecated in version 1.4 " + "and will be removed in 1.6. To keep past behavior, leave 'pos_label' " + " as default value.", FutureWarning + ) + elif pos_label != 1: warnings.warn( "Note that pos_label (set to %r) is ignored when " "average != 'binary' (got %r). You may use " @@ -1554,6 +1572,7 @@ def _check_set_wise_labels(y_true, y_pred, average, labels, pos_label): % (pos_label, average), UserWarning, ) + return labels @@ -1646,6 +1665,10 @@ def precision_recall_fscore_support( For multiclass or multilabel targets, set `labels=[pos_label]` and `average != 'binary'` to report metrics for one label only. + .. versionchanged:: 1.4 + Deprecated `None` as an option, since v0.18 `pos_label` is ignored + when `average` is not 'binary'. + average : {'binary', 'micro', 'macro', 'samples', 'weighted'}, \ default=None If ``None``, the metrics for each class are returned. Otherwise, this @@ -2076,6 +2099,10 @@ def precision_score( For multiclass or multilabel targets, set `labels=[pos_label]` and `average != 'binary'` to report metrics for one label only. + .. versionchanged:: 1.4 + Deprecated `None` as an option, since v0.18 `pos_label` is ignored + when `average` is not 'binary'. + average : {'micro', 'macro', 'samples', 'weighted', 'binary'} or None, \ default='binary' This parameter is required for multiclass/multilabel targets. @@ -2254,6 +2281,10 @@ def recall_score( For multiclass or multilabel targets, set `labels=[pos_label]` and `average != 'binary'` to report metrics for one label only. + .. versionchanged:: 1.4 + Deprecated `None` as an option, since v0.18 `pos_label` is ignored + when `average` is not 'binary'. + average : {'micro', 'macro', 'samples', 'weighted', 'binary'} or None, \ default='binary' This parameter is required for multiclass/multilabel targets. From 9eb2620eb84a056651e2d50db98229175e49e6c9 Mon Sep 17 00:00:00 2001 From: Lucy Liu Date: Fri, 10 Nov 2023 17:41:10 +1100 Subject: [PATCH 2/2] black --- sklearn/metrics/_classification.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sklearn/metrics/_classification.py b/sklearn/metrics/_classification.py index 05e12eb4e3447..f7dd40a25ac24 100644 --- a/sklearn/metrics/_classification.py +++ b/sklearn/metrics/_classification.py @@ -1560,9 +1560,12 @@ def _check_set_wise_labels(y_true, y_pred, average, labels, pos_label): ) elif pos_label is None: warnings.warn( - "The None option for 'pos_label' was deprecated in version 1.4 " - "and will be removed in 1.6. To keep past behavior, leave 'pos_label' " - " as default value.", FutureWarning + ( + "The None option for 'pos_label' was deprecated in version 1.4 " + "and will be removed in 1.6. To keep past behavior, leave 'pos_label' " + " as default value." + ), + FutureWarning, ) elif pos_label != 1: warnings.warn(