[英]How to use combination of over- and undersampling? with imbalanced learn
我想对一些大数据进行重新采样(类大小:8mio vs 2700)我想通过对 class 2 进行过采样和对 class 1 进行欠采样来获得 50.000 个样本。imblearn 似乎提供了一个过采样和过采样的组合作品。
from collections import Counter
from imblearn.over_sampling import SMOTENC
from imblearn.under_sampling import TomekLinks
from imblearn.combine import SMOTETomek
smt = SMOTETomek(random_state=1)
X_resamp, y_resamp = smt.fit_resample(data_all[29000:30000], labels_all[29000:30000])
在数据看起来像之前
>>Counter(labels_all[29000:30000])
>>Counter({0: 968, 9: 32})
之后
>>Counter(y_resamp)
>>Counter({0: 968, 9: 968})
正如我所期望或希望的那样
>>Counter(y_resamp)
>>Counter({0: 100, 9: 100})
似乎您只有 32 条记录 class 9
,因此它对 class 进行采样并将其数据记录与 class 0
的数据记录对齐,因此为9: 968
您正在谈论将数据集减少到 100 条记录,您可以从X
和Y
(相同的 100 条记录)中为每个 class 随机抽样 100 条记录,或者像y_resamp[:100]
一样获取前 100 条记录
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.