Closed
Description
Describe the bug
Describe the bug
Since upgrading to scikit-learn 1.6.1, the utility function is_classifier
always returns False
for custom classifier wrappers, even if they inherit from ClassifierMixin
and explicitly define _estimator_type = "classifier"
.
This was not the case in previous versions (<=1.5.x), and breaks many downstream code patterns relying on is_classifier
, as well as certain custom scorer usages and checks.
Steps/Code to Reproduce
import sklearn
print("scikit-learn version:", sklearn.__version__)
from sklearn.base import BaseEstimator, ClassifierMixin, is_classifier
from sklearn.ensemble import RandomForestClassifier
class BinCls(BaseEstimator, ClassifierMixin):
_estimator_type = "classifier"
def __init__(self, model=None):
self.model = model
def fit(self, X, y):
self.model.fit(X, y)
self.classes_ = self.model.classes_
return self
def predict(self, X):
return self.model.predict(X)
def predict_proba(self, X):
return self.model.predict_proba(X)
rng = RandomForestClassifier()
clf = BinCls(rng)
print("is_classifier(clf) =", is_classifier(clf)) # Expect True, but gets False
### Expected Results
print("is_classifier(clf) =", is_classifier(clf)) # Expect True, but gets False
### Actual Results
print("is_classifier(clf) =", is_classifier(clf)) # Expect True, but gets False
### Versions
```shell
System:
python: 3.12.9 | packaged by Anaconda, Inc. | (main, Feb 6 2025, 18:49:16) [MSC v.1929 64 bit (AMD64)]
executable: C:\Users\Greg\anaconda3\envs\ml_trade\python.exe
machine: Windows-10-10.0.19045-SP0
Python dependencies:
sklearn: 1.6.1
pip: 25.0
setuptools: 72.1.0
numpy: 2.1.3
scipy: 1.15.2
Cython: 3.1.1
pandas: 2.2.3
matplotlib: 3.10.0
joblib: 1.4.2
threadpoolctl: 3.5.0
Built with OpenMP: True
threadpoolctl info:
user_api: blas
internal_api: mkl
num_threads: 4
prefix: mkl_rt
filepath: C:\Users\Greg\anaconda3\envs\ml_trade\Library\bin\mkl_rt.2.dll
version: 2023.1-Product
threading_layer: intel
user_api: openmp
internal_api: openmp
num_threads: 8
prefix: vcomp
filepath: C:\Users\Greg\anaconda3\envs\ml_trade\vcomp140.dll
version: None