[英]How to Classify the imbalanced Dataset using SVM
我正在使用 SVM,我的數據集不平衡。 我得到的結果是將 Class 0 分類為 99%,將 Class 1 分類為 1%。 有什么方法可以使用 SVM 正確分類不平衡數據集。
您可以通過多種方式處理不平衡的數據集。 我最常用的幾個:
Penalize for wrong output: If class A
has much less samples than class B
, then you can increase the penalty incurred for incorrect classification of class A
.
使用SMOTE模塊。 它基本上采用給定 class 中兩個點的凸組合,並將其分配給與兩個選定點相同的 label。
其他可能的選項包括查看不同的評估指標和驗證策略,例如Stratified K Fold 。
有幾種方法可以調整不平衡數據集以將其用於回歸/分類。 這里我將描述過采樣和欠采樣的方法。
在過采樣中,即使數據中的行完全相同,您也會復制少數 class 的數據。 在欠采樣中,您選擇具有 class 1 的所有數據,並選擇具有 label 0 的相同數量的樣本(如果您有大量樣本,這只是一個不錯的選擇)。
您也可以混合使用兩者。 就像是:
def obtain_equal_idx(idx_0, idx_1, n_samples, ratio_unbalance):
idx_1_repeated = np.repeat(idx_1, (n_samples // len(idx_1)) + 1)
idx_0s = np.random.choice(idx_0, ratio_unbalance * (n_samples // 2), replace=False)
idx_delay = np.random.choice(idx_1_repeated, n_samples // 2, replace=False)
return np.concatenate([idx_0s, idx_delay])
idx_0
是標記為 0 的整個數據集的索引, idx_1
與標記為 1 的數據相同, n_samples
是您想要獲取的樣本數, ratio_unbalance
是允許數據的數字(通常為 2 或 3)你會有點不平衡,所以你的 model 知道數據不完全平衡。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.