Search code examples
pythonimbalanced-datasmoteoversampling

How to correct Python Attribute error: 'SMOTE' object has no attribute 'fit_sample'


Hello: I am trying to run the following code:

os = SMOTE(random_state=0)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)
columns = X_train.columns
os_data_X,os_data_y=os.fit_sample(X_train, y_train)

But get the error message described above - AttributeError: 'SMOTE' object has no attribute 'fit_sample'

I am using imbalanced-learn version 0.8.0 and scikit-learn version 0.24.1.

Thank you for any suggestions you can provide. I have imbalanced classes and am trying to adjust the sampling.


Solution

  • fit_sample was renamed to fit_resample in v0.4.

    Replace with:

    os_data_X, os_data_y = os.fit_resample(X_train, y_train)
    

    See documentation here: https://imbalanced-learn.org/stable/references/generated/imblearn.over_sampling.SMOTE.html