xgboost 參數 scale_pos_weight 詳解

話不多說,首先讓我們看官網對此參數的解讀。
API 中這樣說:

scale_pos_weight : float
      Balancing of positive and negative weights.

Parameter Tuning —— Handle Imbalanced Dataset 中這樣說:

For common cases such as ads clickthrough log, the dataset is extremely imbalanced. This can affect the training of xgboost model, 
and there are two ways to improve it.
  If you care only about the ranking order (AUC) of your prediction
      Balance the positive and negative weights, via scale_pos_weight
      Use AUC for evaluation
  If you care about predicting the right probability
      In such a case, you cannot re-balance the dataset
      In such a case, set parameter max_delta_step to a finite number (say 1) will help convergence

官網的意思大致可理解如下:
- scale_pos_weight 是用來調節正負樣本不均衡問題的,用助於樣本不平衡時訓練的收斂。
- 如何你僅僅關注預測問題的排序或者AUC指標,那麼你儘管可以調節此參數。如果你希望得到真正的預測概率則不能夠通過此參數來平衡樣本。什麼意思呢,讓我們來舉個例子:加入我們現在需要通過體重來預測男女,有三個人體重分別爲50kg、60kg、70kg。假設他們是男生的真正概率是:0.4、0.6、0.8。那麼好,我現在模型預測出的概率爲:0.7、0.8、0.9。如果講預測概率的話,顯然模型效果很差,但是我們預測的男生概率的排序以及 ROU 曲線(包括對應 AUC 值)都不會改變。


那麼問題來了,源碼到底是怎麼利用 scale_pos_weight 來平衡樣本的呢,是調節權重還是過採樣呢?我是沒有精力讀源碼了,但是有人在 github 的開源 Issues 給出瞭如下:

if (info.labels[i] == 1.0f) w *= param_.scale_pos_weight

可以看出,應該是增大了少數樣本的學習率。


還有問題就是我參加的比賽是個二分類問題,樣本也是極不平衡,但是評價標準不是 AUC 而是直接的目標損失函數:logloss
實驗證明如下:

  1. 如果我用 logloss 作爲驗證指標,scale_pos_weights 取 1 也就是不加權重時,logloss 更小,而改爲 10(實際不平衡的情況比10倍更嚴重) 以後 logloss 下降慢而且最終 logloss 相對大很多。
  2. 如果我用 AUC 作爲指標則結果正好相反。
  3. 最終結果來看,用 scale_pos_weights 調節後預測的結果所表示概率確實已經沒有參考意義了。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章