Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] 'BalancedBaggingClassifier' and 'EasyEnsembleClassifier' objects have no attribute 'n_features_in_' #872

Closed
breisfeld opened this issue Nov 5, 2021 · 9 comments

Comments

@breisfeld
Copy link

breisfeld commented Nov 5, 2021

Describe the bug

Error when using BalancedBaggingClassifier or EasyEnsembleClassifier methods shown in the documentation: https://imbalanced-learn.org/stable/ensemble.html

Steps/Code to Reproduce

Following examples from the documentation...

model = BalancedBaggingClassifier(base_estimator=DecisionTreeClassifier(),
                                sampling_strategy='auto',
                                replacement=False,
                                random_state=0)
model.fit(X_train, y_train)

or

model = EasyEnsembleClassifier(random_state=0)
model.fit(X_train, y_train)

Actual Results

AttributeError                            Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_247760/4241213219.py in <module>
      8                                 random_state=0)
      9 #model = LGBMClassifier(is_unbalance=True, learning_rate=0.6, n_estimators=500,  random_state=random_state)
---> 10 model.fit(X_train, y_train)

~\anaconda3\envs\iarc_chemicals\lib\site-packages\imblearn\ensemble\_bagging.py in fit(self, X, y)
    319         # RandomUnderSampler is not supporting sample_weight. We need to pass
    320         # None.
--> 321         return self._fit(X, y, self.max_samples, sample_weight=None)
    322 
    323     def _more_tags(self):

~\anaconda3\envs\iarc_chemicals\lib\site-packages\sklearn\ensemble\_bagging.py in _fit(self, X, y, max_samples, max_depth, sample_weight)
    335             max_features = self.max_features
    336         elif isinstance(self.max_features, float):
--> 337             max_features = self.max_features * self.n_features_in_
    338         else:
    339             raise ValueError("max_features must be int or float")

AttributeError: 'BalancedBaggingClassifier' object has no attribute 'n_features_in_'

Similar error for EasyEnsembleClassifier

Versions

Windows-10-10.0.19043-SP0
Python 3.9.7 | packaged by conda-forge | (default, Sep 29 2021, 19:15:42) [MSC v.1916 64 bit (AMD64)]
NumPy 1.20.3
SciPy 1.7.1
Scikit-Learn 1.0.1
Imbalanced-Learn 0.8.1

@breisfeld breisfeld changed the title [BUG] 'BalancedBaggingClassifier' object has no attribute 'n_features_in_' [BUG] 'BalancedBaggingClassifier' and 'EasyEnsembleClassifier' objects have no attribute 'n_features_in_' Nov 5, 2021
@leaphan
Copy link

leaphan commented Nov 24, 2021

i have the same question ,Have you found a solution

@YasCoMa
Copy link

YasCoMa commented Nov 24, 2021

You have to downgrade the scikit-learn package using: pip3 install scikit-learn==1.0 -U
The attribute n_features_in_ is deprecated and its support was lost in sklearn version 1.2

@YasCoMa
Copy link

YasCoMa commented Nov 24, 2021

i have the same question ,Have you found a solution

I just posted the solution for me if you still need it!

@leaphan
Copy link

leaphan commented Nov 25, 2021

You have to downgrade the scikit-learn package using: pip3 install scikit-learn==1.0 -U The attribute n_features_in_ is deprecated and its support was lost in sklearn version 1.2

okay,i will try it,thank u very much!

@glemaitre
Copy link
Member

We solve the problem in master but we would need to release with a more constraint limitation regarding the version of scikit-learn

@glemaitre
Copy link
Member

I solved the issue in master. I will release it shortly. Basically, we broke some expectations in scikit-learn by moving some validation outside from _fit.

tjmcdowelldotcom added a commit to tjmcdowelldotcom/Classification that referenced this issue Dec 16, 2021
Please note there is a known bug in 'EasyEnsembleClassifier' code!
scikit-learn-contrib/imbalanced-learn#872
@lopezjuana
Copy link

I solved the issue in master. I will release it shortly. Basically, we broke some expectations in scikit-learn by moving some validation outside from _fit.

Cómo se resuelve el problema?

@jaymon0703
Copy link

I solved the issue in master. I will release it shortly. Basically, we broke some expectations in scikit-learn by moving some validation outside from _fit.

Hi @glemaitre which commit and release was the fix deployed with? Thank you!

@glemaitre
Copy link
Member

certainly 0.9.0. We realeased 0.9.1 since

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants