Skip to content

array API support for mean_gamma_deviance #29239

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

Merged
merged 9 commits into from
Jun 13, 2024
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
1 change: 1 addition & 0 deletions doc/modules/array_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ Metrics
- :func:`sklearn.metrics.d2_tweedie_score`
- :func:`sklearn.metrics.max_error`
- :func:`sklearn.metrics.mean_absolute_error`
- :func:`sklearn.metrics.mean_gamma_deviance`
- :func:`sklearn.metrics.mean_squared_error`
- :func:`sklearn.metrics.mean_tweedie_deviance`
- :func:`sklearn.metrics.pairwise.cosine_similarity`
Expand Down
1 change: 1 addition & 0 deletions doc/whats_new/v1.6.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ See :ref:`array_api` for more details.
- :func:`sklearn.metrics.d2_tweedie_score` :pr:`29207` by :user:`Emily Chen <EmilyXinyi>`;
- :func:`sklearn.metrics.max_error` :pr:`29212` by :user:`Edoardo Abati <EdAbati>`;
- :func:`sklearn.metrics.mean_absolute_error` :pr:`27736` by :user:`Edoardo Abati <EdAbati>`;
- :func:`sklearn.metrics.mean_gamma_deviance` :pr:`29239` by :usser:`Emily Chen <EmilyXinyi>`;
- :func:`sklearn.metrics.mean_squared_error` :pr:`29142` by :user:`Yaroslav Korobko <Tialo>`;
- :func:`sklearn.metrics.mean_tweedie_deviance` :pr:`28106` by :user:`Thomas Li <lithomas1>`;
- :func:`sklearn.metrics.pairwise.cosine_similarity` :pr:`29014` by :user:`Edoardo Abati <EdAbati>`.
Expand Down
2 changes: 1 addition & 1 deletion sklearn/metrics/_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,7 @@ def mean_tweedie_deviance(y_true, y_pred, *, sample_weight=None, power=0):
raise ValueError(message + "non-negative y and strictly positive y_pred.")
elif power >= 2:
# Gamma and Extreme stable distribution, y and y_pred > 0
if (y_true <= 0).any() or (y_pred <= 0).any():
if xp.any(y_true <= 0) or xp.any(y_pred <= 0):
raise ValueError(message + "strictly positive y and y_pred.")
else: # pragma: nocover
# Unreachable statement
Expand Down
3 changes: 2 additions & 1 deletion sklearn/metrics/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1827,7 +1827,7 @@ def check_array_api_multiclass_classification_metric(


def check_array_api_regression_metric(metric, array_namespace, device, dtype_name):
y_true_np = np.array([2.0, 0.0, 1.0, 4.0], dtype=dtype_name)
y_true_np = np.array([2.0, 0.1, 1.0, 4.0], dtype=dtype_name)
y_pred_np = np.array([0.5, 0.5, 2, 2], dtype=dtype_name)

metric_kwargs = {}
Expand Down Expand Up @@ -1955,6 +1955,7 @@ def check_array_api_metric_pairwise(metric, array_namespace, device, dtype_name)
check_array_api_regression_metric,
],
paired_cosine_distances: [check_array_api_metric_pairwise],
mean_gamma_deviance: [check_array_api_regression_metric],
max_error: [check_array_api_regression_metric],
}

Expand Down