Search code examples
pythonpython-3.xmachine-learningattributeerrorimblearn

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


Why I am getting the error

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

I don't think this code should cause any error?

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

Solution

  • 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)