Exercises — Ensemble methods (voting, stacking, blending)
Before we start, here is the one picture the whole page leans on: the difference between hard voting (count labels) and soft voting (average probabilities).

The figure has two panels. The left panel ("Hard voting") turns each model into a 0/1 label and stacks the counts; the right panel ("Soft voting") keeps each model's probability and averages them. In both panels the red bar labelled ENS is the ensemble's final answer, and the dashed line is the threshold. Notice the two panels can end up on opposite sides of that line — that clash is the heart of Exercise 3.1.
Level 1 — Recognition
Exercise 1.1
Three classifiers vote on one email: Spam, Spam, Not-Spam. Under hard voting, what is the ensemble label?
Recall Solution
Hard voting = majority of the labels (the mode). We have two "Spam" and one "Not-Spam". WHAT we did: counted votes. WHY: hard voting ignores confidence and only tallies discrete labels.
Exercise 1.2
Match each word to its one-line meaning: Voting, Stacking, Blending.
Recall Solution
- Voting ::: combine base predictions by a fixed rule (mode or average) — no learning on top.
- Stacking ::: train a meta-model on out-of-fold base predictions to learn how to combine them.
- Blending ::: like stacking, but the meta-model trains on a single held-out validation set instead of k-fold out-of-fold predictions. The key contrast: voting has no trainable combiner; stacking/blending learn the combiner. See 2.6.12-Cross-validation for the out-of-fold idea.
Level 2 — Application
Exercise 2.1
Three classifiers output these values for one email: . Give (a) the soft-vote average and (b) the soft-vote label (threshold ).
Recall Solution
Since , the label is Spam. WHY average, not mode? Soft voting keeps the magnitude of confidence; here two models barely lean Spam and one barely leans Not-Spam, and the average tips just over the line.
Exercise 2.2
Same email, but now use hard voting on those same three probabilities (each model labels Spam iff ). Do hard and soft agree?
Recall Solution
Labels: Spam, Spam, Not-Spam. Majority Spam (). Both hard and soft say Spam — they agree here. WHY they agree: the two Spam probabilities () sit above and the single Not-Spam probability () sits just below it, all by a whisker. Because every model is near the threshold, no single one is confident enough to drag the average across, so counting labels (majority) and averaging probabilities (soft) land on the same side. Disagreement only appears when one model is far more confident than the others — that is exactly what Exercise 3.1 constructs.
Exercise 2.3
Weighted soft voting. Weights ; . Compute the weighted score and give the label (threshold , weights sum to ).
Recall Solution
Spam. The high-weight, high-confidence model (, ) dominates.
Level 3 — Analysis
Exercise 3.1
Build a case where hard and soft voting disagree. Three models, . Give both decisions and explain the disagreement.
Recall Solution
Hard: labels (Spam, Not-Spam, Not-Spam) majority Not-Spam (). Soft: Spam. WHY they split: one very confident model () is outvoted by two barely-doubtful models (). Hard voting throws away that " vs " gap; soft voting keeps it, so the confident model overrides. This is exactly what the figure below shows.

Exercise 3.2
Independent-error accuracy. Three classifiers, each 70% accurate, errors independent. Compute the majority-vote ensemble accuracy.
Recall Solution
Ensemble is correct when at least 2 of 3 are correct. With : WHAT this shows: three 70% models beat any single one (70%) — the wisdom-of-crowds bump, powered by variance cancellation.
Exercise 3.3
Variance reduction. models, each error variance , errors uncorrelated. Find the ensemble error variance. Then say what happens if the errors are perfectly correlated instead.
Recall Solution
Uncorrelated: . WHY the : the average of independent errors has variance . Perfectly correlated (): averaging identical errors changes nothing, so . Lesson: ensembles pay off only through diversity; identical models give zero reduction. This is why 2.7.2-Random-Forest deliberately decorrelates trees.
Level 4 — Synthesis
Exercise 4.1
General correlated-variance formula. models, each variance , every pair correlated by . Show the ensemble variance is then evaluate it for .
Recall Solution
First, what is ? The correlation coefficient between two errors is defined as their covariance divided by the product of their standard deviations: Here every model shares the same variance (so each standard deviation is ). Rearranging that definition gives the link we need: WHY this matters: is just covariance measured in "units of ", so it is dimensionless and always between and . That is the exact quantity the derivation below multiplies each cross-term by.
Ensemble error . Its variance: There are variance terms () and covariance terms (each from the definition above): Numbers: Even with , correlation pins the variance at (vs the wishful from ).
Exercise 4.2
Design a leakage-free stacking split. You have 10,000 rows and want 5-fold out-of-fold predictions. (a) How many rows of meta-training data do you produce? (b) In fold 3, how many rows does each base model train on vs predict on?
Recall Solution
(a) Every original row is a hold-out in exactly one fold, so it gets exactly one out-of-fold prediction 10,000 meta-training rows (no more, no less). (b) Each fold has rows. In fold 3, base models train on the other 4 folds rows and predict on 2000 rows. WHY: the meta-model must only ever see predictions the base model made on data it did not train on — otherwise the meta-model learns the base models' memorised training quirks, not their real skill. That is the whole point of out-of-fold construction.
Level 5 — Mastery
Exercise 5.1
Full mixed decision. Four models give : with reliability weights (sum ). We adopt this explicit tie-break policy for hard voting: if the label counts tie, fall back to the class with the higher plain soft-vote average probability. Compute: (a) hard-vote label (using the stated tie-break), (b) plain soft-vote label, (c) weighted soft-vote score and label. Then say which decision you'd trust and why.
Recall Solution
Tie-break policy (stated in the problem): a – label tie is broken by the higher plain soft-vote average — this is a deliberate, declared rule, not a hidden convention, so a marker can reproduce it exactly.
(a) Hard: labels (thresh ) (Spam, Not, Spam, Not) tie –. Applying the declared tie-break, compare average probabilities: the Spam-leaning models average while the Not-leaning ones average ; the plain overall average favours Spam Spam. (b) Plain soft: Spam. (c) Weighted soft: Spam. Trust: the weighted soft score () — it uses both confidence and each model's reliability, and it lands well clear of (unlike plain soft's razor-thin ). The two reliable models () both lean Spam, which is reassuring.
Exercise 5.2
Break-even reliability. A single model is 82% accurate. You add two more independent models each of accuracy and take a 3-way majority vote. Find the smallest so the ensemble is at least as accurate as the single 82% model. (Use majority-correct assuming all three share accuracy ; solve .)
Recall Solution
Majority-correct with common accuracy : Set : . Solving numerically, the relevant root in is So each added model only needs about 72.9% accuracy for a 3-way vote to match a lone 82% model — because the vote's variance-cancellation buys extra accuracy. Below the crowd would drag it down. WHY this is the mastery point: individual weakness is fine if errors are independent — diversity converts three mediocre models into one strong committee. Compare 2.7.3-Boosting-methods, which instead makes models dependent on purpose.
Recall Quick self-check
Soft vs hard: which uses probabilities? ::: Soft. Ensemble variance for independent models each ? ::: . Why out-of-fold predictions in stacking? ::: To prevent data leakage from base models' own training rows. Variance floor when errors correlate by ? ::: .