Skip to content
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

MAINT parameter validation for d2_absolute_error_score #26066

Merged
merged 2 commits into from
Apr 4, 2023
Merged
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
16 changes: 13 additions & 3 deletions sklearn/metrics/_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -1500,12 +1500,22 @@ def d2_pinball_score(
return np.average(output_scores, weights=avg_weights)


@validate_params(
jeremiedbb marked this conversation as resolved.
Show resolved Hide resolved
{
"y_true": ["array-like"],
"y_pred": ["array-like"],
"sample_weight": ["array-like", None],
"multioutput": [
StrOptions({"raw_values", "uniform_average"}),
"array-like",
],
}
)
def d2_absolute_error_score(
y_true, y_pred, *, sample_weight=None, multioutput="uniform_average"
):
jeremiedbb marked this conversation as resolved.
Show resolved Hide resolved
"""
:math:`D^2` regression score function, \
fraction of absolute error explained.
:math:`D^2` regression score function, fraction of absolute error explained.

Best possible score is 1.0 and it can be negative (because the model can be
arbitrarily worse). A model that always uses the empirical median of `y_true`
Expand All @@ -1524,7 +1534,7 @@ def d2_absolute_error_score(
y_pred : array-like of shape (n_samples,) or (n_samples, n_outputs)
Estimated target values.

sample_weight : array-like of shape (n_samples,), optional
sample_weight : array-like of shape (n_samples,), default=None
Sample weights.

multioutput : {'raw_values', 'uniform_average'} or array-like of shape \
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 @@ -176,6 +176,7 @@ def _check_function_param_validation(
"sklearn.metrics.cohen_kappa_score",
"sklearn.metrics.confusion_matrix",
"sklearn.metrics.coverage_error",
"sklearn.metrics.d2_absolute_error_score",
"sklearn.metrics.d2_pinball_score",
"sklearn.metrics.d2_tweedie_score",
"sklearn.metrics.dcg_score",
Expand Down