Skip to content

Compatibility issue: _IsotonicRegression class not inheriting from scikit-learn's BaseEstimator #163

@cyrfar

Description

@cyrfar

When calibrating a model using classifier.calibrate(X_cal, Y_cal) and calibration_method='isotonic', an AttributeError is raised during probability prediction. The error message says that _IsotonicRegression object has no attribute __sklearn_tags__. This seems to be due to the _IsotonicRegression class not inheriting from scikit-learn's BaseEstimator, which is required for compatibility with scikit-learn. Similar errors occurs with other calibration methods.

To Reproduce
Steps to reproduce the behavior:

  1. Install hiclass and scikit-learn in a Python environment.
  2. Run the full example code from the docs:
from sklearn.ensemble import RandomForestClassifier

from hiclass import LocalClassifierPerNode

# Define data
X_train = [[1], [2], [3], [4]]
X_test = [[4], [3], [2], [1]]
X_cal = [[5], [6], [7], [8]]
Y_train = [
    ["Animal", "Mammal", "Sheep"],
    ["Animal", "Mammal", "Cow"],
    ["Animal", "Reptile", "Snake"],
    ["Animal", "Reptile", "Lizard"],
]

Y_cal = [
    ["Animal", "Mammal", "Cow"],
    ["Animal", "Mammal", "Sheep"],
    ["Animal", "Reptile", "Lizard"],
    ["Animal", "Reptile", "Snake"],
]

# Use random forest classifiers for every node
rf = RandomForestClassifier()

# Use local classifier per node with isotonic regression as calibration method
classifier = LocalClassifierPerNode(
    local_classifier=rf, calibration_method="isotonic", probability_combiner="multiply"
)

# Train local classifier per node
classifier.fit(X_train, Y_train)

# Calibrate local classifier per node
classifier.calibrate(X_cal, Y_cal)

# Predict probabilities
probabilities = classifier.predict_proba(X_test)

# Print probabilities and labels for the last level
print(classifier.classes_[2])
print(probabilities)

Expected behavior
The code should run without errors and return calibrated probability predictions for the test set.

Screenshots
N/A. Here is the error trace

AttributeError: The following error was raised: '_IsotonicRegression' object has no attribute '__sklearn_tags__'. It seems that there are no classes that implement sklearn_tagsin the MRO and/or all classes in the MRO callsuper().sklearn_tags(). Make sure to inherit from BaseEstimatorwhich implementssklearn_tags(or alternatively definesklearn_tagsbut we don't recommend this approach). Note thatBaseEstimator needs to be on the right side of other Mixins in the inheritance order.

Desktop (please complete the following information):

  • OS: MacOS Tahoe 26.2
  • Version: Python 3.12, hiclass 5.0.4, scikit-learn 1.8.0

Additional context
The issue goes away when downgrading to scikit-learn 1.7.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions