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
base: main
Are you sure you want to change the base?
[WIP] Add array-api support to metrics.confusion_matrix #28867
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
Please also add a changelog entry in |
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:
Any other comments?
None for now :)