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 调节后预测的结果所表示概率确实已经没有参考意义了。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章