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 :AttributeError: can't set attribute #6

Closed
leaphan opened this issue Nov 25, 2021 · 8 comments
Closed

Bug :AttributeError: can't set attribute #6

leaphan opened this issue Nov 25, 2021 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@leaphan
Copy link

leaphan commented Nov 25, 2021

hello ,when i use the code as follow,the will be some errors, EasyEnsembleClassifier was used

from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from sklearn.metrics import balanced_accuracy_score
from sklearn.ensemble import BaggingClassifier
from sklearn.tree import DecisionTreeClassifier
from imbalanced_ensemble.ensemble import EasyEnsembleClassifier
from collections import Counter

X, y = make_classification(n_classes=2, class_sep=2,
weights=[0.1, 0.9], n_informative=3, n_redundant=1, flip_y=0,
n_features=20, n_clusters_per_class=1, n_samples=1000, random_state=10)
print('Original dataset shape %s' % Counter(y))

Original dataset shape Counter({{1: 900, 0: 100}})

X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)
bbc = EasyEnsembleClassifier(random_state=42)
bbc.fit(X_train, y_train)
EasyEnsembleClassifier(...)
y_pred = bbc.predict(X_test)
print(y_pred)

Traceback (most recent call last):
File "C:/Users/Administrator/PycharmProjects/pythonProject5/test-easy.py", line 16, in
bbc.fit(X_train, y_train)
File "C:\Users\Administrator\PycharmProjects\pythonProject5\venv\lib\site-packages\imbalanced_ensemble\utils_validation.py", line 602, in inner_f
return f(**kwargs)
File "C:\Users\Administrator\PycharmProjects\pythonProject5\venv\lib\site-packages\imbalanced_ensemble\ensemble\under_sampling\easy_ensemble.py", line 275, in fit
return self._fit(X, y,
File "C:\Users\Administrator\PycharmProjects\pythonProject5\venv\lib\site-packages\imbalanced_ensemble\utils_validation.py", line 602, in inner_f
return f(**kwargs)
File "C:\Users\Administrator\PycharmProjects\pythonProject5\venv\lib\site-packages\imbalanced_ensemble\ensemble_bagging.py", line 359, in fit
n_samples, self.n_features
= X.shape
AttributeError: can't set attribute

@ZhiningLiu1998
Copy link
Owner

image

Hi leaphan,

Thanks for your interest, but I cannot reproduce your error.
I completely reinstalled IMBENS from PyPI in my local environment and ran your example code, but nothing happened.
This may be caused by the inconsistent python version.
I'm using python 3.8.5, it would be helpful for me to locate the error and debug if you can provide more detailed system information, e.g., the version of python and main dependencies like NumPy, scipy, sklearn, etc.

@ZhiningLiu1998 ZhiningLiu1998 self-assigned this Nov 25, 2021
@ZhiningLiu1998 ZhiningLiu1998 added the bug Something isn't working label Nov 25, 2021
@leaphan
Copy link
Author

leaphan commented Nov 25, 2021

thanks for your reply. i'm using python 3.8

1637838498(1)

@leaphan
Copy link
Author

leaphan commented Nov 25, 2021

python3.8.8

1637839798(1)

@leaphan
Copy link
Author

leaphan commented Nov 25, 2021

1637840500(1)

@ZhiningLiu1998
Copy link
Owner

Thanks for your help! I reproduced the error using python 3.8.

I've confirmed that this is caused by the property naming (n_features_), which is now depreciated in sklearn.
This issue should have been fixed by my recent commit.
You can now install from this Github repository:

$ git clone https://github.com/ZhiningLiu1998/imbalanced-ensemble.git
$ cd imbalanced-ensemble
$ pip install .

and EasyEnsemble as well as other bagging-based methods should work well.

Please feel free to contact me if you have any further questions or find any other bugs.

Best,
Zhining

@leaphan
Copy link
Author

leaphan commented Nov 25, 2021

Thanks for your help! I reproduced the error using python 3.8.

I've confirmed that this is caused by the property naming (n_features_), which is now depreciated in sklearn. This issue should have been fixed by my recent commit. You can now install from this Github repository:

$ git clone https://github.com/ZhiningLiu1998/imbalanced-ensemble.git
$ cd imbalanced-ensemble
$ pip install .

and EasyEnsemble as well as other bagging-based methods should work well.

Please feel free to contact me if you have any further questions or find any other bugs.

Best, Zhining

thank u very much,i got the result with your help!

@ZhiningLiu1998
Copy link
Owner

@all-contributors please add @leaphan for the bug reporting

@allcontributors
Copy link
Contributor

@ZhiningLiu1998

I've put up a pull request to add @leaphan! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants