ZhiningLiu1998 / imbalanced-ensemble

🛠️ Class-imbalanced Ensemble Learning Toolbox. | 类别不平衡/长尾机器学习库
https://imbalanced-ensemble.readthedocs.io
MIT License
326 stars 51 forks source link

Bug :AttributeError: can't set attribute #6

Closed leaphan closed 2 years ago

leaphan commented 2 years ago

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.nfeatures = X.shape AttributeError: can't set attribute

ZhiningLiu1998 commented 2 years ago

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.

leaphan commented 2 years ago

thanks for your reply. i'm using python 3.8

1637838498(1)

leaphan commented 2 years ago

python3.8.8

1637839798(1)

leaphan commented 2 years ago

1637840500(1)

ZhiningLiu1998 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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

allcontributors[bot] commented 2 years ago

@ZhiningLiu1998

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