Reputation:
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)
Upvotes: 33
Views: 64472
Reputation: 11
Another way
from imblearn.combine import SMOTEENN
Sm=SMOTEENN()
X, y=Sm.fit_resample(X, y)
Upvotes: 1
Reputation: 23171
It used to be fit_sample
but was renamed fit_resample
with an alias for backward compatibility in imblearn 0.4 (this was documented). Then the alias was removed in version 0.8 (for some reason it was not documented). In short, SMOTE().fit_sample(X_train, y_train)
used to work but not anymore.
Now only SMOTE().fit_resample(X_train, y_train)
works.
Also, all imblearn objects have a fit()
method defined as well but it's completely useless because everything it does is already done by fit_resample()
anyway (the documentation even urges you to use fit_resample()
over fit()
).
Upvotes: 0
Reputation: 2615
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)
Upvotes: 50