diff --git a/sklearn/metrics/_regression.py b/sklearn/metrics/_regression.py index b19fc2e7f3f70..43e3198e9349d 100644 --- a/sklearn/metrics/_regression.py +++ b/sklearn/metrics/_regression.py @@ -1500,12 +1500,22 @@ def d2_pinball_score( return np.average(output_scores, weights=avg_weights) +@validate_params( + { + "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" ): """ - :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` @@ -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 \ diff --git a/sklearn/tests/test_public_functions.py b/sklearn/tests/test_public_functions.py index b2d6b0da4f379..fe15f7ed4c31e 100644 --- a/sklearn/tests/test_public_functions.py +++ b/sklearn/tests/test_public_functions.py @@ -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",