Repository navigation
Description
Describe the bug and give evidence about its user-facing impact
There's currently 2 classifiers with array API support:
LogisticRegressionRidgeClassifier
The docs and discussions in this issue tracker are quite unclear about what should be the expected behavior when input types are mixed in the case of classifiers.
Since in general 'y' can be something like strings or non-sequential integers that get re-encoded internally, I think it makes sense that the classes_ attributes under array API would be obtained from the type of 'y' and then sliced when returning something from .predict() - i.e. "prediction follows 'y'".
This appears to be the case for LogisticRegression:
import os
os.environ["SCIPY_ARRAY_API"] = "1"
import numpy as np
import torch
rng = np.random.default_rng(seed=123)
X = rng.random(size=(20,3))
y = rng.integers(2, size=X.shape[0])
yt = torch.tensor(y, device="xpu", dtype=torch.float32)
from sklearn import set_config
from sklearn.linear_model import LogisticRegression
set_config(array_api_dispatch=True)
model = LogisticRegression(solver="lbfgs").fit(X, yt)
model.classes_tensor([0., 1.], device='xpu:0')
But the docs state "everything follows 'X'" instead, and RidgeClassifier does appear to follow this logic from the docs, even if it might not be as natural for classification scenarios:
from sklearn.linear_model import RidgeClassifier
model = RidgeClassifier(solver="svd").fit(X, yt)
model.classes_array([0., 1.], dtype=float32)
Steps/Code to Reproduce
Described above.
Expected Results
All classifiers with array API support should work like in LogisticRegression.
Actual Results
RidgeClassifier works differently.
Versions
System:
python: 3.13.13 | packaged by conda-forge | (main, Apr 8 2026, 02:00:33) [GCC 14.3.0]
executable: /export/users/dcortes/miniforge3/envs/torch19/bin/python
machine: Linux-6.17.0-20-generic-x86_64-with-glibc2.39
Python dependencies:
sklearn: 1.9.dev0
pip: 26.1.1
setuptools: 70.2.0
numpy: 2.4.4
scipy: 1.17.1
Cython: 3.2.4
pandas: 3.0.3
matplotlib: None
joblib: 1.5.3
threadpoolctl: 3.6.0
Built with OpenMP: True
threadpoolctl info:
user_api: blas
internal_api: openblas
num_threads: 64
prefix: libscipy_openblas
filepath: /mnt/cached_oses/dcortes/miniforge3/envs/torch19/lib/python3.13/site-packages/numpy.libs/libscipy_openblas64_-32a4b2a6.so
version: 0.3.31.188.0
threading_layer: pthreads
architecture: SkylakeX
user_api: blas
internal_api: openblas
num_threads: 64
prefix: libscipy_openblas
filepath: /mnt/cached_oses/dcortes/miniforge3/envs/torch19/lib/python3.13/site-packages/scipy.libs/libscipy_openblas-6cdc3b4a.so
version: 0.3.30
threading_layer: pthreads
architecture: SkylakeX
user_api: openmp
internal_api: openmp
num_threads: 112
prefix: libgomp
filepath: /mnt/cached_oses/dcortes/miniforge3/envs/torch19/lib/libgomp.so.1.0.0
version: NoneInterest in fixing the bug
No.
Activity
david-cortes-intel commentedon May 18, 2026
Also related to discussion in #33822
ogrisel commentedon May 20, 2026
Thanks for the report. I believe
RidgeClassifierhas not yet been updated to pass the newly introduced common tests for estimators with mixed namespace inputs:I think that it should be changed to behave as
LogisticRegressiondoes.