Repository navigation
FIX: RidgeClassifier.classes_ should follow array API y namespace - #34065
Conversation
| if y_is_array_api and xp_y.isdtype(y.dtype, "numeric"): | ||
| self.classes_ = move_to( | ||
| self._label_binarizer.classes_, xp=xp, device=device_ | ||
| ) | ||
| else: | ||
| self.classes_ = self._label_binarizer.classes_ |
There was a problem hiding this comment.
Context on why we can now always rely on LabelBinarizer.classes_ directly here:
LinearClassifierMixin.predict already handles classes_ in its own namespace and only moves the final predictions back to the namespace/device of X:
scikit-learn/sklearn/linear_model/_base.py
Lines 420 to 427 in 97889bd
So classes_ does not need to be eagerly moved during fit.
|
I think we need a changelog entry to document the fix for this one. |
ogrisel
left a comment
There was a problem hiding this comment.
LGTM besides the following. I am fine with merging this PR as is and continue the work in follow-up PRs.
| pred_xp = ridge_xp.predict(X_xp) | ||
| assert pred_xp.shape == pred_np.shape == y.shape | ||
| assert_allclose(move_to(pred_xp, xp=np, device="cpu"), pred_np) | ||
| assert_array_equal(move_to(ridge_xp.classes_, xp=np, device="cpu"), classes_np) |
There was a problem hiding this comment.
I checked _check_array_api_core and the classes_ attribute is skipped from the check, so at the moment the common tests do not enforce any consistency with respect to the namespace, device and value of this attribute.
I think we should explicitly set expectations in the array API doc and then update the common test. We can do that either in this PR or in a follow-up issue+PR.
This is particularly the case for string class labels, but the particular case of string class labels can be handled in a dedicated follow-up PR.
Testing classifiers with string labels was originally explored in #33525 but wasn't included in the end so we still need to expand the testing harness for this, possibly with a dedicated common test.
There was a problem hiding this comment.
Testing classifiers with string labels was originally explored in #33525 but wasn't included in the end
Ah yes, I have it as a todo, but did not open an issue.
ref: #33525 (comment)
Happy to open an issue unless someone wants to work on it now/soon?
There was a problem hiding this comment.
I think I prefer to merge this PR as it is, so you can open the issue, thanks!
There was a problem hiding this comment.
Sorry I did not mean in this PR, just soon in a separate PR.
I'll open an issue.
There was a problem hiding this comment.
Sorry I did not mean in this PR, just soon in a separate PR.
Yes that's what I understood :) I was answering this part of @ogrisel's comment:
We can do that either in this PR or in a follow-up issue+PR.
Let's go for the follow-up issue+PR solution where you open the issue ;) (or maybe I'm mixing different topics? 🤔 )
There was a problem hiding this comment.
@lucyleeow: if you open the issue for common testing classifier with array API X and string labels in y, then we should make sure to test both .fit and .score: #33822 and as a result we will indirectly test integration for mixed namespace with string label support for some common classification metrics.
There was a problem hiding this comment.
as a result we will indirectly test integration for mixed namespace with string label support for some common classification metrics.
Good point, though we do already do this in test_array_api_classification_mixed_string_numeric_input in metrics test_common.py ?
Co-authored-by: Olivier Grisel <[email protected]>
|
@lucyleeow shall we merge this, then? |
|
Yes go ahead! |
…34065) Co-authored-by: Olivier Grisel <[email protected]>
Reference Issues/PRs
Fixes #34047
What does this implement/fix? Explain your changes.
As decided in the issue,
RidgeClassifier.classes_should follow array API y namespace likeLogisticRegressiondoes.AI usage disclosure
I used AI assistance for:
Any other comments?
Intel array API CI run: https://github.com/probabl-ai/scikit-learn-intel-workflow/actions/runs/26164735798 ✅