Tree-Based & Instance Methods
Level: 4 — Application (novel/unseen problems, no hints) Time limit: 60 minutes Total marks: 60
Show all working. Round numerical answers to 4 decimal places unless stated otherwise. Use natural log base 2 for entropy where entropy is requested.
Question 1 — Splitting a Node (14 marks)
A binary classification node contains 10 training samples of the following class labels:
A candidate feature (numeric) has values: aligned index-wise with the labels above.
You are considering a threshold split .
(a) Compute the entropy (base 2) and the Gini impurity of the parent node. (4)
(b) For the candidate threshold (i.e. split into vs ), compute the information gain and the weighted Gini of the split. (6)
(c) A colleague claims is the optimal threshold for this feature. Argue whether any threshold can achieve a purer split, and identify the best achievable weighted Gini for this feature. Justify with reasoning about the label ordering. (4)
Question 2 — AdaBoost Iteration (14 marks)
You run AdaBoost (SAMME / discrete, binary labels ) on 5 training points. All points start with equal weights. After training weak learner , it misclassifies points 2 and 4 only.
(a) Compute the weighted error and the learner weight . (4)
(b) Compute the updated, normalized weight distribution over the 5 points after the reweighting and normalization step. (6)
(c) Explain quantitatively (using your numbers) why the sum of misclassified-point weights after normalization equals exactly , and state what this implies for the next iteration. (4)
Question 3 — Out-of-Bag Estimation (10 marks)
You build a random forest by bootstrap sampling points (sampling with replacement, sample size ).
(a) Derive the probability that a specific point is not selected in a single bootstrap sample of size , and give its limiting value as . (4)
(b) For , compute the exact probability a given point is out-of-bag for one tree, to 4 decimals. (3)
(c) A forest has 200 trees. On average, roughly how many trees will treat a given fixed training point as OOB? Explain how the OOB error is then computed for that point. (3)
Question 4 — KNN & Distance Metrics (12 marks)
Given training points with labels:
| Point | Label | ||
|---|---|---|---|
| A | 1 | 1 | Red |
| B | 2 | 2 | Red |
| C | 4 | 4 | Blue |
| D | 5 | 1 | Blue |
Query point .
(a) Compute the Euclidean and Manhattan distances from to each of A, B, C, D. (6)
(b) Predict the label of under 1-NN and 3-NN using Euclidean distance. Show which neighbours are used. (4)
(c) Explain, referencing the curse of dimensionality, one concrete reason why the Euclidean-based prediction becomes unreliable if we appended 100 irrelevant noise features to this dataset. (2)
Question 5 — Gradient Boosting Concept (10 marks)
A gradient boosting regressor uses squared-error loss . The initial model is the constant .
Training targets: .
(a) Compute and the pseudo-residuals evaluated at for each point. (4)
(b) The first regression tree predicts a constant for the two left points (indices 1,2) and a constant for the two right points (indices 3,4), fitting the residuals by mean. With learning rate , give for all four points. (4)
(c) State why gradient boosting fits residuals (gradients) rather than re-weighting samples like AdaBoost. (2)
Answer keyMark scheme & solutions
Question 1 (14 marks)
Parent: 6 positives, 4 negatives, , .
(a) Entropy: (2 marks — correct formula 1, value 1)
Gini: (2 marks)
(b) Split at : left = indices 1–6 (all ), 6 samples, pure. Right = indices 7–10 (all ), 4 samples, pure.
Left entropy , right entropy . Weighted child entropy . Information gain . (3 marks)
Weighted Gini . (3 marks)
(c) Because the labels are perfectly ordered (all then all ) and is monotonically increasing, the threshold separates the classes with zero impurity. No split can do better than weighted Gini (the theoretical minimum). So IS optimal; the best achievable weighted Gini is . (4 marks: recognise perfect separation 2, state min Gini = 0 with justification 2)
Question 2 (14 marks)
Initial weights: each. Misclassified: points 2, 4.
(a) . (2 marks) (2 marks)
(b) Update rule: ; multiply misclassified by , correct by .
, .
Unnormalized:
- Correct points (1,3,5): each
- Misclassified (2,4): each
Sum .
Normalized:
- Correct: each
- Misclassified: each
(Update rule 2, unnormalized 2, normalized values 2)
(c) After normalization, weighted error of under = sum of misclassified weights . This is a general AdaBoost property: the reweighting makes the current learner have exactly 50% weighted error on the new distribution (equivalent to random guessing), forcing the next learner to focus on the previously hard points. (numeric confirmation 2, interpretation 2)
Question 3 (10 marks)
(a) Probability a specific point NOT chosen in one draw . Independent over draws: Limit: . (formula 2, limit 2)
(b) : . (3 marks)
(c) Fraction of trees for which a point is OOB . For 200 trees: trees. OOB error for that point = aggregate prediction (majority vote / average) using only those ~74 trees that did not train on it; the overall OOB error averages this over all points, giving a validation-free generalization estimate. (count 2, computation of OOB error 1)
Question 4 (12 marks)
(a) Query .
Euclidean:
- A(1,1):
- B(2,2):
- C(4,4):
- D(5,1):
Manhattan:
- A:
- B:
- C:
- D:
(3 marks Euclidean, 3 marks Manhattan)
(b) 1-NN: nearest is B (dist 1.0) → Red. 3-NN: nearest three are B (1.0), then a tie among A, C, D (all 2.2361). Choosing any 3, e.g. {B, and two of A/C/D}. With B=Red, A=Red, then one Blue → 2 Red vs 1 Blue → Red. (Note tie must be broken; a reasonable tie-break like taking A and C gives {B:Red, A:Red, C:Blue} → Red.) Answer: 1-NN = Red, 3-NN = Red (with stated tie-breaking). (4 marks: 1-NN 2, 3-NN with tie note 2)
(c) With 100 noise features, Euclidean distances become dominated by noise-dimension variation; all pairwise distances concentrate (ratio of nearest to farthest → 1), so "nearest neighbour" is no longer meaningfully closer in the relevant features — predictions degrade. (2 marks)
Question 5 (10 marks)
(a) . (1) Pseudo-residuals : (3 marks)
(b) Left leaf (points 1,2): . Right leaf (points 3,4): . :
- pts 1,2:
- pts 3,4:
(leaf values 2, 2)
(c) Gradient boosting fits each new learner to the negative gradient (residuals) of the loss, performing functional gradient descent, so it directly reduces the loss for any differentiable loss. AdaBoost's reweighting is a special case for exponential loss; residual-fitting generalizes to arbitrary losses and continuous targets. (2 marks)
[
{"claim":"Q1a parent entropy = 0.9710 and Gini = 0.48","code":"from sympy import log, Rational, N\np=Rational(6,10); q=Rational(4,10)\nH=-(p*log(p,2)+q*log(q,2)); G=1-p**2-q**2\nresult = (abs(float(H)-0.9710)<1e-3) and (float(G)==0.48)"},
{"claim":"Q2 alpha1 = 0.2027 and D2 misclassified weight = 0.25","code":"import sympy as sp\neps=sp.Rational(2,5)\nalpha=sp.Rational(1,2)*sp.log((1-eps)/eps)\nc=sp.Rational(1,5)*sp.exp(-alpha); m=sp.Rational(1,5)*sp.exp(alpha)\nZ=3*c+2*m\nresult = (abs(float(alpha)-0.2027)<1e-3) and (abs(float(m/Z)-0.25)<1e-6)"},
{"claim":"Q3b OOB prob for n=5 is 0.32768","code":"result = abs((1-1/5)**5 - 0.32768) < 1e-9"},
{"claim":"Q5 residuals and F1 correct","code":"y=[3,6,9,12]; F0=sum(y)/4\nr=[v-F0 for v in y]\nc=(r[0]+r[1])/2; d=(r[2]+r[3])/2\nF1=[F0+0.5*c,F0+0.5*c,F0+0.5*d,F0+0.5*d]\nresult = (F0==7.5) and (r==[-4.5,-1.5,1.5,4.5]) and (F1==[6.0,6.0,9.0,9.0])"}
]