scikit-learn-contrib / imbalanced-learn

A Python Package to Tackle the Curse of Imbalanced Datasets in Machine Learning
https://imbalanced-learn.org
MIT License
6.85k stars 1.29k forks source link

[BUG] `sklearn=1.4` TypeError: BaggingClassifier.__init__() got an unexpected keyword argument 'base_estimator' #1060

Closed ayaanhossain closed 10 months ago

ayaanhossain commented 10 months ago

@glemaitre When using the BalancedBaggingClassifier using sklearn=1.4 as the backend, I encountered

TypeError: BaggingClassifier.__init__() got an unexpected keyword argument 'base_estimator'

Looking further, inside imblearn/ensemble/_bagging.py the following code snippet may be responsible.

# TODO: remove when supporting scikit-learn>=1.2
bagging_classifier_signature = inspect.signature(super().__init__)
estimator_params = {"base_estimator": base_estimator}
if "estimator" in bagging_classifier_signature.parameters:
    estimator_params["estimator"] = estimator
else:
    self.estimator = estimator

Perhaps, as the TODO suggests, this snippet needs to be adjusted since we're way past sklearn=1.2?

EDIT: Perhaps, the issue is even deeper. I tried commenting parts of the above snippet, but still run into a similar base_estimator parameter error during parameter validation steps incurred by some of the parent classes for BalancedBaggingClassifier.

EDIT2: Okay, so the fixes are being worked on in the development branch. I installed the 0.12-dev from this git repository, and things seem to be working.