Data Mining Exercise 8
Decision Tree - Information Gain vs Gini Index for selecting the best Attribute
Warning
This article is a work in progress and may contain incomplete information or inaccuracies. Please verify details from reliable sources.
Data Mining Exercise 8
π Precaution
In the data table for question 5, some Class Label cells are "blank" (no + sign). I will assume those blank cells are negative class (-) to make it a Binary Class Problem according to the problem.
| A | B | Class Label |
|---|
-----| |T|F|+| |T|T|+| |T|T|+| |T|F|-| |T|T|+| |F|F|-| |F|F|-| |F|F|-| |T|T|-| |T|F|-|
Question 5: Selecting Attribute A or B
Data Summary
Total data count 10 rows
- Class (+): 4 people (Rows 1, 2, 3, 5)
- Class (-): 6 people (Rows 4, 6, 7, 8, 9, 10)
5a. Calculate Information Gain (Choose A or B?)
Entropy Formula
Entropy of Parent (P)
Information Gain of Attribute A
A = T (7 people): has (+)4, (-)3
A = F (3 people): has (+)0, (-)3 (Pure)
Weighted Entropy:
Information Gain(A):
Information Gain of Attribute B
B = T (4 people): has (+)3, (-)1
B = F (6 people): has (+)1, (-)5
Weighted Entropy:
Information Gain(B):
Summary 5a
β Choose Attribute A
Because Gain(A) = 0.2815 > Gain(B) = 0.2566
5b. Calculate Gain in Gini Index (Choose A or B?)
Gini Index Formula
Gini of Parent (P)
Gini of Attribute A
A = T:
A = F:
Weighted Gini:
Gain Gini(A):
Gini of Attribute B
B = T:
B = F:
Weighted Gini:
Gain Gini(B):
Summary 5b
β Choose Attribute B
Because Gain Gini(B) = 0.1632 > Gain Gini(A) = 0.1377
5c. Explanation - Can we choose different Attributes?
Answer
β Possible (Yes)
As seen in this example (Info Gain chose A but Gini chose B)
Reason
Information Gain (Entropy):
- Tends to be biased towards Attributes that divide into the most "Pure" subgroups.
- Even if that group is small (e.g. A=F only has 3 people, but 100% pure, making Entropy drop drastically).
Gini Index:
- Tends to prefer divisions that result in "large and moderately pure" groups rather than small, highly pure groups.
- Gini will not drop as fast as Entropy when it encounters a small Pure node.
Question 6: Gini Index of Node Splitting
| P | C1 | C2 | |
|---|---|---|---|
| Class 0 | 7 | 3 | 4 |
| Class 1 | 3 | 0 | 3 |
Data
- Parent (P): Class 0 = 7, Class 1 = 3 (Total 10)
- Child 1 (C1): Class 0 = 3, Class 1 = 0 (Total 3) β Pure
- Child 2 (C2): Class 0 = 4, Class 1 = 3 (Total 7)
6a. Calculate Gini index of node P
6b. Calculate Weighted Gini index & Decision
Gini of Child 1 (C1)
This group only has Class 0 (Pure).
Gini of Child 2 (C2)
Weighted Gini
Decision Summary
π Comparison Result
- Old Gini: 0.42
- New Gini (Weighted): 0.343
- Reduced value (Gain): 0.42 - 0.343 = 0.077
β Should Consider (Yes)
Because Gini value decreased, it means the data purity increased (Impurity decreased), especially Node C1 which split out to be 100% pure.