AttributeError: 'RandomOverSampler' 对象没有属性 'fit_sample'

问题描述

我正在尝试使用 imblearn 的 RandomOverSampler,但出现错误

查看其他帖子,似乎旧版本有问题,但我检查了我的版本,我有

sklearn.__version__
'0.24.1'

imblearn.__version__
'0.8.0'

这是我要运行的代码

from imblearn.over_sampling import RandomOverSampler

OS = RandomOverSampler(sampling_strategy='auto',random_state=0)
osx,osy = OS.fit_sample(X,y)

我得到的错误是:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-9-a080b92fc7bc> in <module>
      2 
      3 OS = RandomOverSampler(sampling_strategy='auto',random_state=0)
----> 4 osx,y)

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

解决方法

你想要OS.fit_resample(X,y),而不是fit_sample

,

您需要 OS.fit_resample(X,y),而不是 fit_resample。