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 (Structured for 20 Marks)β
(a) Gini Index for the Parent Node (Root) (4 Marks)β
-
Step 1: Class Frequency Distribution at Root Node (1 Mark)
- Total number of customer instances ():
- Number of instances with : (Customers: C3, C4, C5, C6)
- Number of instances with : (Customers: C1, C2, C7)
-
Step 2: Class Probabilities at Root (1 Mark)
-
Step 3: State the Gini Index Formula (1 Mark)
-
Step 4: Substitution and Calculation (1 Mark)
(b) Compute Gini Index for Each Possible Split (8 Marks)β
In the Classification and Regression Trees (CART) methodology, trees are constructed strictly via binary splits. For an attribute with discrete categories, there are unique binary partitions.
1. Candidate Binary Splits for Age Group (: Young, Middle, Senior)β
-
Partition 1: vs
- Left Node (: Young, ):
- C1 (No), C2 (No) .
- Right Node (: Middle + Senior, ):
- C3 (Yes), C4 (Yes), C5 (Yes), C6 (Yes), C7 (No) .
- Weighted Gini for Partition 1:
- Left Node (: Young, ):
-
Partition 2: vs
- Left Node (: Middle, ):
- C3 (Yes), C4 (Yes) .
- Right Node (: Young + Senior, ):
- C1 (No), C2 (No), C5 (Yes), C6 (Yes), C7 (No) .
- Weighted Gini for Partition 2:
- Left Node (: Middle, ):
-
Partition 3: vs
- Left Node (: Senior, ):
- C5 (Yes), C6 (Yes), C7 (No) .
- Right Node (: Young + Middle, ):
- C1 (No), C2 (No), C3 (Yes), C4 (Yes) .
- Weighted Gini for Partition 3:
- Left Node (: Senior, ):
2. Candidate Binary Splits for Income Level (: Low, Medium, High)β
-
Partition 1: vs
- Left Node (: Low, ):
- C1 (No), C3 (Yes), C7 (No) .
- Right Node (: Medium + High, ):
- C2 (No), C4 (Yes), C5 (Yes), C6 (Yes) .
- Weighted Gini for Partition 1:
- Left Node (: Low, ):
-
Partition 2: vs
- Left Node (: Medium, ):
- C2 (No), C5 (Yes) .
- Right Node (: Low + High, ):
- C1 (No), C3 (Yes), C4 (Yes), C6 (Yes), C7 (No) .
- Weighted Gini for Partition 2:
- Left Node (: Medium, ):
-
Partition 3: vs
- Left Node (: High, ):
- C4 (Yes), C6 (Yes) .
- Right Node (: Low + Medium, ):
- C1 (No), C2 (No), C3 (Yes), C5 (Yes), C7 (No) .
- Weighted Gini for Partition 3:
- Left Node (: High, ):
Alternative: Multi-Way Attribute Gini Summary (Standard Exam Reference)β
If evaluated under the non-binary multi-way split definition ():
- Age Group:
- Income Level:
(c) Best Attribute to Split Using Gini Index Criterion (4 Marks)β
- Step 1: Compare Gini Values & Gini Gain (2 Marks) In decision tree learning, the optimal split is the one that minimizes the resulting weighted Gini index (or equivalently, maximizes the Gini Gain ):
| Attribute | Candidate Binary Split | Resulting Gini () | Gini Gain () |
|---|---|---|---|
| Age Group | vs | (Maximum Gain) | |
| Income Level | vs |
(Under the multi-way formulation, Age Group vs Income Level ).
- Step 2: Conclusion & Selection (2 Marks)
- Selected Best Attribute: Age Group (with binary split condition vs ).
- Reasoning: It produces the minimum weighted impurity () and achieves the highest impurity reduction (). It immediately isolates a completely pure terminal leaf node for Young customers ( with certainty).
(d) Tie-Breaking: What Happens if Both Attributes Have the Same Gini Value? (2 Marks)β
If two attributes produce identical Gini index values, standard CART algorithms resolve the tie using the following established protocols:
- Domain-Specific / Cost Priority: Select the attribute that is cheaper, faster, or less intrusive to acquire in real-world production (e.g., Age Group may be easier to collect than verified Income).
- Subtree Balance / Child Node Distribution: Choose the split that creates more evenly distributed subset sizes (minimizing sample variance between child nodes).
- Deterministic Heuristic: Follow a consistent tie-breaking rule, such as selecting the attribute that appears first in the dataset schema (e.g., column index order).
- Secondary Information Metric: Compute Information Gain (Entropy) or Gain Ratio to assess if higher-order divergence distinguishes the attributes.
(e) Two Key Advantages of CART over ID3 or C4.5 (2 Marks)β
- Unified Framework for Classification & Regression:
- CART seamlessly builds both Classification Trees (using the Gini Index for categorical targets) and Regression Trees (using Mean Squared Error / Variance Reduction for continuous numerical targets). In contrast, ID3 is strictly limited to classification, and C4.5 requires separate extensions.
- Binary Splitting Avoids Multi-Way Fragmentation:
- CART strictly enforces binary splits ( child nodes per split), preventing the exponential data fragmentation problem seen in ID3 (which creates a separate branch for every category). This preserves sample statistical power in lower nodes and naturally prevents overfitting on high-cardinality nominal attributes.
- Rigorous Cost-Complexity Pruning:
- CART uses a mathematically disciplined Minimal Cost-Complexity Pruning algorithm (-pruning parameterized with cross-validation), which is theoretically superior to the greedy heuristic error-based pruning utilized in C4.5.
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 (Structured for 20 Marks)β
(i) Why Decision Stumps are Used as Weak Learners in AdaBoost (4 Marks)β
A decision stump is a 1-level decision tree consisting of a single root split node (testing exactly one attribute threshold) connected directly to two terminal leaf nodes.
- Satisfaction of Weak Learner Condition (1 Mark):
- Boosting theory (Freund & Schapire) requires base learners to perform only slightly better than random guessing (error in binary classification). A simple 1-feature stump easily satisfies this minimal requirement without needing complex parameter tuning.
- High Bias, Ultra-Low Variance Structure (1 Mark):
- Stumps are extreme high-bias, low-variance models. Since boosting is fundamentally designed to reduce ensemble bias by additively combining weak models, starting with low-variance base learners prevents the ensemble from exploding in variance.
- Computational Speed & Scalability (1 Mark):
- Training a stump requires scanning only candidate thresholds. In production transaction systems (such as high-frequency fraud detection), hundreds of boosting rounds can be trained in seconds.
- Interpretability & Feature Ranking (1 Mark):
- Because each stump isolates a single feature (e.g., ), aggregating the stump weights provides an intuitive, mathematically exact measure of cumulative feature importance.
(ii) How Sample Weights are Updated After Each Iteration (4 Marks)β
-
Step 1: Initialization (1 Mark)
- At iteration , all transaction samples are initialized with equal, uniform weights:
-
Step 2: Weighted Error Rate Computation (1 Mark)
- For the -th weak learner , the weighted misclassification error is computed as the sum of weights of incorrectly predicted transactions: where and is the indicator function.
-
Step 3: Learner Importance Weight (1 Mark)
- The voting weight assigned to stump is:
-
Step 4: Multiplicative Weight Update & Renormalization (1 Mark)
- Sample weights for iteration are updated exponentially based on whether the transaction was correctly or incorrectly classified:
- For Correctly Classified Samples ():
- For Misclassified Samples ():
- is the normalization factor ensuring :
- Core Insight: Transactions misclassified as genuine when fraudulent are amplified in weight, forcing subsequent stumps to concentrate heavily on resolving these hard-to-detect frauds.
(iii) Error and Alpha Computation for a Stump with 10% Misclassifications (4 Marks)β
-
Step 1: Compute Weighted Error Rate () (1 Mark)
- Given that the stump misclassifies of the total sample weight:
-
Step 2: State the Formula for Importance Weight () (1 Mark)
-
Step 3: Step-by-Step Numerical Evaluation (1 Mark)
- Evaluate the odds ratio:
- Substitute into the logarithm:
- Using :
-
Step 4: Mathematical & Practical Interpretation (1 Mark)
- High Positive Weight: Because (substantially better than random guessing), is strongly positive.
- Voting Influence: In the final ensemble decision rule: this high-performing stump receives a powerful voting weight of , significantly influencing the fraud classification outcome.
(iv) How Boosting Reduces Bias but Can Sometimes Increase Variance (4 Marks)β
-
How Boosting Reduces Bias (2 Marks):
- Additive Sequential Correction: Individual decision stumps have severe underfitting (high bias) because a single threshold cannot capture complex decision surfaces.
- Progressive Residual Modeling: Each successive learner is trained on the reweighted distribution of samples misclassified by preceding learners.
- Non-Linear Boundary Synthesis: Linearly combining numerous piecewise linear stumps forms highly expressive, intricate, non-linear decision boundaries: This guarantees that the ensemble training error drops exponentially toward zero as iterations increase.
-
Why Boosting Can Sometimes Increase Variance (2 Marks):
- Extreme Sensitivity to Outliers & Label Noise: If a payment dataset contains mislabeled transactions (e.g., an abnormal genuine purchase falsely flagged as fraud) or anomalous outliers, AdaBoost repeatedly misclassifies them.
- Exponential Weight Explosion: The weight of these noisy points escalates exponentially (), causing the algorithm to over-focus on learning isolated noise points rather than generalizable fraud patterns.
- Overfitting & Decision Boundary Fragmentation: The ensemble boundary contorts into irregular, sharp pockets around noisy outliers, leading to high variance, brittle predictions, and deteriorated test accuracy.
- Mitigation: Employing shrinkage (learning rate ), limiting maximum boosting iterations , or using robust variants like Gradient Boosting with Huber loss.
(v) Handling Missing Values in the "Device ID" Feature (4 Marks)β
In practical fraud detection, "Device ID" is frequently missing due to private browsing modes, cookie blocking, or emulator masking. AdaBoost handles this through several robust mechanisms:
- Feature Bypassing via Alternative Stumps (Primary CART/Stump Defense) (1.5 Marks):
- In AdaBoost, each weak learner selects only one best feature to split on at each iteration. If "Device ID" contains extensive missing entries that degrade its split quality, the algorithm automatically selects an alternative, fully observed attribute (e.g., Transaction Amount, IP Geolocation, or Time of Transaction) that yields a lower weighted error .
- Missing as an Informative Predictive Category (1 Mark):
- In cyber-fraud analysis, a missing Device ID is rarely random (it is Missing Not At Random, MNAR). Fraudsters deliberately conceal device fingerprints. AdaBoost treats
Missing/Nullas a separate, dedicated categorical level (Device_ID = Unknown). This category often becomes an exceptionally powerful indicator of fraudulent intent.
- In cyber-fraud analysis, a missing Device ID is rarely random (it is Missing Not At Random, MNAR). Fraudsters deliberately conceal device fingerprints. AdaBoost treats
- Surrogate Split Rule (CART-Specific Mechanism) (1 Mark):
- If a stump insists on evaluating Device ID, CART constructs a surrogate split using an auxiliary feature (e.g., IP Address or Browser Type) that mimics the Device ID split with maximum mutual correlation, routing missing transactions along the surrogate branch.
- Weighted Proportional Assignment (0.5 Marks):
- When encountering a missing value during split evaluation, the sample's weight can be split proportionally across both branches according to the relative weight distribution of observed transactions in the child nodes.