gpt4 book ai didi

python - 重新抽样查询

转载 作者:行者123 更新时间:2023-12-01 00:15:58 24 4
gpt4 key购买 nike

我在这里使用 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 , replace=True, # sample with replacement
n_samples=243 , # 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)

最佳答案

通过进行过采样/欠采样,您实际上可以改变不平衡数据集的分布,并尝试提高模型的性能。所以,它实际上可以被认为是一种增强方法。已经有关于替换重采样的讨论,所以我建议您看一下: https://stats.stackexchange.com/questions/171440/bootstrap-methodology-why-resample-with-replacement-instead-of-random-subsamp为了查明您的模型是否过度拟合,您需要一个大型测试集(没有任何过采样等),并且该测试集必须与您的训练集不同。如果您的模型表现良好,则过度拟合的可能性就会降低。但是,当进行过采样/欠采样时,您仍然会影响数据的偏差。因此,关键是要找出你的模型是否可以很好地概括未见过的样本。在训练集上它应该表现得非常好(在一般情况下)。在进行交叉验证时,还必须考虑一些非常重要的事情 - 您是在每个折叠内还是在整个数据集上应用采样?这是关于该主题的讨论https://www.researchgate.net/post/should_oversampling_be_done_before_or_within_cross-validation希望我的回答对您有帮助!

关于python - 重新抽样查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59333630/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com