Unit 4: Decision Trees & Ensemble Learning
Course - Machine Learning Algorithms (21CSC555J)
Assessment - Continuous Test 2 (CT-2)
Unit - Unit 4: Decision Trees (CART) & Ensemble Learning (AdaBoost)
Total Weightage - 40 Marks (Question 3: 20 Marks; Question 4: 20 Marks)
Question 3: CART Classification Tree Construction (20 Marks)β
Question Statement
A retail company wants to build a CART classification tree to decide whether a customer will Buy (Yes) or Not Buy (No) a product based on two attributes: Age Group and Annual Income Level.
The training dataset is as follows:
| Customer | Age Group | Income Level | Buy |
|---|---|---|---|
| C1 | Young | Low | No |
| C2 | Young | Medium | No |
| C3 | Middle | Low | Yes |
| C4 | Middle | High | Yes |
| C5 | Senior | Medium | Yes |
| C6 | Senior | High | Yes |
| C7 | Senior | Low | No |
- (a) Calculate the Gini Index for the parent node (root) before any split. (4 Marks)
- (b) Compute the Gini Index for each possible split based on: (8 Marks)
- Age Group
- Income Level
- (c) Determine the Best Attribute to Split using Gini Index criterion. (4 Marks)
- (d) Explain what would happen if both attributes had the same Gini value. (2 Marks)
- (e) Mention two advantages of CART over ID3 or C4.5 decision trees. (2 Marks)
Solution 3β
π Exam-Ready Answer (Crisp 20-Mark Structure)β
(a) Gini Index for the Parent Node (Root) (4 Marks)β
-
Step 1: Class Distribution & Probabilities (2 Marks)
- Total samples:
- Class counts: (C3, C4, C5, C6), (C1, C2, C7)
- Probabilities:
-
Step 2: Formula & Calculation (2 Marks)
(b) Compute Gini Index for Each Possible Split (8 Marks)β
CART strictly uses binary splits. For an attribute with discrete categories, there are candidate binary partitions:
1. Splits for Age Group (: Young, Middle, Senior) (4 Marks)β
-
Partition 1: vs
- Left (, Young): 0 Yes, 2 No (Pure Leaf)
- Right (, Mid+Sen): 4 Yes, 1 No
- Weighted Gini:
-
Partition 2: vs
- Left (, Middle): 2 Yes, 0 No (Pure Leaf)
- Right (, Young+Sen): 2 Yes, 3 No
- Weighted Gini:
-
Partition 3: vs
- Left (, Senior): 2 Yes, 1 No
- Right (, Young+Mid): 2 Yes, 2 No
- Weighted Gini:
2. Splits for Income Level (: Low, Medium, High) (4 Marks)β
-
Partition 1: vs
- Left (, Low): 1 Yes, 2 No
- Right (, Med+High): 3 Yes, 1 No
- Weighted Gini:
-
Partition 2: vs
- Left (, Medium): 1 Yes, 1 No
- Right (, Low+High): 3 Yes, 2 No
- Weighted Gini:
-
Partition 3: vs
- Left (, High): 2 Yes, 0 No (Pure Leaf)
- Right (, Low+Med): 2 Yes, 3 No
- Weighted Gini:
(c) Best Attribute to Split (4 Marks)β
- Impurity & Gain Comparison (2 Marks):
| Attribute | Best Binary Split Condition | Resulting Gini | Gini Gain () |
|---|---|---|---|
| Age Group | vs | (Maximum Gain) | |
| Income Level | vs |
- Selection & Justification (2 Marks):
- Selected Attribute: Age Group (with binary split condition vs ).
- Reason: It minimizes weighted impurity (), achieves highest Gini Gain (), and immediately isolates a pure terminal leaf node for Young customers ().
(d) Tie-Breaking Protocol for Identical Gini Values (2 Marks)β
If two attributes produce identical Gini values, resolve the tie using:
- Acquisition Cost: Choose the attribute cheaper or easier to collect in practice (e.g., Age Group over verified Income).
- Subtree Balance: Pick the split creating more evenly balanced sample counts between child nodes.
- Schema Order: Default to the attribute appearing first in the dataset schema.
- Secondary Metric: Compute Information Gain (Entropy) to test if logarithmic divergence breaks the tie.
(e) Two Key Advantages of CART over ID3 or C4.5 (2 Marks)β
- Classification & Regression Support: CART natively constructs both Classification Trees (via Gini Index) and Regression Trees (via Variance Reduction / MSE). ID3 supports classification only.
- Binary Splitting Avoids Fragmentation: Enforcing strictly 2 branches per split () prevents multi-way branch fragmentation (a flaw of ID3/C4.5), preserving statistical sample power in deeper child nodes.
- Disciplined Cost-Complexity Pruning: Uses minimal cost-complexity -pruning parameterized with cross-validation, which is theoretically sounder than heuristic error pruning.
Question 4: AdaBoost Transaction Fraud Classification (20 Marks)β
Question Statement
An online payment platform applies AdaBoost to classify transactions as Fraudulent or Genuine. Each weak learner is a decision stump based on one feature (like transaction amount or device ID).
- i) Explain why decision stumps are used as weak learners in AdaBoost. (4 Marks)
- ii) Describe how sample weights are updated after each iteration. (4 Marks)
- iii) Suppose a stump misclassifies 10% of samples - explain how its error and alpha (importance weight) are computed. (4 Marks)
- iv) Discuss how boosting reduces bias but can sometimes increase variance. (4 Marks)
- v) If the dataset has missing values in the "Device ID" feature, explain how AdaBoost handles this situation. (4 Marks)
Solution 4β
Exam-Ready Answer (Crisp 20-Mark Structure)β
(i) Why Decision Stumps are Used as Weak Learners (4 Marks)β
- Weak Learner: Only one simple split on a single feature threshold.
- Low Variance: Extremely simple structure makes it less sensitive to training-data variations and prevents ensemble variance explosion.
- Fast: Each stump is computationally cheap to train (), allowing hundreds of iterations in real time.
- Interpretable: Easy to understand and provides direct feature importance rankings.
Memory: One Split -> Low Variance -> Fast -> Interpretable
(ii) How Sample Weights are Updated After Each Iteration (4 Marks)β
-
Step 1 - Uniform Initialization: Give every sample equal initial weight:
-
Step 2 - Weighted Misclassification Error: Add the weights of incorrectly classified samples:
-
Step 3 - Learner Importance (): Calculate how much the stump is trusted: (Low error High Stronger vote)
-
Step 4 - Exponential Reweighting & Normalization:
- Wrong samples: Weight increases ().
- Correct samples: Weight decreases ().
- Normalize: Divide by so weights sum to .
- Train the next stump using the updated sample weights.
Memory: Uniform -> Error -> Alpha -> Reweight -> Normalize -> Next Stump
(iii) Calculate Alpha When Error is 10% (4 Marks)β
-
Given:
-
Formula & Calculation:
-
Meaning:
- Low error High Strong positive vote in final ensemble.
- This error and belong specifically to this one stump/iteration.
(iv) How Boosting Reduces Bias but Can Increase Variance (4 Marks)β
-
Why Bias Decreases:
- Individual decision stumps are simple and underfit alone.
- Each successive stump explicitly focuses on samples misclassified by previous rounds.
- Combining many weak learners creates a stronger, non-linear ensemble boundary.
- Therefore, training bias decreases toward zero.
-
Why Variance Can Increase:
- Boosting aggressively focuses on hard-to-classify samples.
- If those difficult instances are noise or outliers, their weights become exponentially inflated.
- Subsequent stumps fit the noise rather than the underlying pattern, leading to overfitting.
- Therefore, variance can increase.
Memory: Correct mistakes -> Bias | Chase noise -> Variance
(v) Handling Missing Values in "Device ID" (4 Marks)β
AdaBoost has no built-in missing value handling; it relies on preprocessing or base-learner capabilities:
- Pre-processing / Imputation:
- Impute missing values before boosting using mode or median, optionally adding a binary missingness indicator flag.
- Missing as an Informative Category:
- Treat
MissingorUnknownas a distinct category, allowing stumps to learn if missingness itself predicts fraud.
- Treat
- Base Learner Handles Missing Values Natively:
- CART stump: Uses surrogate splits as a backup feature if Device ID is missing.
- C4.5-style stump: Distributes the instance's weight fractionally across all possible branches.
Memory: Impute -> Missing Category -> Native Handling