To solve AttributeError: ‘SMOTE’ object has no attribute ‘fit_sample’ error follow below methods.
Code that causes error :
from imblearn.over_sampling import SMOTE
smt = SMOTE(random_state=0)
X_train, y_train = smt.fit_sample(X_train, y_train)
ERROR LOG
AttributeError: ‘SMOTE’ object has no attribute ‘fit_sample’
How to solve AttributeError: ‘SMOTE’ object has no attribute ‘fit_sample’ ?
The error AttributeError: ‘SMOTE’ object has no attribute ‘fit_sample’ is caused due to incorrect function you are using. If you import SMOTE using the below code like this then you should use fit_resample() instead of fit_sample.
from imblearn.over_sampling import SMOTE
you need to do fit_resample()
oversample = SMOTE()
X, y = oversample.fit_resample(X, y)
Hope the above solution works.
Also read :