Thanks to visit codestin.com
Credit goes to github.com

Skip to content

MAINT Deprecate None option in pos_label for precison/recall/f1 and jaccard metrics #27762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion sklearn/metrics/_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -1546,14 +1558,24 @@ 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 "
"labels=[pos_label] to specify a single positive class."
% (pos_label, average),
UserWarning,
)

return labels


Expand Down Expand Up @@ -1646,6 +1668,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
Expand Down Expand Up @@ -2076,6 +2102,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.
Expand Down Expand Up @@ -2254,6 +2284,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.
Expand Down