决策树综合

一、概念

算法特征
ID3使用 信息增益 度量不纯度;可处理 离散型 数据;可用于 分类;每个节点衍生出 多个分支
C4.5使用 信息增益率 度量不纯度;可处理 离散型/连续型 数据;可用于 分类;每个节点衍生出 多个分支
CART使用 基尼系数 度量不纯度;可处理 离散型/连续型 数据;可用于 分类/回归;每个节点衍生出 两个分支

依据信息论的定义,信息的混乱程度由熵 (Entropy) 给出。假定样本数据 X X X 中有 N N N 种类别,则 H ( X ) = − ∑ j = 1 N p j log ⁡ p j H(X)=-\sum_{j=1}^N p_j \log p_j H(X)=j=1Npjlogpj 信息增益 (Information Gain) 计算一个节点中的数据划分前后的熵差值,衡量不纯度减小的程度: i n f o _ g a i n = H ( X ) − ∑ i ∣ X i ∣ ∣ X ∣ H ( X i ) info\_gain=H(X)-\sum_i \frac{|X_i|}{|X|}H(X_i) info_gain=H(X)iXXiH(Xi)信息增益的缺点是显而易见的,当某一特征(例如姓名)取值较多时,每一种取值下对应一条记录,使用该特征划分能获取极大的信息增益,但实际上训练完成的算法泛化能力极差。因此基于信息增益的 ID3 算法仅适用于处理取值较少的离散型数据。为应对此类情况,信息增益率 (Information Gain Ratio) 在信息增益的基础上做调整: i n f o _ g a i n _ r a t i o = i n f o _ g a i n H ( A ) info\_gain\_ratio=\frac{info\_gain}{H(A)} info_gain_ratio=H(A)info_gain H ( A ) H(A) H(A) 代表属性 A A A 取值的信息熵。基尼系数 (Gini Index) 则是与熵相对的另一种不纯度度量方式,公式如下: G i n i ( X ) = 1 − ∑ j = 1 N p j 2 Gini(X)=1-\sum_{j=1}^Np_j^2 Gini(X)=1j=1Npj2在 CART 算法中,我们希望最大化划分前后的基尼增益: G i n i _ g a i n = G i n i ( X ) − ∑ i ∣ X i ∣ ∣ X ∣ G i n i ( X i ) Gini\_gain=Gini(X)-\sum_i\frac{|X_i|}{|X|}Gini(X_i) Gini_gain=Gini(X)iXXiGini(Xi)学术界还有诸多其他类型的信息不纯度度量方式,在此不多赘述。

二、算法

ID3

该算法在几种决策树算法中最为简单,以下伪代码中包含了预剪枝过程(信息增益太小,或验证集表现无法继续提升),这一过程在 C4.5 和 CART 算法中同样适用。关于 ID3 算法使用信息增益作为不纯度度量标准的缺陷上文中已说明。

Algorithm ID3(Node):
Input: Object Node containing sample data.
Output: N/A.
if the depth exceeds the claimed maximum depth then label Node with y and terminate the branch
if the samples in Node is of the same class y then label Node with y and terminate the branch
if there is no remaining attribute unused then label Node with the class y with the most samples and terminate the branch
for each unused attribute A do
  calculate information gain
 select the attribute A* that maximizes information gain as the branching attribute at Node
call prunning()    # code block to terminate the branch in advance, i.e. when the information gain is too small.
 segment the samples of Node into M fractions based on their values of A*
for each segmentation Di do
  initialize child node Node_i and feed Di to the node
  recursively call ID3(Node_i)

C4.5

为避免 ID3 中特征选取偏向于取值较多的特征,C4.5 使用信息增益率作为不纯度的度量方式。同时,C4.5 增加了对连续型变量的二分法处理过程。二分法在于首先对特征取值进行排序,而后依据相邻数值的平均数生成一列二分阈值,从中挑出最佳划分点。

Algorithm C4.5(Node):
Input: Object Node containing sample data.
Output: N/A.
if the depth exceeds the claimed maximum depth then label Node with y and terminate the branch
if the samples in Node is of the same class y then label Node with y and terminate the branch
if there is no remaining attribute unused then label Node with the class y with the most samples and terminate the branch
for each unused attribute A do
  if A is discrete then
   calculate information gain ratio
  else
   select the optimal threshold value that maximizes infomation gain ratio
 select the attribute A* that maximizes information gain ratio as the branching attribute at Node
call prunning()    # code block to terminate the branch in advance, i.e. when the information gain ratio is too small.
 segment the samples of Node into M fractions based on the branching principle
for each segmentation Di do
  initialize child node Node_i and feed Di to the node
  recursively call C4.5(Node_i)

CART

CART 算法与 C4.5 相比,对离散型变量同样采用二分法处理,将树的结构约束为二叉树,同时增加了对回归任务的处理步骤。
分类问题上,CART 使用基尼增益挑选最佳划分点 (具体方法与 C4.5 类似):
ρ ∗ = arg ⁡ max ⁡ ρ [ G i n i ( X ) − ∑ i G i n i ( X i ) ] \rho^*=\arg\max_\rho \big[Gini(X)-\sum_iGini(X_i)\big] ρ=argρmax[Gini(X)iGini(Xi)]回归问题上,CART 则使用最小二乘法: ρ ∗ = arg ⁡ min ⁡ ρ [ ∑ x i &lt; ρ ( y i − y ˉ x i &lt; ρ ) 2 + ∑ x i ≥ ρ ( y i − y ˉ x i ≥ ρ ) 2 ] \rho^*=\arg\min_\rho \big[\sum_{x_i&lt;\rho}(y_i-\bar{y}_{x_i&lt;\rho})^2+\sum_{x_i\ge\rho}(y_i-\bar{y}_{x_i \ge\rho})^2\big] ρ=argρmin[xi<ρ(yiyˉxi<ρ)2+xiρ(yiyˉxiρ)2]

Algorithm CART(Node):
Input: Object Node containing sample data.
Output: N/A.
if the depth exceeds the claimed maximum depth then terminate the branch
if the samples in Node is of the same class or covers a range smaller than requirement then terminate the branch
if there is no remaining attribute unused then terminate the branch
for each unused attribute A do
  if A is discrete then
   select the optimal value that maximizes Gini gain or minimizes square values
  else
   select the optimal threshold value that maximizes Gini gain or minimizes square values
 select the attribute A* that maximizes Gini gain or minimizes square values as the branching attribute at Node
call prunning()    # code block to terminate the branch in advance, i.e. when the Gini gain is too small.
 segment the samples of Node into two fractions based on the branching principle
for each segmentation Di (i=1,2) do
  initialize child node Node_i and feed Di to the node
  recursively call CART(Node_i)

三、剪枝

为防止决策树算法过拟合,通常有预剪枝和后剪枝两种处理方式。预剪枝通过设立提前停止条件,在生成枝叶时立即执行,也即上述伪代码中的 prunning(),常见的条件有 “不纯度降低少于阈值” 和 “无法继续优化验证集表现” 等;后剪枝则在决策树生成完毕后进行修剪,通常而言也有两种做法:“使用验证集检测无法提升准确度的节点”、“应用正则化思想结合样本不纯度和模型复杂度定义新的损失函数”。以 CART 分类为例,第二种方法中的损失函数采取以下形式: L = ∑ i ∣ X i ∣ ∣ X ∣ G i n i ( X i ) + α ∣ N ∣ L=\sum_i\frac{|X_i|}{|X|}Gini(X_i)+\alpha|N| L=iXXiGini(Xi)+αN α \alpha α 是惩罚因子,该值越大则模型复杂度的惩罚越大; ∣ N ∣ |N| N 代表该节点下游子节点的数目。如果剪枝前的损失函数值大于剪枝后的值,则对该节点进行剪枝。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值