Add. Information gain ratio

pull/2/head
benjas 4 years ago
parent 8e29c1a94a
commit 9592593d16

@ -95,3 +95,121 @@ Example
如果有1个坏苹果和9个好苹果时我们可以认为大部分都是坏苹果。内部并不混乱确定性很大熵很小。
### 信息增益
Information gain
表示得知特征X的信息而使得类Y的信息的不确定性减少的程度。
特征A对训练集D的信息增益g(D,A)定义为集合D的经验熵H(D)与特征A给定条件下D的经验条件熵H(D|A)之差g(D, A) = H(D) - H(D|A)
当前的信息熵等于划分完(如划分成两个)的信息熵之和。
**信息增益算法**
输入训练数据集D和特征A
输出特征A对训练数据集D的信息
1. 计算数据集D的经验熵H(D)
![1618582986891](assets/1618582986891.png)
2. 计算特征A对数据集D的经验条件熵H(D|A)
![1618583056578](assets/1618583056578.png)
![1618583066653](assets/1618583066653.png)
3. 计算信息增益
![1618583156554](assets/1618583156554.png)
### 举个例子
Example
是否信贷
| ID | 年龄 | 有工作 | 有自己房子 | 信贷情况 | 类别 |
| ---- | ---- | ------ | ---------- | -------- | ---- |
| 1 | 青年 | 否 | 否 | 一般 | 否 |
| 2 | 青年 | 否 | 否 | 好 | 否 |
| 3 | 青年 | 是 | 否 | 好 | 是 |
| 4 | 青年 | 是 | 是 | 一般 | 是 |
| 5 | 青年 | 否 | 否 | 一般 | 否 |
| 6 | 中年 | 否 | 否 | 一般 | 否 |
| 7 | 中年 | 否 | 否 | 好 | 否 |
| 8 | 中年 | 是 | 是 | 好 | 是 |
| 9 | 中年 | 否 | 是 | 非常好 | 是 |
| 10 | 中年 | 否 | 是 | 非常好 | 是 |
| 11 | 老年 | 否 | 是 | 非常好 | 是 |
| 12 | 老年 | 否 | 是 | 好 | 是 |
| 13 | 老年 | 是 | 否 | 好 | 是 |
| 14 | 老年 | 是 | 否 | 非常好 | 是 |
| 15 | 老年 | 否 | 否 | 一般 | 否 |
对上表所给的训练数据集D根据信息增益准则选择最优特征。首先计算经验熵H(D)
![1618747519765](assets/1618747519765.png)
> 计算类别一共15个类别9个是6个否
然后计算各特征对数据集D的信息增益分别以A1,A2,A3,A4表示年龄、有工作、有自己房子和信贷情况4个特征
1. 首先计算年龄![1618747694405](assets/1618747694405.png)
> H(D)=0.971上面计算了H(D1)青年H(D2)中年H(D3)老年
2. 计算有工作
![1618747990121](assets/1618747990121.png)
> H(D)=0.971H(D1)是有工作H(D2)是无工作
3. 计算有无房子
![1618748039172](assets/1618748039172.png)
4. 计算信贷情况
![1618748063199](assets/1618748063199.png)
有无房子是作为信贷的第一个划分,下降的最快
### 信息增益比
Information gain ratio
**信息增益比:**
如果以信息增益为划分依据,存在偏向选择取值较多的特征,信息增益是对这一问题进行矫正。
**举例**
如上面的例子后面加入了身份证这个特征身份证又是唯一的算法对样本画了个15叉树一层就搞定了全部的分类。
这样会造成一个问题,划分会倾向于特征取值数目较多的,即分的更快。
但在预测集上就出现很大的问题了,即预测集的身份证肯定也是唯一的。
**定义:**
特征A对训练数据集D的信息增益比![1618748316870](assets/1618748316870.png)定义为其信息增益g(D,A)与训练数据集D关于特征A的经验熵H(D)之比:
![1618749594369](assets/1618749594369.png)
**计算**
如上面的年龄有3个类青年、中年、老年![1618749717493](assets/1618749717493.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 159 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Loading…
Cancel
Save