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

[WIP] Add array-api support to metrics.confusion_matrix #28867

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

charlesjhill
Copy link

@charlesjhill charlesjhill commented Apr 21, 2024

Reference Issues/PRs

See #26024 for the array-api meta-issue tracking the "tools" in sklearn.

What does this implement/fix? Explain your changes.

This PR adds array-api compatibility to the sklearn.metrics.confusion_matrix method, aiming to support all of its current API surface. Many other classification metrics are or can be computed based on a confusion matrix so it seems fairly high value to port.

TODO:

  • Complete porting confusion_matrix test suite to check other array namespaces.

Any other comments?

None for now :)

Copy link

github-actions bot commented Apr 21, 2024

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: 2ea2722. Link to the linter CI: here

Copy link
Member

@ogrisel ogrisel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick feedback.

# import array_api_strict as xp
X = xp.asarray(X, copy=copy)
dtype = X.dtype
isscaler = X.ndim == 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: scaler => scalar.

msg = (
"Cannot return indices with the torch backend yet. See" " array_api_compat."
)
raise NotImplementedError(msg)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have opened data-apis/array-api-compat#135. If array_api_compat maintainers accept this suggestion, then it might be worth contributing such a temporary workaround to array_api_compat. If not, we can implement our own temporary workaround for torch in scikit-learn.

yield namespace, "cuda"
yield namespace, "mps"
else:
yield namespace, None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for this. There once this is in, we should do a follow-up PR for occurrences of yield_namespace_device_dtype_combinations that discard the dtype value to avoid redundant test cases.

@ogrisel
Copy link
Member

ogrisel commented May 7, 2024

Please also add a changelog entry in v1.6.rst as soon as #27381 is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants