我正在使用 RandomUnderSampler 中的 imblearn ,但出现以下错误。有任何想法吗?谢谢

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

输出:
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'

我正在使用的主要库:
imbalanced-learn==0.3.3
pandas==0.24.2
numpy==1.15.4
scikit-learn==0.19.2

最佳答案

fit_resample 方法最近被引入到 imbalanced-learn API 中。要么更新 imbalanced-learn,要么改用 fit_sample

关于python - RandomUnderSampler' 对象没有属性 'fit_resample',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57466592/

10-12 16:58