我在使用sklearn.utils resample时有些困惑。
使用不平衡的数据集,我试图对多数类进行随机下采样。一切运行正常,但是当我刚刚意识到使用(replace = True)的模型的性能确实得到了显着改善时。
这里的性能提高背后的原因是什么?样品是否被复制的样品代替?这里有没有过度拟合的地方?
我对此有些陌生,因此,非常感谢您在此进行任何澄清。
这是代码的一部分,它对整体进行了重大更改。
from sklearn.utils import resample
Negative = sms[sms.Label == 'Neg']
Positive = sms[sms.Label == 'Pos']
# Upsample minority class
df_Negative_res = resample(Negative,replace=True,# sample with replacement
n_samples=243,# to match majority class
random_state=seed ) # reproducible results
df_Positive_res = resample(Positive,# to match majority class
random_state=seed) # reproducible results
# Combine majority class with upsampled minority class
sms = pd.concat([df_Negative_res,df_Positive_res])
print(sms)