Ví dụ 2:
Áp dụng các công thức sau:
Entropy : E = SUM(-pi * log2(pi))
Gain : G = E - SUM(Si/S * Ei)
Find Root
9+, 5- E = 0.94 | |||
Age | Income | Student | Credit_rating |
Youth 2+, 3- E = 0.97
Middle_aged 4+,0- E = 0
Senior 3+, 2- E = 0.97
G= 0.94 - 5/14 * 0.94 - 0 - 5/14 * 0.97 = 0.247 (max)
| G = 0.029 | G = 0.152 | G = 0.048 |
=> Root is Age (Youth, Middle_aged, Senior)
Find node for brand Youth (brands: youth)
2+, 3- E = 0.97 | ||
Income | Student | Credit_rating |
High 0+, 2- E = 0
Medium 1+, 1- E= 1
Low 1+, 0- E = 0
G = 0.97 - 2/5 * 1 = 0.57 | G = 0.971 (max) | G = 0.02 |
=> Brand Youth have node is Student (no, yes)
Find node for brand no (brands: youth - no)
0, 3- E = 0 |
=> Brand no have leaf is NO
Find node for brand yes (brands: youth - yes)
2+, 0- E = 0 |
=> Brand yes have leaf is YES
Find node for brand Middle_aged (brands: middle_aged)
4+, 0- E = 0 |
=> Brand Middle_aged have leaf is YES
Find node for brand Senior (brands: senior) //i forget student, you need add student
3+, 2- E = 0.97 | |
Income | Credit_rating |
G = 0.0202 | G = 0.971 (max) |
=> Brand Senior have node is Credit_rating (fair, excellent)
Find node for brand fair (brands: senior - fair)
3+, 0- E = 0 |
=> Brand fair have leaf is YES
Find node for brand excellent (brands: senior - excellent)
0+, 2- E = 0 |
=> Brand excellent have leaf is NO
Tree:
Root |
|
| Age |
|
|
Brand | Youth | Middle_aged | Senior | ||
Node | Student |
| Credit_rating | ||
Brand | Yes | No |
| Fair | Excellent |
Leaf | YES | NO | YES | YES | NO |
No comments:
Post a Comment