信息增益和特征工程
特征工程(feature engineering)中很关键的一个组成部分是特征选择(feature selection)。特征选择是一个重要的“数据预处理”(data preprocessing)过程。从给定的特征集合中选择出相关特征(relevant feature)子集的过程,称为特征选择。
特征选择的过程可以由“子集搜索”(subset search)和“子集评价”(subset evaluation)组成。简单来说,这个过程就是产生一个“候选子集”,评价出它的好坏,基于评价结果产生下一个候选子集,再对其进行评价。持续这个过程,直至无法找到更好的候选子集。
子集搜索的方法有前向搜索、后向搜索、双向搜索等。
评价方式中比较常见的有基于信息增益的评价方式,本文将介绍这种方式,并举出一个例子。
数据
Outlook | Temperature | Humidity | Windy | Play? |
---|---|---|---|---|
sunny | hot | high | false | no |
sunny | hot | high | true | no |
overcast | hot | high | false | yes |
rain | mild | high | false | yes |
rain | cool | normal | false | yes |
rain | cool | normal | true | no |
overcast | cool | normal | true | yes |
sunny | mild | high | false | no |
sunny | cool | normal | false | yes |
rain | mild | normal | false | yes |
sunny | mild | normal | true | yes |
overcast | mild | high | true | yes |
overcast | hot | normal | false | yes |
rain | mild | high | true | no |
天气预报数据例子
信息熵
信息熵的公式为:
这里定义数据集为 D 则原始数据集的信息熵为:
信息增益
信息增益的公式:
假设选择的是outlook特征,则此时根据这一特征D分成了三个子集:
分别计算这三个子集的信息熵:
将三个子集的信息熵分别乘以三个子集各自的个数和数据集的总个数的比值再求和:
最后用原始数据的信息熵 Ent(D) 减去上式得到的值,就得到了信息增益。
信息增益率
截止到目前,我们已经得到了一个评价特征是否有效的方法:计算信息增益。当信息增益越大时,说明选择的特征包含的可供分类的信息越多。
然而以上这个结论是要基于一个假设的:所有的特征都是离散型特征,如天气数据表中的数据一样。
当出现连续型数值时,基于信息增益的评价方式将出现问题。
如:现在在天气数据的基础上加上一列特征:day of month
day of month | Outlook | Temperature | Humidity | Windy | Play? |
---|---|---|---|---|---|
1 | sunny | hot | high | false | no |
2 | sunny | hot | high | true | no |
3 | overcast | hot | high | false | yes |
4 | rain | mild | high | false | yes |
5 | rain | cool | normal | false | yes |
6 | rain | cool | normal | true | no |
7 | overcast | cool | normal | true | yes |
8 | sunny | mild | high | false | no |
9 | sunny | cool | normal | false | yes |
10 | rain | mild | normal | false | yes |
11 | sunny | mild | normal | true | yes |
12 | overcast | mild | high | true | yes |
13 | overcast | hot | normal | false | yes |
14 | rain | mild | high | true | no |
此时day of month的信息增益将非常大,因为其为不重复且连续的14个值。
这里就将使用信息增益率来评价,其定义为:
其中, a 为特征,
由此可以得出,day of month的 IV 也会比较大,导致其信息增益率较低。
信息增益、信息增益率和决策树
决策树有两种很常见的剪枝方法:ID3、C4.5
其中ID3使用信息增益剪枝,选择那些信息增益大的特征机型保留。
C4.5使用的是信息增益率,但是需要注意的是,增益率准则对可取值数目较少的属性有所偏好,因此C4.5算法并不是直接使用信息增益率最大的候选划分属性,而是使用了一个启发式:先从候选划分属性中找出信息增益高于平均水平的属性,在从中选择增益率最高的。