CAB212 · Unit 3: Classification
Decision trees: entropy, information gain and Gini
8 practice questions
Key points
- Entropy 0 = pure; Gini 0 = pure
- Gain = parent entropy - weighted child entropy
- CART uses Gini; ID3 uses information gain
- Prune or limit depth to avoid overfitting
A decision tree repeatedly splits data on the feature/threshold that best separates classes, ending in leaves with predictions.
- Entropy H = -sum(p_i log2 p_i). Pure node: 0. Two equal classes: 1 bit.
- Gini impurity G = 1 - sum(p_i^2). Pure node: 0. Two equal classes: 0.5.
- Information gain = H(parent) - weighted average H(children).
Worked example: a node with 9 positive and 5 negative samples has H = 0.940. Splitting into (6+, 2-) and (3+, 3-) gives H = 0.811 and 1.0; weighted average = (8/14)(0.811) + (6/14)(1.0) = 0.892, so information gain = 0.048.
Algorithms: ID3 (information gain, categorical), C4.5 (gain ratio), CART (Gini, binary splits, also regression).
Trees overfit if grown fully. Control with max depth, minimum samples per leaf, or pruning. They need no scaling, handle mixed data, and are interpretable.
Exam pitfall: the best split is the one with the highest information gain (lowest weighted child impurity), not the lowest.
Try two questions
The Gini impurity of a node with 50% of each of two classes is:
- 0
- 1
- 0.5
- 0.25
Show the answer
C. 1 - (0.25 + 0.25) = 0.5.
A node has 9 positive and 5 negative samples. Its entropy is about:
- 1.00
- 0.50
- 0.36
- 0.94
Show the answer
D. -(9/14)log2(9/14) - (5/14)log2(5/14) = 0.940.