XGB算法梳理
学习内容:
1.CART树
2.算法原理
3.损失函数
4.分裂结点算法
5.正则化
6.对缺失值处理
7.优缺点
8.应⽤场景
9.sklearn参数
1.CART树
  CART算法是⼀种⼆分递归分割技术,把当前样本划分为两个⼦样本,使得⽣成的每个⾮叶⼦结点都有两个分⽀,因此CART算法⽣成的决策树是结构简洁的⼆叉树。由于
CART算法构成的是⼀个⼆叉树,它在每⼀步的决策时只能是“是”或者“否”,即使⼀个feature有多个取值,也是把数据分为两部分。在CART算法中主要分为两个步骤
将样本递归划分进⾏建树过程
⽤验证数据进⾏剪枝
2.算法原理
  输⼊:训练数据集D,停⽌计算的条件;
  输出:CART决策树。
  根据训练数据集,从根结点开始,递归地对每个结点进⾏⼀下操作,构建⼆叉决策树:
  1)设结点的训练数据集为D,计算现有特征对该点数据集的基尼指数。此时,对每个特征A,对其可
能取的每个值a,根据样本点计算对A = a的测试为“是”或“否”讲D分割
成D_1和D_2两部分,计算A = a时的基尼指数。
  2)在所有可能的特征A以及他们所有可能的切分点a中,选择基尼指数最⼩的特征及其对应的切分点作为最优切分点,依最有特征与最优切分点,从现结点⽣成两个⼦结
点,将训练数据集依特征分配到两个⼦结点中去。
  3)对两个⼦结点递归地调⽤1),2),直⾄满⾜停⽌条件。
  4)⽣成CART决策树。
3.损失函数
  L = \sum\limits_{x_i \leq R_m} (y_i - f(x_i))^2 + \sum\limits_{i=1}^K \Omega (f_k)
4.分裂结点算法
  使⽤基尼指数⽤于分裂结点的依据
  概率分布的基尼指数定义为:Gini(p) = \sum\limits_{k=1}^K p_k (1-p_k) = 1 - \sum\limits_{k=1}^K p_k^2
  如果样本那集合D根据特征A是否取某⼀可能值a被分割成D_1和D_2两部分,即D_1 = \{(x,y) \leq D | A(x) = a \} , D_2 = D - D_1
  根据基尼指数值越⼤,样本集合不确定性就越⼤。
5.正则化
  标准GBM的实现没有像XGBoost这样的正则化步骤。正则化对减少过拟合也是有帮助的。实际上,XGBoost以“正则化提升(regularized boosting)”技术⽽闻名。
  \Omega (f) = \gamma T +  \frac{1}{2} \lambda ||\omega||^2
6.对缺失值处理
  XGBoost内置处理缺失值的规则。⽤户需要提供⼀个和其它样本不同的值,然后把它作为⼀个参数传进去,以此来作为缺失值的取值。XGBoost在不同节点遇到缺失值时采
⽤不同的处理⽅法,并且会学习未来遇到缺失值时的处理⽅法。
7.优缺点
优点:
  XGBoost可以实现并⾏处理,相⽐GBM有了速度的飞跃,LightGBM也是微软最新推出的⼀个速度提升的算法。 XGBoost也⽀持Hadoop实现。
  XGBoost⽀持⽤户⾃定义⽬标函数和评估函数,只要⽬标函数⼆阶可导就⾏。
8.应⽤场景
  评分系统,智能垃圾邮件识别,⼴告推荐系统
9.sklearn参数
 class xgboost.XGBRegressor(max_depth=3, learning_rate=0.1, n_estimators=100, silent=True, objective='reg:linear', booster='gbtree', n_jobs=1, nthread=None, gamma=0, min_child_weight=1, max_delta_step=0  max_depth: 参数类型() – Maximum tree depth for base learners. 树的最⼤深度
  learning_rate: 参数类型() – Boosting learning rate (xgb’s “eta”).学习率
  n_estimators: 参数类型() – Number of boosted trees to fit.优化树的个数
  silent: 参数类型(boolean) – Whether to print messages while running boosting.在运⾏过程中是否打印流程
  objective: 参数类型(string or callable) – Specify the learning task and the corresponding learning objective or a custom objective function to be used (see note below).明确
学习任务
  booster: 参数类型(string) – Specify which booster to use: gbtree, gblinear or dart.指定使⽤的booster
  nthread: 参数类型() – Number of parallel threads used to run xgboost. (Deprecated, please use n_jobs).多线程
  n_jobs: 参数类型() – Number of parallel threads used to run xgboost. (replaces nthread).多线程
  gamma: 参数类型() – Minimum loss reduction required to make a further partition on a leaf node of the tree.增加分⽀时减少的最少损失
  min_child_weight: 参数类型() – Minimum sum of instance weight(hessian) needed in a child.叶节点最⼩权重
  max_delta_step: 参数类型() – Maximum delta step we allow each tree’s weight estimation to be.最⼤迭代次数
  subsample: 参数类型() – Subsample ratio of the training instance.训练样本的采样率
  colsample_bytree: 参数类型() – Subsample ratio of columns when constructing each tree.构建树时下采样率
  colsample_bylevel: 参数类型() – Subsample ratio of columns for each split, in each level.构建每⼀分⽀时下采样率
  reg_alpha: 参数类型( (xgb's alpha)) – L1 regularization term on weights.L1正则化权重
  reg_lambda: 参数类型( (xgb's lambda)) – L2 regularization term on weights.L2正则化权重
  scale_pos_weight: 参数类型() – Balancing of positive and negative weights.正负样本⽐率
  base_score: – The initial prediction score of all instances, global bias.初始实例分数
  seed: 参数类型() – Random number seed. (Deprecated, please use random_state).随机种⼦
  random_state: 参数类型() – Random number seed. (replaces seed).随机种⼦
正则化算法调用  missing:参数类型(, optional) – Value in the data which needs to be present as a missing value. If None, defaults to np.nan.当出现缺失值时,使⽤该值代替。
  importanc_type:参数类型(string, default "gain") – The feature importance type for the  property: either “gain”, “weight”, “cover”, “total_gain” or “total_cover”.特征重要类型  **kwargs: 参数类型(, optional) –Keyword arguments for XGBoost Booster object. Full documentation of parameters can be found here:
Processing math: 0%

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。