Decision Trees & Ensemble Methods
The single most heavily tested subject area. Quinlan's ID3 Entropy and Information Gain on the 14-day Weather dataset, Breiman's CART Gini Index construction, the mathematical proof of Random Forest variance reduction, and AdaBoost reweighting.
01. Intuition & Concept Contrast
Decision trees perform recursive greedy axis-aligned orthogonal partitions of feature space. A single tree suffers from high variance (overfitting); ensemble methods combine multiple trees to eliminate variance or bias.
Information Gain (ID3) vs Gini Index (CART)
Shannon Entropy (ID3): Measures thermodynamic disorder in bits: $H(S) = -\sum p_i \log_2(p_i)$. Computationally heavier due to $\log_2$. Supports multi-way splits.
Gini Impurity (CART): Probability of incorrect classification under random labeling: $\text{Gini} = 1 - \sum p_i^2$. Computationally faster (pure squaring). Strictly binary splits.
Bagging (Random Forest) vs Boosting (AdaBoost)
Bagging (Parallel Variance Reduction): Trains unpruned deep trees independently on bootstrap samples. Reduces variance without changing bias.
Boosting (Sequential Bias Reduction): Trains shallow trees (stumps) sequentially; each tree focuses on errors made by previous trees. Reduces bias and variance.
02. Splitting Criteria Formulations (ID3 vs CART)
| Feature | Quinlan's ID3 | Breiman's CART |
|---|---|---|
| Splitting Metric | Information Gain (Shannon Entropy) | Gini Impurity / Index |
| Split Type | Multi-way (branch per categorical level) | Strictly Binary ($A \le \theta$ or $A \in \{v\}$) |
| Continuous Features | Requires manual discretization | Native sorting and binary thresholds |
| Pruning Strategy | Reduced error pruning after growth | Cost-Complexity Pruning ($R_\alpha(T)$) |
03. Random Forest Mathematical Variance Reduction Proof
Nov 2025 (Q4) Guaranteed Exam Derivation (8 Marks). Mathematical derivation proving how Random Forests eliminate tree variance.
Step-by-Step Derivation:
1. Let an ensemble of $B$ bootstrap regression trees be denoted $T_1(\mathbf{x}), \dots, T_B(\mathbf{x})$.
2. Assume each individual tree has identical variance: $\operatorname{Var}(T_b(\mathbf{x})) = \sigma^2$.
3. Assume pairwise correlation between any two distinct trees is $\operatorname{Corr}(T_j, T_k) = \rho$, so that covariance is $\operatorname{Cov}(T_j, T_k) = \rho \sigma^2$ for $j \neq k$.
4. The ensemble prediction is the arithmetic mean: $\bar{T} = \frac{1}{B}\sum_{b=1}^B T_b(\mathbf{x})$.
5. Expanding the variance of the sum:
$$\begin{aligned} \operatorname{Var}(\bar{T}) &= \operatorname{Var}\left(\frac{1}{B}\sum_{b=1}^B T_b\right) \\[6pt] &= \frac{1}{B^2} \left[ \sum_{b=1}^B \operatorname{Var}(T_b) + \sum_{j \neq k} \operatorname{Cov}(T_j, T_k) \right] \\[6pt] &= \frac{1}{B^2} \left[ B\sigma^2 + B(B-1)\rho \sigma^2 \right] \\[6pt] &= \frac{\sigma^2}{B} + \frac{B - 1}{B}\rho \sigma^2 \\[6pt] &= \mathbf{\rho \sigma^2 + \frac{1 - \rho}{B}\sigma^2} \quad \text{Q.E.D.} \end{aligned}$$1. As $B \to \infty$: The term $\frac{1-\rho}{B}\sigma^2 \to 0$, leaving residual variance $\rho \sigma^2$.
2. Feature Subspace Randomization ($m \approx \sqrt{p}$ or $p/3$): If we only use Bagging, all trees split on the single strongest feature (e.g. house size), making trees highly correlated ($\rho \to 1$). By forcing trees to choose splits only from a randomly selected subset of $m$ features at each node, trees become de-correlated: $\boldsymbol{\rho \to 0}$.
As $\rho \to 0$ and $B \to \infty$, ensemble variance approaches 0, producing a model with low bias and low variance.
04. AdaBoost Adaptive Boosting Mechanics
Nov 2025 (Q7) & CT-2 (Q4) Core Theory (8-10 Marks).
If $\epsilon_t < 0.5 \implies \alpha_t > 0$. Accurate learners receive large positive voting power.
Misclassified instances ($y_i h_t < 0$) have weights multiplied by $e^{+\alpha_t}$ (scaled up); correctly classified instances are multiplied by $e^{-\alpha_t}$ (scaled down).
05. Notation Decoding Matrix
| Symbol | Formal Name | Plain-English Meaning | Exam Benchmark Value |
|---|---|---|---|
| $H(S)$ | Shannon Entropy | Impurity / disorder of set $S$ in bits | $H(9\text{Yes}, 5\text{No}) = \mathbf{0.9403}$ bits |
| $\operatorname{Gain}(S, A)$ | Information Gain | Reduction in entropy achieved by splitting on $A$ | $\text{Gain}(\text{Outlook}) = \mathbf{0.2467}$ (Highest) |
| $\operatorname{Gini}(S)$ | Gini Impurity | Probability of misclassifying randomly picked item | $\text{Gini}(4\text{Yes}, 3\text{No}) = 1 - (16/49) - (9/49) = \mathbf{0.4898}$ |
| $\rho$ | Ensemble Tree Correlation | Degree to which individual trees make identical errors | Lowered toward $0$ via random feature sampling |
| $\alpha_t$ | Learner Importance | Voting weight assigned to base stump $t$ | $\alpha_t = \frac{1}{2}\ln(\frac{1-\epsilon_t}{\epsilon_t})$ |
06. Repeatable Step-by-Step Solving Protocol
Count $(+, -)$ outcomes for each distinct category $v$ of attribute $A$.
Choose attribute with Highest Information Gain (ID3) or Lowest Weighted Gini (CART).
If a branch contains only one class ($H = 0$), terminate as leaf. If impure, recurse on remaining attributes.
07. 6 Deadly Exam Traps & Common Student Mistakes
Computing $H(S)$ with $\ln$ Instead of $\log_2$
Entropy in ID3 must be in base 2 (bits). To compute with basic calculators: $\log_2(p) = \frac{\ln(p)}{\ln(2)} \approx \frac{\ln(p)}{0.69315}$. Using natural logs gives values in "nats" and loses marks.
Forgetting $- \sum p \log_2(p)$
Since $p_i \le 1$, $\log_2(p_i)$ is negative. Omitting the leading minus sign produces negative entropy values. Entropy is strictly non-negative ($H \ge 0$).
Picking the Highest Weighted Gini
Higher Information Gain is better, but Lower Weighted Gini Impurity is better. If using Gini directly, pick the attribute that minimizes $\text{Gini}_{\text{split}}$.
Assuming RF is Just Bagging
Bagging alone does not decorrelate trees ($\rho \approx 1$). Feature Subspace Sampling ($m \approx \sqrt{p}$) is the critical invention that decorrelates trees ($\rho \to 0$).
Forgetting Normalization Constant $Z_t$
After multiplying weights by $e^{\pm \alpha_t}$, you must divide each weight by $Z_t = \sum w_{t+1}(i)$ so that updated weights sum to $1.0$.
Splitting Pure Nodes
When a branch has all Yes or all No ($H = 0$), do not attempt further splits! It is a terminal leaf.
08. Complete University Question Bank (All Past PYQs Solved)
Jan 2025 · Question 6 The 14-Day Weather Dataset Full ID3 Construction (20 Marks)
A sports club has historical data on 14 days with attributes Outlook, Temperature, Humidity, Wind, and Decision (Play: 9 Yes, 5 No).
Construct a complete decision tree model using Quinlan's ID3 algorithm. Describe attribute selection, splitting criteria, and build the tree. (20 Marks)
| Day | Outlook | Temperature | Humidity | Wind | Decision |
|---|---|---|---|---|---|
| 1 | sunny | hot | high | weak | No |
| 2 | sunny | hot | high | strong | No |
| 3 | overcast | hot | high | weak | Yes |
| 4 | rainfall | mild | high | weak | Yes |
| 5 | rainfall | cool | normal | weak | Yes |
| 6 | rainfall | cool | normal | strong | No |
| 7 | overcast | cool | normal | strong | Yes |
| 8 | sunny | mild | high | weak | No |
| 9 | sunny | cool | normal | weak | Yes |
| 10 | rainfall | mild | normal | weak | Yes |
| 11 | sunny | mild | normal | strong | Yes |
| 12 | overcast | mild | high | strong | Yes |
| 13 | overcast | hot | normal | weak | Yes |
| 14 | rainfall | mild | high | strong | No |
Solution:
1. Root Node Entropy of Entire Dataset ($S$):
Total: $N = 14$, Positive ($p_+ = 9/14$), Negative ($p_- = 5/14$):
$$H(S) = -\left(\frac{9}{14}\log_2\frac{9}{14} + \frac{5}{14}\log_2\frac{5}{14}\right) \approx -(-0.4087 - 0.5316) = \mathbf{0.9403 \text{ bits}}$$2. Information Gain for Candidate Attributes:
A. Outlook:
- Sunny ($5$ days: $2$ Yes, $3$ No): $H(S_{\text{sunny}}) = -\frac{2}{5}\log_2\frac{2}{5} - \frac{3}{5}\log_2\frac{3}{5} = \mathbf{0.9710}$
- Overcast ($4$ days: $4$ Yes, $0$ No): $H(S_{\text{overcast}}) = 0.0000$ (Pure Node!)
- Rainfall ($5$ days: $3$ Yes, $2$ No): $H(S_{\text{rainfall}}) = -\frac{3}{5}\log_2\frac{3}{5} - \frac{2}{5}\log_2\frac{2}{5} = \mathbf{0.9710}$
B. Humidity: High ($3$ Yes, $4$ No; $H=0.9852$), Normal ($6$ Yes, $1$ No; $H=0.5917$):
$$\operatorname{Gain}(S, \text{Humidity}) = 0.9403 - \left[\frac{7}{14}(0.9852) + \frac{7}{14}(0.5917)\right] = 0.9403 - 0.7885 = \mathbf{0.1518}$$C. Wind: Weak ($6$ Yes, $2$ No; $H=0.8113$), Strong ($3$ Yes, $3$ No; $H=1.0000$):
$$\operatorname{Gain}(S, \text{Wind}) = 0.9403 - \left[\frac{8}{14}(0.8113) + \frac{6}{14}(1.0000)\right] = 0.9403 - 0.8922 = \mathbf{0.0481}$$D. Temperature: Hot ($2$ Yes, $2$ No), Mild ($4$ Yes, $2$ No), Cool ($3$ Yes, $1$ No):
$$\operatorname{Gain}(S, \text{Temperature}) = 0.9403 - 0.9111 = \mathbf{0.0292}$$3. Root Node Selection:
$\operatorname{Gain}(\text{Outlook}) = \mathbf{0.2467}$ is the highest. Therefore, Outlook is selected as the Root Node.
4. Expanding Branches:
- Branch 1 (Outlook = Overcast): All $4$ examples (Days 3, 7, 12, 13) are "Yes". $\implies$ Leaf: Play = Yes.
- Branch 2 (Outlook = Sunny): Contains Days 1, 2, 8, 9, 11 (2 Yes, 3 No). Evaluating Humidity:
- Humidity = High (Days 1, 2, 8): All 3 are "No" $\implies$ Leaf: Play = No.
- Humidity = Normal (Days 9, 11): Both are "Yes" $\implies$ Leaf: Play = Yes.
- Branch 3 (Outlook = Rainfall): Contains Days 4, 5, 6, 10, 14 (3 Yes, 2 No). Evaluating Wind:
- Wind = Weak (Days 4, 5, 10): All 3 are "Yes" $\implies$ Leaf: Play = Yes.
- Wind = Strong (Days 6, 14): Both are "No" $\implies$ Leaf: Play = No.
CT-2 · Question 3 CART Customer Purchase Decision Tree Construction (20 Marks)
7 customers with Age Group (Young, Middle, Senior), Income Level (Low, Med, High), and Buy (4 Yes, 3 No).
C1: Young, Low, No | C2: Young, Med, No | C3: Middle, Low, Yes | C4: Middle, High, Yes
C5: Senior, Med, Yes | C6: Senior, High, Yes | C7: Senior, Low, No
(a) Gini Index at root (4M)
(b) Gini Index for Age Group and Income Level splits (8M)
(c) Best attribute to split (4M)
(d) What happens if Gini values tie (2M)
(e) Advantages of CART over ID3 (2M)
Solution:
(a) Root Gini Index (4 Marks)
$$\operatorname{Gini}(S) = 1 - \left(\frac{4}{7}\right)^2 - \left(\frac{3}{7}\right)^2 = 1 - \frac{16}{49} - \frac{9}{49} = 1 - \frac{25}{49} = \frac{24}{49} \approx \mathbf{0.4898}$$(b) Split Gini Computations (8 Marks)
1. Attribute: Age Group
- Young ($2$ customers: $0$ Yes, $2$ No): $\operatorname{Gini} = 1 - 0^2 - 1^2 = \mathbf{0.0}$ (Pure)
- Middle ($2$ customers: $2$ Yes, $0$ No): $\operatorname{Gini} = 1 - 1^2 - 0^2 = \mathbf{0.0}$ (Pure)
- Senior ($3$ customers: $2$ Yes, $1$ No): $\operatorname{Gini} = 1 - (2/3)^2 - (1/3)^2 = 1 - 5/9 = 4/9 \approx \mathbf{0.4444}$
2. Attribute: Income Level
- Low ($3$ customers: $1$ Yes, $2$ No): $\operatorname{Gini} = 1 - (1/3)^2 - (2/3)^2 = 4/9 \approx \mathbf{0.4444}$
- Medium ($2$ customers: $1$ Yes, $1$ No): $\operatorname{Gini} = 1 - (1/2)^2 - (1/2)^2 = 1/2 = \mathbf{0.5000}$
- High ($2$ customers: $2$ Yes, $0$ No): $\operatorname{Gini} = 1 - 1^2 = \mathbf{0.0}$
(c) Best Attribute to Split (4 Marks)
Since $\operatorname{Gini}_{\text{split}}(\text{Age Group}) = 0.1905 < \operatorname{Gini}_{\text{split}}(\text{Income}) = 0.3333$, Age Group produces much purer sub-nodes and is chosen as the Best Split.
(d) Tie-Breaking Protocol (2 Marks)
If two attributes have identical Gini values, the algorithm breaks the tie by: (1) selecting the split that produces more balanced child node sample counts, (2) selecting the attribute with lower computation cost, or (3) using arbitrary programmatic indexing order.
(e) Advantages of CART over ID3 (2 Marks)
- Binary Splits: Avoids fragmented over-partitioning caused by multi-way splits.
- No Logarithms: Computationally faster since $1 - \sum p_i^2$ avoids expensive transcendental $\log_2$ evaluations.
Nov 2025 · Question 4 Housing Price Decision Tree Overfitting & Random Forest Variance Proof (20 Marks)
A single Decision Tree model to predict housing prices has zero training error but poor test performance.
i) Diagnose the problem with the model. (6 Marks)
ii) Propose a solution using Ensembling. (6 Marks)
iii) Explain in detail how Random Forest addresses this through mathematical proof. (8 Marks)
Solution:
(i) Diagnosis (6 Marks)
The model suffers from **Overfitting** driven by **High Variance and Low Bias** in the Bias-Variance decomposition: $\mathbb{E}[(y - \hat{f})^2] = \text{Bias}^2 + \text{Var} + \sigma_\epsilon^2$. Greedy unpruned recursive splitting memorizes training noise.
(ii) Proposed Solution: Random Forest Regression (6 Marks)
Deploy a Random Forest ensemble combining Bootstrap Aggregation (Bagging) with Feature Subspace Randomization.
(iii) Mathematical Variance Reduction Proof (8 Marks)
$$\operatorname{Var}\left(\frac{1}{B}\sum_{b=1}^B T_b\right) = \mathbf{\rho \sigma^2 + \frac{1 - \rho}{B}\sigma^2}$$As $B \to \infty$, the term $\frac{1-\rho}{B}\sigma^2 \to 0$, leaving residual variance $\rho \sigma^2$.
Standard Bagging trees are highly correlated ($\rho \approx 1$). Random Forests restrict feature splits to a random subset of $m \approx p/3$ features, de-correlating the trees ($\rho \to 0$) and driving total ensemble variance to near zero.
09. Interactive Offline Entropy & Information Gain Calculator
Enter positive and negative sample counts to calculate Shannon Entropy in bits ($H$) and verify your homework or exam numericals.
10. Active Recall Self-Test Quiz
11. Exam Hall Answer Sheet Presentation Checklist
Write $H(S) = -\sum p_i \log_2(p_i)$ and $\operatorname{Gini}(S) = 1 - \sum p_i^2$ with base 2 highlighted.
Write $H(9, 5) = \mathbf{0.9403 \text{ bits}}$. Draw a box around this benchmark.
List Outlook ($0.2467$), Humidity ($0.1518$), Wind ($0.0481$), Temperature ($0.0292$) side-by-side.
Draw boxed nodes for attributes, labeled arrows for categories, and double-lined boxes for terminal leaf predictions.
Show $\frac{1}{B^2}[B\sigma^2 + B(B-1)\rho\sigma^2] = \rho\sigma^2 + \frac{1-\rho}{B}\sigma^2$. Mention feature subsampling ($m \approx \sqrt{p}$).
Always mention: (1) Binary splits prevent over-fragmentation, (2) Avoids transcendental $\log_2$ evaluations.