XGBoost特点、调参、讨论

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/niaolianjiulin/article/details/76574216

XGBoost是在GBDT(梯度提升决策树)基础上发展而来。

GBDT含有几个关键点:梯度提升,提升决策树,回归问题。

本质模型为加法模型,基函数为决策树,迭代拟合标注和模型的残差,来不断逼近损失函数最小化。更一般的情况,以当前模型在L负梯度方向的值,作为残差的近似。

XGBoost(eXtreme Gradient Boosting)针对GBDT框架,加入了很多改进点。

1. XGB的特点

(1)传统GBDT以CART作为基函数,xgb还支持线性分类器,此时XGB相当于来L1/L2正则化项的LR(分类)或者Liear R(回归)。

booster [default=gbtree]
设置参数:gbtree: tree-based models/gblinear: linear models

(2)传统GBDT在优化时只用到一阶导数信息(负梯度),xgboost则对代价函数进行了二阶泰勒展开,同时用到一阶和二阶导数。且xgboost工具支持自定义代价函数,只要函数可一阶和二阶求导。

(3)xgboost在代价函数里加入了正则项,控制模型复杂度。正则项里包含了树的叶节点个数、每个叶子节点上输出的score的L2模的平方和。从Bias-variance tradeoff角度来讲,正则项降低了模型variance,使学习出来的模型更加简单,防止过拟合,这也是xgboost优于传统GBDT的一个特性。 剪枝是都有的,叶子节点输出L2平滑是新增的。

(4)shrinkage缩减和column_subsampling
shrinkage缩减:类似于学习速率,在每一步tree boosting之后增加了一个参数n(权重),通过这种方式来减小每棵树的影响力,给后面的树提供空间去优化模型。
column subsampling:列(特征)抽样,随机森林那边学习来的,防止过拟合的效果比传统的行抽样还好(行抽样功能也有),并且有利于后面提到的并行化处理算法。

(5)split finding algorithms(划分点查找算法)
树节点在进行分裂时,我们需要计算每个特征的每个分割点对应的增益,即用贪心法 greedy algorithm枚举所有可能的分割点。当数据无法一次载入内存或者在分布式情况下,贪心算法效率就会变得很低,所以xgboost还提出了一种可并行的近似approximate algorithm直方图算法Weighted Quantile Sketch,用于高效地生成候选的分割点。

(6)对缺失值的处理。对于特征的值有缺失的样本,xgboost可以自动学习出它的分裂方向。 稀疏感知算法 Sparsity-aware Split Finding

(7)Built-in Cross-Validation(内置交叉验证)
XGBoost allows user to run a cross-validation at each iteration of the boosting process and thus it is easy to get the exact optimum number of boosting iterations in a single run.
This is unlike GBM where we have to run a grid-search and only a limited values can be tested.

(8)High Flexibility(高灵活性)
XGBoost allow users to define custom optimization objectives and evaluation criteria.
This adds a whole new dimension to the model and there is no limit to what we can do.

(9)xgboost支持并行,提高计算速度。

2. XGB并行化

boosting不是一种串行的结构吗?怎么并行的?

注意xgboost的并行不是在tree粒度的并行,xgboost也是一次迭代完才能进行下一次迭代的(第t次迭代的代价函数里包含了前面t-1次迭代的预测值)。

xgboost的并行是在特征粒度上的(是在构建树的过程中)。我们知道,决策树的学习最耗时的一个步骤就是对特征的值进行排序(因为要确定最佳分割点),xgboost在训练之前,预先对数据进行排序,然后保存为block结构,后面的迭代中重复地使用这个结构,大大减小计算量。

这个block结构也使得并行成为了可能,在进行节点分裂时,需要计算每个特征的增益,最终选增益最大的那个特征去做分裂,那么各个特征的增益计算就可以开多线程进行。

这里写图片描述

构建树包括外层循环和内层循环。外层循环是构建树的子节点中,对子节点分别使用CART,那么此处可以并行化处理。内层循环是在某个节点做CART,需要遍历特征列,确定特征及特征最佳分割点,此处也可以并行。

3. XGB关键调参

3.1 常规参数

(1)booster [default=gbtree]:选择基分类器
gbtree: tree-based models/gblinear: linear models

(2)silent [default=0]:设置成1则没有运行信息输出,最好是设置为0.

(3)nthread [default to maximum number of threads available if not set]:线程数

3.2 模型参数

(1)eta:shrinkage参数,更新叶子节点权重时,乘以该系数避免步长过大。

(2)min_child_weight:default=1]参数默认是 1,每个叶子里面 h 的和至少是多少,对正负样本不均衡时的 0-1 分类而言,假设 h 在 0.01 附近,min_child_weight 为 1 意味着叶子节点中最少需要包含 100 个样本。这个参数非常影响结果,控制叶子节点中二阶导的和的最小值,该参数值越小,越容易 overfitting。

(3) max_depth [default=6]:每颗树最大深度,树高越深,叶节点越多,越容易过拟合。

(4)max_leaf_nodes:最大叶结点数,与max_depth作用有点重合。

(5) gamma [default=0]:后剪枝时,用于控制是否后剪枝的参数。

(6)max_delta_step [default=0]:这个参数在更新步骤中起作用,如果取0表示没有约束,如果取正值则使得更新步骤更加保守。可以防止做太大的更新步子,使更新更加平缓。

(7)subsample [default=1]:样本随机采样,较低的值使得算法更加保守,防止过拟合,但是太小的值也会造成欠拟合。是Bagging思想,样本扰动。

(8)colsample_bytree [default=1]:列采样,对每棵树的生成用的特征进行列采样。一般设置为: 0.5-1。如RF的思想,属性扰动。

(9) lambda [default=1]:控制模型复杂度的权重值的L2正则化项参数,参数越大,模型越不容易过拟合。 (叶节点上输出的score的L2模的平方和)

(10)alpha [default=0]:控制模型复杂程度的权重值的 L1 正则项参数,参数值越大,模型越不容易过拟合。 (叶节点个数)

(11)scale_pos_weight [default=1]:如果取值大于0的话,在类别样本不平衡的情况下有助于快速收敛。

3.3 学习任务参数

(1)objective [default=reg:linear]:定义最小化损失函数类型。

常用参数:
binary:logistic –logistic regression for binary classification, returns 预测概率值 (not class)

multi:softmax –multiclass classification using the softmax objective, returns 预测的类别 (not probabilities)
you also need to set an additional num_class (number of classes) parameter defining the number of unique classes

multi:softprob –same as softmax, but returns predicted probability of each data point belonging to each class.

(2)eval_metric [ default according to objective ]: The metric to be used for validation data.

The default values are rmse for regression and error for classification.

Typical values are:

rmse – root mean square error
mae – mean absolute error
logloss – negative log-likelihood
error – Binary classification error rate (0.5 threshold)
merror – Multiclass classification error rate
mlogloss – Multiclass logloss
auc: Area under the curve

(3)seed [default=0]:
The random number seed. 随机种子,用于产生可复现的结果
Can be used for generating reproducible results and also for parameter tuning.

注意::
python sklearn参数名会有所变化
eta –> learning_rate
lambda –> reg_lambda
alpha –> reg_alpha


参考资料

XGB原理
http://blog.csdn.net/sb19931201/article/details/52557382
http://blog.csdn.net/a819825294/article/details/51206410

译文:XGB调参
http://blog.csdn.net/hhy518518/article/details/54988024

并行化策略
http://zhanpengfang.github.io/418home.html

知乎:GBDT和XGB的区别?为何快?并行策略?
https://www.zhihu.com/question/41354392

比XGBOOST更快–LightGBM介绍
https://zhuanlan.zhihu.com/p/25308051

猜你喜欢

转载自blog.csdn.net/niaolianjiulin/article/details/76574216
今日推荐