CSC420 Ā· 2080 Ā· 10 marks
How Classification Differs from Regression. Train ID3 Classifier
How Classification Differs from Regression. Train ID3 Classifier
Classification vs Regression and ID3 Decision Tree
Part 1: Classification vs Regression
| Aspect | Classification | Regression |
|---|---|---|
| Output | Discrete class label (e.g. Up/Down) | Continuous numeric value |
| Goal | Assign a tuple to a predefined category | Predict a numeric quantity |
| Example | Loan = "safe"/"risky" | Predicting house price |
| Algorithms | ID3, Naive Bayes, KNN | Linear/Polynomial Regression |
| Evaluation | Accuracy, Precision, Recall | RMSE, MAE |
Classification predicts a discrete categorical label; regression predicts a continuous ordered value.
Part 2: ID3 Classifier
Given data
9 tuples: Class Up = 5, Down = 4.
Step 1: Entropy of dataset
$$E(D) = -\tfrac{5}{9}\log_2\tfrac{5}{9} - \tfrac{4}{9}\log_2\tfrac{4}{9} = 0.4711 + 0.5200 = 0.9911$$
Step 2: Information Gain
Age: old(3): 0Up,3Down; mid(3): 2Up,1Down; new(3): 3Up,0Down
$$E(\text{old})=0,\quad E(\text{new})=0$$ $$E(\text{mid}) = -\tfrac{2}{3}\log_2\tfrac{2}{3}-\tfrac{1}{3}\log_2\tfrac{1}{3}=0.9183$$ $$E_{\text{Age}} = \tfrac{3}{9}(0)+\tfrac{3}{9}(0.9183)+\tfrac{3}{9}(0)=0.3061$$ $$\text{Gain(Age)} = 0.9911 - 0.3061 = 0.6850$$
Competition: Yes(4): 2Up,2Down; No(5): 3Up,2Down
$$E(\text{Yes})=1.0,\quad E(\text{No})=0.9710$$ $$E_{\text{Comp}} = \tfrac{4}{9}(1.0)+\tfrac{5}{9}(0.9710)=0.9838$$ $$\text{Gain(Competition)} = 0.9911-0.9838 = 0.0073$$
Type: SW(5): 2Up,3Down; HW(4): 3Up,1Down
$$E(\text{SW})=0.9710,\quad E(\text{HW})=0.8113$$ $$E_{\text{Type}} = \tfrac{5}{9}(0.9710)+\tfrac{4}{9}(0.8113)=0.5394+0.3606=0.9000$$ $$\text{Gain(Type)} = 0.9911-0.9000 = 0.0911$$
Root = Age (highest gain 0.6850).
Step 3: Split on Age
- Age = old ā all Down ā leaf Down
- Age = new ā all Up ā leaf Up
- Age = mid ā mixed, needs further split.
Step 4: Subtree for Age = mid
| Competition | Type | Profit |
|---|---|---|
| Yes | SW | Down |
| No | HW | Up |
| Yes | HW | Up |
Subset: 3 tuples (2 Up, 1 Down). $$E(D_{mid}) = -\tfrac{2}{3}\log_2\tfrac{2}{3}-\tfrac{1}{3}\log_2\tfrac{1}{3}=0.9183$$
Competition: Yes(2): 1Up,1Down ā E=1.0; No(1): 1Up ā E=0 $$E_{\text{Comp}} = \tfrac{2}{3}(1.0)+\tfrac{1}{3}(0)=0.6667$$ $$\text{Gain} = 0.9183-0.6667 = 0.2516$$
Type: SW(1): 0Up,1Down ā E=0; HW(2): 2Up ā E=0 $$E_{\text{Type}} = 0 \Rightarrow \text{Gain} = 0.9183 ;(\text{maximum})$$
Split on Type:
- Type = SW ā Down
- Type = HW ā Up
Final Decision Tree
Age?
āāā old ā Down
āāā new ā Up
āāā mid ā Type?
āāā SW ā Down
āāā HW ā Up
Step 5: Prediction for [Age = Mid, Competition = Yes, Type = HW]
Age = mid ā check Type ā Type = HW ā Up
$$\boxed{\text{Predicted Profit = Up}}$$
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.