[英]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.