Week 11 · Bagging, boosting and AdaBoost
Read the words of the video
- Imagine asking one friend for advice; they might be wrong. But if you ask many friends, and they all give slightly different opinions, you often get a better answer. This is like combining many simple ideas to make one really strong one. We call this an ensemble.
- There are two main ways to build this committee. Imagine many students studying different notes, then voting. This is called Bagging, and it helps fix 'jumpy' mistakes. Or, imagine tutors teaching one after another, each focusing on what the last one got wrong. This is Boosting, which makes 'weak' lessons strong.
- With Boosting, we focus on tough problems. Imagine five balloons, all equally weighted. If our first attempt pops just one balloon, that tricky balloon instantly becomes much heavier. So, the next attempt will try extra hard to avoid that specific balloon, learning from the mistake.
- Remember, for exams, know how Bagging fixes 'jumpy' problems by reducing variance, and how Boosting strengthens 'weak' lessons by reducing bias. Also, roughly 37 percent of data is 'out-of-bag' in Bagging. Keep practicing these ideas, and you'll do great!
The one-minute story
One expert may be wrong. A committee is harder to fool. An ensemble combines many simple models into one strong one. There are two classic ways to build the committee:
Bagging: many students, each studying a different random pile of the notes. Each student gives a vote, and we go with the majority. Because each saw slightly different notes, their mistakes point in different directions and cancel out. This calms jumpy models (variance), like deep decision trees.
Boosting: a relay of tutors. Tutor 1 teaches a quick lesson and finds which questions the class got wrong. Tutor 2 concentrates specifically on those hard questions. Tutor 3 does the same for what is still wrong, and so on. The final answer is a weighted vote where better tutors speak louder. This lifts weak models (bias) into a strong one. AdaBoost is the famous example.
By the end of this week you can:
- explain why averaging reduces variance;
- describe bootstrap sampling, bagging, out-of-bag error and random forests;
- run AdaBoost by hand: weights, error , , reweighting;
- compare bagging and boosting.
Words you need
- Ensemble - a group of models whose predictions are combined.
- Weak learner - a model only slightly better than guessing (a one-question decision tree, a "stump").
- Bootstrap sample - a sample of size drawn with replacement from examples.
- Out-of-bag (OOB) - the examples a given bootstrap sample missed.
- Random forest - bagged decision trees with extra randomness in the features each split may use.
- Boosting - training models in sequence, each focusing on the previous ones' mistakes.
Idea 1: Why averaging helps
Suppose models each make a prediction with variance , and their errors are independent. The average has variance
Ten independent models with variance give an average with variance . If the errors are correlated with correlation , the variance is : averaging helps less when the models are alike. So the art is to make models that are good but different.
Idea 2: Bagging and random forests
Bagging (Bootstrap aggregating):
- Build bootstrap samples (each: draws with replacement from the training set).
- Train one model (typically a deep, unpruned decision tree) on each.
- Predict by majority vote (classification) or average (regression).
It reduces variance and leaves the bias about the same. It works best with high-variance, low-bias models (deep trees) and does little for stable ones.
Out-of-bag error. The chance a particular example is not picked in a bootstrap sample is . So each model never sees about 36.8% of the data. Test each model on the examples it missed and average: a free, honest validation estimate with no separate hold-out set.
Random forest = bagged trees plus one trick: at every split, the tree may only consider a random subset of the features (about for classification). That forces the trees to differ ( smaller), so the average is better. Forests are strong, need little tuning and give a feature importance measure.
Question. A training set has examples. About how many are out-of-bag for one bootstrap sample?
Solution. , so about 368 examples are left out (and about 632 distinct ones are used).
Idea 3: Boosting and AdaBoost
AdaBoost (Adaptive Boosting) keeps a weight on every training example, and re-weights after every round so that the next learner concentrates on the examples the ensemble currently gets wrong. Labels are and each weak learner outputs .
AdaBoost
- Start with equal weights .
For rounds :
- train a weak learner using the weights ;
- compute its weighted error (must be );
- its say in the final vote: ;
- update: (wrong examples get heavier, right ones lighter), then normalise so the weights sum to 1.
- Final classifier: .
Intuition for : close to 0 means a great learner, is large; means a useless coin flip, ; would give a negative weight (flip its vote).
Question. Five examples start with weights each. The first stump gets exactly one wrong. Compute , and the new weights.
Solution.
- (the weight of the one mistake).
- .
- Wrong example: . Each of the four right ones: . Sum .
- Normalise (divide by ): wrong example ; each right one .
The single mistake now holds half of all the weight. The next stump will be heavily penalised unless it gets that example right, which is exactly the "focus on the hard question" idea.
Question. Three stumps with vote on a new point. What does the final classifier say?
Solution. Score , so the prediction is . Two stumps said , but the first is trusted more than the other two together.
Facts about AdaBoost:
- Only needs weak learners with ; the training error drops exponentially with the number of rounds (bounded by ).
- It reduces bias: many simple stumps combine into a complex boundary.
- It is sensitive to noise and outliers: mislabelled points keep getting heavier and can drag the ensemble along, so it can overfit noisy data.
- It minimises an exponential loss; gradient boosting generalises the idea to any differentiable loss.
Idea 4: Bagging versus boosting
| Bagging / random forest | Boosting (AdaBoost) | |
|---|---|---|
| Builds models | in parallel, independently | in sequence, each depends on the last |
| Data seen by each model | bootstrap sample, equal weights | re-weighted data |
| Combines by | simple vote / average | weighted vote () |
| Reduces mainly | variance | bias |
| Base learner | deep, low-bias trees | shallow, weak learners (stumps) |
| Noise sensitivity | robust | sensitive |
Your turn
Ten independent models each have prediction variance . What is the variance of their average?
Need a hint?
.
Show the full solution
.
A weak learner has weighted error . Find , and the multipliers applied to correct and wrong examples.
Need a hint?
.
Show the full solution
. Wrong: . Right: .
Four examples have weights each. The learner gets one wrong with , so the multipliers are and . Give the new normalised weights.
Need a hint?
Multiply, add, divide.
Show the full solution
Wrong: . Right: each (three of them: ). Total . Normalised: wrong , each right . (Again the one mistake gets exactly half the weight.)
In a bootstrap sample of points, what fraction are expected to be out-of-bag for large ? How many distinct points are in the sample, as a fraction?
Need a hint?
.
Show the full solution
OOB about ; distinct points about .
(a) Bagging trains its models one after another. (b) AdaBoost gives larger weights to misclassified examples. (c) A random forest considers all features at every split. (d) A learner with error 0.5 gets a zero vote in AdaBoost.
Need a hint?
Re-read the tables.
Show the full solution
(a) False, in parallel. (b) True. (c) False, a random subset. (d) True, .
Exam radar
In the MLT End Term, summaries mention AdaBoost in 22 of 49 papers, Bagging in 14, Random Forest in 12.
Typical: compute or the new weights for a given , "which statements about bagging/boosting are true?", "bagging reduces variance, boosting reduces bias", fractions of out-of-bag samples, and "what does the final AdaBoost classifier look like?" ().
- (the half and the order of over ).
- After updating, normalise the weights.
- Bagging variance; boosting bias.
- Bootstrap = with replacement.
- Boosting is sequential and cannot be parallelised across rounds; bagging can.
Quick quiz
In AdaBoost, a learner with weighted error 0.2 gets the vote weight alpha equal to...
- ln 4
- half of ln 4
- 0.2
- 4
Bagging mainly reduces...
- bias
- variance
- the number of features
- training time
For large n, the fraction of examples missing from one bootstrap sample is about...
- 10 percent
- 50 percent
- 36.8 percent
- 63.2 percent
Select all TRUE statements. (select all that apply)
- Boosting trains models sequentially.
- AdaBoost can be hurt by noisy labels.
- Random forests use all features at every split.
- Bagging gives higher weights to misclassified points.
Recap
- Averaging independent models cuts variance by ; use different-but-good models.
- Bagging: bootstrap samples, deep trees, vote/average; ~36.8% OOB (free validation). Random forest = bagging + random feature subset per split.
- AdaBoost: weights weak learner reweight normalise; final .
- Bagging reduces variance; boosting reduces bias (but is noise-sensitive).
- Average of independent: ; correlated:
- OOB probability
- AdaBoost: ; ; ;
- MLP week 10 - Random forests, boosting and tuning: Boosting and random forests: the theory, then the code.
Practise with real exam questions
These come straight from past papers (with the real figures and the official answer key). Open 16 real questions on this week All End Term papers