AttributeError: 'SMOTE' object has no attribute 'fit_sample'

user12088653 picture user12088653 · Feb 25, 2021 · Viewed 9.3k times · Source

Hi can anyone help why I am getting AttributeError: 'SMOTE' object has no attribute 'fit_sample' error? I don't think this code should cause any error? Thanks

from imblearn.over_sampling import SMOTE
smt = SMOTE(random_state=0)
X_train_SMOTE, y_train_SMOTE = smt.fit_sample(X_train, y_train)

Answer

Subbu VidyaSekar picture Subbu VidyaSekar · Feb 25, 2021

If you import like this

from imblearn.over_sampling import SMOTE

you need to do fit_resample()

oversample = SMOTE()
X, y = oversample.fit_resample(X, y)