C++,python,热爱算法和机器学习
全部博文(1214)
分类: IT职场
2015-01-29 14:44:10
参考:
1. Wiki上的
2. 百度文库里的一个PPT,有算例, 3. 百度文库,PPT,很多算例,开始有信息理论,极力推荐阅读,4.用Python实现ID3和C4.5 决策树ID3和C4.5算法Python实现源码
下面是整理的学习笔记。
用途:
The ID3 algorithm is used by training on a dataset to produce a which is stored in memory. At runtime, this decision tree is used to classify new unseen test cases by working down the decision tree using the values of this test case to arrive at a terminal node that tells you what class this test case belongs to.
基本思想:
角度1. 越是小型的决策树越优于大的决策树(尽管如此该算法也不是总是生成最小的树形结构)
角度2. 引入信息论中互信息(信息增益),作为判别因素的度量,即:以信息熵的下降速度作为选取测试属性的标准,所选的测试属性是从根到当前节点的路径上尚未被考虑的具有最高信息增益的属性
算法描述:
If S is a collection of 14 examples with 9 YES and 5 NO examples then
Notice entropy is 0 if all members of S belong to the same class(the data is perfectly classified). The range of entropy is 0("perfectly classified") to 1 ("totally random").
Gain(S, A) is information gain of example set S on attribute A is defined as
Where:
S is each value v of all possible values of attribute A
Sv = subset of S for which attribute A has value v
|Sv| = number of elements in Sv
|S| = number of elements in S
Suppose S is a set of 14 examples in which one of the attributes is wind speed. The values of Wind can be Weak or Strong.The classification of these 14 examples are 9 YES and 5 NO. For attribute Wind, suppose there are 8 occurrences of Wind = Weak and 6 occurrences of Wind = Strong. For Wind = Weak, 6 of the examples are YES and 2 are NO. For Wind = Strong, 3 are YES and3 are NO. Therefore
= 0.940 - (8/14)*0.811 - (6/14)*1.00
= 0.048
Entropy(Sweak) = - (6/8)*log2(6/8) - (2/8)*log2(2/8)= 0.811
Entropy(Sstrong) = - (3/6)*log2(3/6) - (3/6)*log2(3/6)= 1.00
For each attribute, the gain is calculated and the highest gain is used in the decision node.
selects the attribute which has the smallest entropy (or largest information gain) value.