2016-12-31 26 views
-1

你好我與sklearn工作進行分類,我有標籤的分佈如下:以下SVC的最佳類別權重參數?

label : 0 frecuency : 119 
label : 1 frecuency : 1615 
label : 2 frecuency : 197 
label : 3 frecuency : 70 
label : 4 frecuency : 203 
label : 5 frecuency : 137 
label : 6 frecuency : 18 
label : 7 frecuency : 142 
label : 8 frecuency : 15 
label : 9 frecuency : 182 
label : 10 frecuency : 986 
label : 12 frecuency : 73 
label : 13 frecuency : 27 
label : 14 frecuency : 81 
label : 15 frecuency : 168 
label : 18 frecuency : 107 
label : 21 frecuency : 125 
label : 22 frecuency : 172 
label : 23 frecuency : 3870 
label : 25 frecuency : 2321 
label : 26 frecuency : 25 
label : 27 frecuency : 314 
label : 28 frecuency : 76 
label : 29 frecuency : 116 

一兩件事,顯然突出的是,我有一個不平衡的數據集工作,我有許多標籤類25,23,1,10,我在培訓後得到不好的結果如下:

   precision recall f1-score support 

      0  0.00  0.00  0.00  31 
      1  0.61  0.23  0.34  528 
      2  0.00  0.00  0.00  70 
      3  0.67  0.06  0.11  32 
      4  0.00  0.00  0.00  62 
      5  0.78  0.82  0.80  39 
      6  0.00  0.00  0.00   3 
      7  0.00  0.00  0.00  46 
      8  0.00  0.00  0.00   5 
      9  0.00  0.00  0.00  62 
     10  0.14  0.01  0.02  313 
     12  0.00  0.00  0.00  30 
     13  0.31  0.57  0.40   7 
     14  0.00  0.00  0.00  35 
     15  0.00  0.00  0.00  56 
     18  0.00  0.00  0.00  35 
     21  0.00  0.00  0.00  39 
     22  0.00  0.00  0.00  66 
     23  0.41  0.74  0.53  1278 
     25  0.28  0.39  0.33  758 
     26  0.50  0.25  0.33   8 
     27  0.29  0.02  0.03  115 
     28  1.00  0.61  0.76  23 
     29  0.00  0.00  0.00  42 

avg/total  0.33  0.39  0.32  3683 

我越來越多的零和SVC不能從幾個班學習,我現在用的是超參數如下:

from sklearn import svm 
clf2= svm.SVC(kernel='linear') 

我爲了克服這個問題,我建造一個字典,權重爲每個類如下:

weight={} 
for i,v in enumerate(uniqLabels): 
     weight[v]=labels_cluster.count(uniqLabels[i])/len(labels_cluster) 

for i,v in weight.items(): 
     print(i,v) 
print(weight) 

這些都是分開的數字輸出,我只是把determinated標籤的元素的數量總在標籤元件設置的,這些數字的總和爲1:

0 0.010664037996236221 
1 0.14472622994892015 
2 0.01765391164082803 
3 0.006272963527197778 
4 0.018191594228873554 
5 0.012277085760372793 
6 0.0016130477641365713 
7 0.012725154583744062 
8 0.0013442064701138096 
9 0.01630970517071422 
10 0.0883591719688144 
12 0.0065418048212205395 
13 0.002419571646204857 
14 0.007258714938614571 
15 0.015055112465274667 
18 0.009588672820145173 
21 0.011201720584281746 
22 0.015413567523971682 
23 0.34680526928936284 
25 0.20799354780894344 
26 0.0022403441168563493 
27 0.028138722107715744 
28 0.006810646115243301 
29 0.01039519670221346 

與此字典權重再次試圖如下:

from sklearn import svm 
clf2= svm.SVC(kernel='linear',class_weight=weight) 

我:

   precision recall f1-score support 

      0  0.00  0.00  0.00  31 
      1  0.90  0.19  0.31  528 
      2  0.00  0.00  0.00  70 
      3  0.00  0.00  0.00  32 
      4  0.00  0.00  0.00  62 
      5  0.00  0.00  0.00  39 
      6  0.00  0.00  0.00   3 
      7  0.00  0.00  0.00  46 
      8  0.00  0.00  0.00   5 
      9  0.00  0.00  0.00  62 
     10  0.00  0.00  0.00  313 
     12  0.00  0.00  0.00  30 
     13  0.00  0.00  0.00   7 
     14  0.00  0.00  0.00  35 
     15  0.00  0.00  0.00  56 
     18  0.00  0.00  0.00  35 
     21  0.00  0.00  0.00  39 
     22  0.00  0.00  0.00  66 
     23  0.36  0.99  0.52  1278 
     25  0.46  0.01  0.02  758 
     26  0.00  0.00  0.00   8 
     27  0.00  0.00  0.00  115 
     28  0.00  0.00  0.00  23 
     29  0.00  0.00  0.00  42 

avg/total  0.35  0.37  0.23  3683 

由於我沒有收到良好的效果我很欣賞的建議來自動調整每個類的權重,並表示,在SVC,我不有很多expierience不平衡問題的處理,因此所有這些建議很好收到。

回答

1

看來你正在做你應該做的事情的對立面。特別是,你想要的是在較小的類上加上較高的權重,這樣在訓練這些類時分類器會受到更多的懲罰。開始的好處是設置class_weight="balanced"

+0

是的,我同意你的觀點我正在做的與我的方法相反,我想反映我的數據集在這些數字中的真實情況,現在我相信我需要使用這些數字來構建一個實現相反的新規則但考慮到這些數字 - – neo33

相關問題