Tree-Based & Instance Methods
Chapter: 2.3 Tree-Based & Instance Methods Level: 2 — Recall (definitions, standard textbook problems, short derivations) Time Limit: 30 minutes Total Marks: 50
Instructions
- Answer all questions. Show working where calculations are required.
- Use for entropy calculations unless stated otherwise.
Q1. Define the following decision-tree terms in one line each: (a) root node, (b) leaf node, (c) splitting, (d) depth of a tree. (4 marks)
Q2. A binary classification node contains 8 positive and 8 negative samples. (a) Compute the entropy of this node. (2 marks) (b) Compute the Gini impurity of this node. (2 marks)
Q3. A parent node with 10 samples (5 positive, 5 negative) is split into two children:
- Left child: 4 positive, 0 negative
- Right child: 1 positive, 5 negative
Compute the information gain of this split using entropy. (6 marks)
Q4. Explain in your own words what overfitting in a decision tree looks like, and name two techniques to reduce it. (4 marks)
Q5. Distinguish between pre-pruning and post-pruning. Give one example criterion for each. (4 marks)
Q6. Explain bagging (bootstrap aggregating) in 3–4 sentences, and state how a Random Forest differs from plain bagging of trees. (6 marks)
Q7. Define Out-of-Bag (OOB) error. Approximately what fraction of the training samples are expected to be OOB for a given tree, and why? (5 marks)
Q8. Compare AdaBoost and Gradient Boosting in terms of how each fits successive weak learners. (5 marks)
Q9. Compute the following distances between and : (a) Euclidean distance. (2 marks) (b) Manhattan distance. (2 marks)
Q10. Explain the effect of choosing too small and too large a value of in K-Nearest Neighbors, and briefly state how the curse of dimensionality affects KNN. (6 marks)
END OF PAPER
Answer keyMark scheme & solutions
Q1. (4 marks) — 1 mark each
- (a) Root node: the topmost node containing the entire dataset before any split.
- (b) Leaf node: a terminal node with no children that outputs a prediction (class/value).
- (c) Splitting: partitioning the samples at a node into child nodes based on a feature threshold/value.
- (d) Depth: the length of the longest path from the root node to any leaf node.
Q2. (4 marks) (a) . (2 marks) — max entropy for balanced binary node.
(b) (2 marks) — max Gini = 0.5 for binary.
Q3. (6 marks) Parent entropy: → . (1 mark)
Left child (4 pos, 0 neg): pure → . (1 mark)
Right child (1 pos, 5 neg), total 6: . (2 marks)
Weighted child entropy (weights 4/10 and 6/10): (1 mark)
Information gain: (1 mark)
Q4. (4 marks)
- Overfitting description (2 marks): the tree grows very deep, creating leaves that fit noise/individual training points; near-perfect training accuracy but poor test/generalization accuracy; decision boundaries become overly complex.
- Two techniques (1 mark each): pruning (pre/post), limiting max depth, minimum samples per leaf/split, ensembling (bagging/random forest), setting a minimum impurity decrease. Any two valid.
Q5. (4 marks)
- Pre-pruning (early stopping) (2 marks): stop growing the tree before it fully fits the data. Example criterion: stop when max depth reached / node has fewer than samples / information gain below threshold.
- Post-pruning (2 marks): grow full tree then remove/collapse branches that don't improve validation performance. Example: cost-complexity (weakest-link) pruning, reduced-error pruning.
Q6. (6 marks)
- Bagging (3 marks): generate bootstrap samples (sample with replacement) from the training set; train a separate tree on each; aggregate predictions by majority vote (classification) or averaging (regression). This reduces variance since averaging many high-variance trees stabilizes the prediction.
- Random Forest difference (3 marks): in addition to bagging the samples, at each split a random subset of features (e.g. features) is considered rather than all features. This decorrelates the trees, reducing ensemble variance further than plain bagging.
Q7. (5 marks)
- Definition (2 marks): OOB error is a validation estimate computed by predicting each training sample using only the trees for which that sample was not in the bootstrap set, then measuring the error on those predictions.
- Fraction ≈ 36.8% (1 mark).
- Why (2 marks): probability a sample is NOT chosen in draws with replacement from items is . So about 37% of samples are OOB per tree.
Q8. (5 marks)
- AdaBoost (2.5 marks): fits weak learners sequentially, re-weighting samples — misclassified points get higher weights so the next learner focuses on them. Final prediction is a weighted vote where learner weight depends on its error.
- Gradient Boosting (2.5 marks): fits each new learner to the negative gradient (residuals) of a differentiable loss function; adds it to the ensemble with a learning rate. Generalizes boosting to arbitrary loss functions via gradient descent in function space.
Q9. (4 marks) Difference vector: . (a) Euclidean: (2 marks) (b) Manhattan: (2 marks)
Q10. (6 marks)
- Too small (e.g. ) (2 marks): low bias, high variance; very sensitive to noise/outliers; jagged decision boundary; overfits.
- Too large (2 marks): high bias, low variance; over-smoothed boundary; may include distant irrelevant neighbors and misclassify; underfits (extreme predicts majority class always).
- Curse of dimensionality (2 marks): in high dimensions distances become nearly uniform (all points roughly equidistant), so "nearest" neighbors are not meaningfully closer; neighborhoods become sparse, degrading KNN accuracy and requiring exponentially more data.
[
{"claim":"Q2a entropy of balanced binary node = 1.0", "code":"p=Rational(1,2); H=-p*log(p,2)-p*log(p,2); result = (H==1)"},
{"claim":"Q2b Gini of balanced binary node = 0.5", "code":"p=Rational(1,2); G=1-(p**2+p**2); result = (G==Rational(1,2))"},
{"claim":"Q3 information gain approx 0.61 bits", "code":"HR=-Rational(1,6)*log(Rational(1,6),2)-Rational(5,6)*log(Rational(5,6),2); Hsplit=Rational(4,10)*0+Rational(6,10)*HR; IG=1-Hsplit; result = abs(float(IG)-0.61) < 0.01"},
{"claim":"Q7 OOB fraction approx 0.368", "code":"val=limit((1-1/n)**n, n, oo); result = abs(float(val)-0.3679) < 0.001"},
{"claim":"Q9 Euclidean=5 and Manhattan=7", "code":"a=Matrix([1,2,3]); b=Matrix([4,6,3]); d=b-a; euc=sqrt(sum(x**2 for x in d)); man=sum(abs(x) for x in d); result = (euc==5 and man==7)"}
]