Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Version 1.6.X: ClassifierMixIn failing with new __sklearn_tags__ function #30479

Closed
@DaMuBo

Description

@DaMuBo

Describe the bug

Hi,

we are using Sklearn in our projects for different classification training methods on production level. In the dev stage we upgraded to the latest release and our Training failed due to changes in the ClassifierMixIn Class. We use it in combination with a sklearn Pipeline.

in 1.6.X the following function was introduced:

    def __sklearn_tags__(self):
        tags = super().__sklearn_tags__()
        tags.estimator_type = "classifier"
        tags.classifier_tags = ClassifierTags()
        tags.target_tags.required = True
        return tags

It is calling the sklearn_tags methods from it's parent class. But the ClassifierMixIn doesn't have a parent class. So it says function super().sklearn_tags() is not existing.

Steps/Code to Reproduce

from sklearn.base import ClassifierMixin,
from sklearn.pipeline import Pipeline
import numpy as np

class MyEstimator(ClassifierMixin):
    def __init__(self, *, param=1):
        self.param = param
    def fit(self, X, y=None):
        self.is_fitted_ = True
        return self
    def predict(self, X):
        return np.full(shape=X.shape[0], fill_value=self.param)

X = np.array([[1, 2], [2, 3], [3, 4]])
y = np.array([1, 0, 1])


my_pipeline = Pipeline([("estimator", MyEstimator(param=1))])
my_pipeline.fit(X, y)
my_pipeline.predict(X)

Expected Results

A Prediction is returned.

Actual Results

Traceback (most recent call last):
  File "c:\Users\xxxx\error_sklearn\redo_error.py", line 22, in <module>
    my_pipeline.predict(X)
  File "C:\Users\xxxx\error_sklearn\.venv\Lib\site-packages\sklearn\pipeline.py", line 780, in predict
    with _raise_or_warn_if_not_fitted(self):
  File "C:\Program Files\Wpy64-31230\python-3.12.3.amd64\Lib\contextlib.py", line 144, in __exit__
    next(self.gen)
  File "C:\Users\xxxx\error_sklearn\.venv\Lib\site-packages\sklearn\pipeline.py", line 60, in _raise_or_warn_if_not_fitted
    check_is_fitted(estimator)
  File "C:\Users\xxxx\git_projects\error_sklearn\.venv\Lib\site-packages\sklearn\utils\validation.py", line 1756, in check_is_fitted
    if not _is_fitted(estimator, attributes, all_or_any):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\xxxx\error_sklearn\.venv\Lib\site-packages\sklearn\utils\validation.py", line 1665, in _is_fitted
    return estimator.__sklearn_is_fitted__()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\xxxx\error_sklearn\.venv\Lib\site-packages\sklearn\pipeline.py", line 1310, in __sklearn_is_fitted__
    check_is_fitted(last_step)
  File "C:\Users\xxxx\error_sklearn\.venv\Lib\site-packages\sklearn\utils\validation.py", line 1751, in check_is_fitted
    tags = get_tags(estimator)
           ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\xxxx\error_sklearn\.venv\Lib\site-packages\sklearn\utils\_tags.py", line 396, in get_tags
    tags = estimator.__sklearn_tags__()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\xxxx\error_sklearn\.venv\Lib\site-packages\sklearn\base.py", line 540, in __sklearn_tags__
    tags = super().__sklearn_tags__()
           ^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'super' object has no attribute '__sklearn_tags__'

Versions

1.6.0 / 1.6.X

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions