Skip to content

MAINT Parameters validation for metrics.fbeta_score #25840

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
Show file tree
Hide file tree
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
33 changes: 28 additions & 5 deletions sklearn/metrics/_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,25 @@ def f1_score(
)


@validate_params(
{
"y_true": ["array-like", "sparse matrix"],
"y_pred": ["array-like", "sparse matrix"],
"beta": [Interval(Real, 0.0, None, closed="both")],
"labels": ["array-like", None],
"pos_label": [Real, str, "boolean", None],
"average": [
StrOptions({"micro", "macro", "samples", "weighted", "binary"}),
None,
],
"warn_for": [list, tuple, set],
"sample_weight": ["array-like", None],
"zero_division": [
Options(Real, {0, 1}),
StrOptions({"warn"}),
],
}
)
def fbeta_score(
y_true,
y_pred,
Expand Down Expand Up @@ -2743,9 +2762,11 @@ def log_loss(
else:
# TODO: Remove user defined eps in 1.5
warnings.warn(
"Setting the eps parameter is deprecated and will "
"be removed in 1.5. Instead eps will always have"
"a default value of `np.finfo(y_pred.dtype).eps`.",
(
"Setting the eps parameter is deprecated and will "
"be removed in 1.5. Instead eps will always have"
"a default value of `np.finfo(y_pred.dtype).eps`."
),
FutureWarning,
)

Expand Down Expand Up @@ -2812,8 +2833,10 @@ def log_loss(
y_pred_sum = y_pred.sum(axis=1)
if not np.isclose(y_pred_sum, 1, rtol=1e-15, atol=5 * eps).all():
warnings.warn(
"The y_pred values do not sum to one. Starting from 1.5 this"
"will result in an error.",
(
"The y_pred values do not sum to one. Starting from 1.5 this"
"will result in an error."
),
UserWarning,
)
y_pred = y_pred / y_pred_sum[:, np.newaxis]
Expand Down
1 change: 1 addition & 0 deletions sklearn/tests/test_public_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def _check_function_param_validation(
"sklearn.metrics.dcg_score",
"sklearn.metrics.det_curve",
"sklearn.metrics.f1_score",
"sklearn.metrics.fbeta_score",
"sklearn.metrics.get_scorer",
"sklearn.metrics.hamming_loss",
"sklearn.metrics.jaccard_score",
Expand Down