CSC420 · 2081 · 10 marks
Decision Tree Classification with ID3 Algorithm
Decision Tree Classification with ID3 Algorithm
Overfitting and Underfitting + ID3 Decision Tree
Given
| TID | Age | Car Type | Class |
|---|---|---|---|
| 1 | ≤30 | Family | High |
| 2 | ≤30 | Sports | High |
| 3 | >30 | Sports | High |
| 4 | >30 | Family | Low |
| 5 | >30 | Truck | Low |
| 6 | ≤30 | Family | High |
- Total tuples = 6
- Class High: TID 1, 2, 3, 6 → 4 tuples
- Class Low: TID 4, 5 → 2 tuples
- Attributes: Age (≤30, >30), Car Type (Family, Sports, Truck)
Part 1: Definitions
Overfitting
Overfitting occurs when a model learns the training data too well, capturing noise and random fluctuations rather than the underlying pattern. It shows high accuracy on training data but poor accuracy on unseen/test data. In decision trees, this happens when the tree grows too deep.
Underfitting
Underfitting occurs when a model is too simple to capture the underlying structure of the data. It shows poor accuracy on both training and test data. In decision trees, this happens when the tree is too shallow.
Part 2: ID3 Algorithm
Step 1: Entropy of the whole dataset
$$Entropy(S) = -\frac{4}{6}\log_2\frac{4}{6} - \frac{2}{6}\log_2\frac{2}{6}$$
$$= -\tfrac{2}{3}(-0.585) - \tfrac{1}{3}(-1.585) = 0.390 + 0.528 = 0.918$$
Step 2: Gain for Age
Age = ≤30: TID 1, 2, 6 → High:3, Low:0 → $Entropy = 0$
Age = >30: TID 3, 4, 5 → High:1, Low:2
$$Entropy(>30) = -\tfrac{1}{3}\log_2\tfrac{1}{3} - \tfrac{2}{3}\log_2\tfrac{2}{3} = 0.528 + 0.390 = 0.918$$
$$Info_{Age}(S) = \tfrac{3}{6}(0) + \tfrac{3}{6}(0.918) = 0.459$$
$$Gain(Age) = 0.918 - 0.459 = 0.459$$
Step 3: Gain for Car Type
Family: TID 1, 4, 6 → High:2, Low:1 → $Entropy = 0.918$ Sports: TID 2, 3 → High:2, Low:0 → $Entropy = 0$ Truck: TID 5 → High:0, Low:1 → $Entropy = 0$
$$Info_{CarType}(S) = \tfrac{3}{6}(0.918) + \tfrac{2}{6}(0) + \tfrac{1}{6}(0) = 0.459$$
$$Gain(CarType) = 0.918 - 0.459 = 0.459$$
Step 4: Select Root
| Attribute | Gain |
|---|---|
| Age | 0.459 |
| Car Type | 0.459 |
Both are tied at 0.459. Selecting Age as root (either is valid).
Step 5: Split on Age
Age
/ \
≤30 >30
[1,2,6] [3,4,5]
H:3,L:0 H:1,L:2
PURE→High impure
- Age ≤30: all High → leaf Class = High
- Age >30: TID 3 (High), 4 (Low), 5 (Low) → not pure, split further.
Step 6: Split the (Age > 30) subset
Remaining attribute: Car Type. Subset = {3, 4, 5}.
- Sports: TID 3 → High → pure → High
- Family: TID 4 → Low → pure → Low
- Truck: TID 5 → Low → pure → Low
Entropy of each subset = 0, so Car Type perfectly classifies this subset.
Final Decision Tree
Age
/ \
≤30 >30
| |
[High] Car Type
/ | \
Sports Family Truck
| | |
[High] [Low] [Low]
Classification Rules
- If Age ≤ 30 → High
- If Age > 30 AND Car = Sports → High
- If Age > 30 AND Car = Family → Low
- If Age > 30 AND Car = Truck → Low
This tree classifies all 6 training tuples correctly.
The completed tree splits the (Age > 30) subset on Car Type, with entropy = 0.918, both gains = 0.459 and Age chosen as the root, the left branch being pure High.
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.