|
23 | 23 | # License: BSD 3 clause
|
24 | 24 |
|
25 | 25 |
|
| 26 | +from numbers import Integral, Real |
26 | 27 | import warnings
|
27 | 28 | import numpy as np
|
28 | 29 |
|
|
40 | 41 | from ..utils.multiclass import type_of_target
|
41 | 42 | from ..utils.validation import _num_samples
|
42 | 43 | from ..utils.sparsefuncs import count_nonzero
|
43 |
| -from ..utils._param_validation import StrOptions, validate_params |
| 44 | +from ..utils._param_validation import StrOptions, Options, validate_params |
44 | 45 | from ..exceptions import UndefinedMetricWarning
|
45 | 46 |
|
46 | 47 | from ._base import _check_pos_label_consistency
|
@@ -1038,6 +1039,23 @@ def zero_one_loss(y_true, y_pred, *, normalize=True, sample_weight=None):
|
1038 | 1039 | return n_samples - score
|
1039 | 1040 |
|
1040 | 1041 |
|
| 1042 | +@validate_params( |
| 1043 | + { |
| 1044 | + "y_true": ["array-like", "sparse matrix"], |
| 1045 | + "y_pred": ["array-like", "sparse matrix"], |
| 1046 | + "labels": ["array-like", None], |
| 1047 | + "pos_label": [Real, str, "boolean", None], |
| 1048 | + "average": [ |
| 1049 | + StrOptions({"micro", "macro", "samples", "weighted", "binary"}), |
| 1050 | + None, |
| 1051 | + ], |
| 1052 | + "sample_weight": ["array-like", None], |
| 1053 | + "zero_division": [ |
| 1054 | + Options(Integral, {0, 1}), |
| 1055 | + StrOptions({"warn"}), |
| 1056 | + ], |
| 1057 | + } |
| 1058 | +) |
1041 | 1059 | def f1_score(
|
1042 | 1060 | y_true,
|
1043 | 1061 | y_pred,
|
@@ -1083,7 +1101,7 @@ def f1_score(
|
1083 | 1101 | .. versionchanged:: 0.17
|
1084 | 1102 | Parameter `labels` improved for multiclass problem.
|
1085 | 1103 |
|
1086 |
| - pos_label : int, float, bool or str, default=1 |
| 1104 | + pos_label : int, float, bool, str or None, default=1 |
1087 | 1105 | The class to report if ``average='binary'`` and the data is binary.
|
1088 | 1106 | If the data are multiclass or multilabel, this will be ignored;
|
1089 | 1107 | setting ``labels=[pos_label]`` and ``average != 'binary'`` will report
|
|
0 commit comments