Add. Build the decision tree

pull/2/head
benjas 6 years ago
parent 9592593d16
commit 464f107928

@ -213,3 +213,24 @@ Information gain ratio
如上面的年龄,有3个类(青年、中年、老年),![1618749717493](assets/1618749717493.png)
信息增益比和信息增益的区别就是除以![1618749843112](assets/1618749843112.png)
### 决策树的构建
Build the decision tree
ID3算法:
- 输入:训练数据集D,特征A,阈值ε ;
- 输出:决策树T
1. 若D中所有实例属于同一类![1618749968444](assets/1618749968444.png),则T为单节点数,并将类![1618749968444](assets/1618749968444.png)作为该节点的类标记,返回T;
2. 若A = Ø,则T为单节点树,并将D中实例数最大的类![1618749968444](assets/1618749968444.png)作为该节点的类标记,返回T;
3. 否则,按算法计算A中各特征对D的信息增益,选择信息增益最大的特征Ag;
4. 如果Ag的信息增益小于阈值ε,则置T为单节点树,并将D中实例数最大的类![1618749968444](assets/1618749968444.png)作为该节点的类标记,返回T;
5. 否则,对Ag的每一个可能值ai,依![1618750408613](assets/1618750408613.png)将D分割为若干非空子集Di,将Di中实例最大的类作为标记,构建子节点,由节点及其子节点构成树T,返回T;
6. 对第i个子节点,以Di为训练集,以A - {Ag}为特征集,递归地调用1~5步,得到树Ti,返回Ti。

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Loading…
Cancel
Save