RandomUnderSampler' object has no attribute 'fit_resample'

10,497

The method fit_resample was introduced lately to imbalanced-learn API. Either update imbalanced-learn or use fit_sample instead.

Share:
10,497
hsbr13
Author by

hsbr13

Updated on June 09, 2022

Comments

  • hsbr13
    hsbr13 almost 2 years

    I am using RandomUnderSampler from imblearn, but I get the following error. Any ideas? Thanks

    from imblearn.under_sampling import RandomUnderSampler
    print('Initial dataset shape %s' % Counter(y.values.squeeze()))
    rus = RandomUnderSampler(random_state=42)
    X_undersampled, y_undersampled = rus.fit_resample(X, y)
    y_undersampled = y_undersampled.squeeze()
    

    output:

    Initial dataset shape Counter({0: 2499739, 1: 1558})
    
    ---------------------------------------------------------------------------
    AttributeError                            Traceback (most recent call last)
    <ipython-input-18-4fe9dcfbd68e> in <module>
          1 print('Initial dataset shape %s' % Counter(y.values.squeeze()))
          2 rus = RandomUnderSampler(random_state=42)
    ----> 3 X_undersampled, y_undersampled = rus.fit_resample(X, y)
          4 y_undersampled = y_undersampled.squeeze()
          5 
    
    AttributeError: 'RandomUnderSampler' object has no attribute 'fit_resample'
    

    main libraries I am using:

    imbalanced-learn==0.3.3
    pandas==0.24.2
    numpy==1.15.4
    scikit-learn==0.19.2
    
  • Pramit
    Pramit almost 4 years
    Had a similar problem few days back. Had to use fit_sample from version 0.6.2
  • Miguel Rueda
    Miguel Rueda almost 4 years
    @Pramit Same issue here using the version 0.7.0 and 0.22.1 sci-kit version.
  • Miguel Rueda
    Miguel Rueda almost 4 years
    I solved this problem by updating the scikit-learn version to 0.23.1