Ensembles: there is no single best classifier (No Free Lunch), so combine many classifiers into one “committee”. Two opposing principles: random forests average many deep, overfitting trees (reduce variance); boosting combines many underfitting weak learners with specific weights (reduce bias).
Bootstrap approximates the distribution of an estimate by recomputing it on B resamples. Bagging averages the B bootstrap estimates: with pairwise correlation ρ the variance is ρσ2+(1−ρ)Bσ2 instead of σ2, so success depends on how independent the estimates are.
Random forests: bagged spatial decision trees, each grown on a random subsample with the split dimension chosen from a random subset of m≈d/3 dimensions. A forest can be consistent even if its individual (deep) trees are not.
AdaBoost: start with uniform weights; in round t fit a weak learner ht with weighted error εt, give it the vote wt=21log(εt1−1), multiply the weights by e−wtyiht(xi) and renormalize. Output sign(∑twtht(x)).
Theorem 1 (training error of AdaBoost): if every εt≤21−γ, the training error is at most exp(−2γ2T). Proof: 1{error}≤e−yf(x), telescoping ZT=∏tZt+1/Zt with Zt+1/Zt=2εt+1(1−εt+1)≤e−2γ2.
Test error: VC bound with VC(HT)≲T⋅VC(B)log(TVC(B)) (needs T/n→0); the margin bound does not depend on T and explains why boosting keeps improving after zero training error. Weak and strong PAC learnability are equivalent. Gradient boosting fits each new base learner to the negative gradient of the loss; AdaBoost is the special case of the exponential loss.
Exam relevance
Real exam, task type “AdaBoost” (4 P): all formulas are given, a toy data set with a plot; compute h1, ε1, w1, the new weights D(2) (with normalization) and h2, then comment on the behaviour, for example whether stumps can solve an XOR configuration or what happens when εt=21. Train it with the task and the widget below.
Real exam, multiple choice: bagging came up (what it reduces, when it works).
Mock exam, task 7: prove that the training error is at most ZT and derive exp(−2γ2T) from Zt/Zt−1=2εt(1−εt). The full proof is below.
Sheet 7, Exercise 3 (why bagging reduces variance); Sheet 8 (boosting stumps by hand, implementing AdaBoost, gradient boosting and the choice of the base learner).
Only what you should know by heart in the exam. Click a card for the answer, or press a to go through them as flashcards. For Anki: deck of this lecture.
Variance of the average of B bagged estimates?
Answer
Variance σ2 each, pairwise correlation ρ: ρσ2+(1−ρ)Bσ2.
The shared part ρσ2 stays, only the rest averages out.
Random forests vs. boosting: which error does each reduce?
Answer
Random forests average many deep, overfitting trees: they reduce variance.
Boosting combines many underfitting weak learners with weights: it reduces bias.
How many of the original points does a bootstrap sample contain?
Answer
About 63% of the distinct points, since (1−n1)n→e−1≈0.37 are never drawn.
AdaBoost: weighted error and vote of the weak learner ht?
Answer
εt=∑iDi1[ht(xi)=yi] wt=21log(εt1−1)=21lnεt1−εt (also written αt)
AdaBoost: weight update and final classifier?
Answer
Di←Die−wtyiht(xi)/Z. After the update the misclassified points carry exactly half of the weight.
Output: sign(∑twtht(x)).
Training error bound of AdaBoost?
Answer
If every εt≤21−γ: training error ≤∏t2εt(1−εt)≤e−2γ2T.
Can AdaBoost with decision stumps fit XOR?
Answer
No. A weighted sum of stumps is additive in the coordinates, and XOR needs an interaction of both.
How is AdaBoost related to gradient boosting?
Answer
Gradient boosting fits each new base learner to the negative gradient of the loss.
AdaBoost is the special case of the exponential loss e−yf(x).
Overview: 1. Ensembles, bootstrap and bagging, 2. Random forests, 3. Boosting: weak and strong learners, 4. AdaBoost and its training error, 5. The test error of AdaBoost, 6. Gradient boosting.
Motivation from statistics: ensembles, bagging, bootstrap
Combining classifiers in ensembles
Slides 3-5
(Literature: the statistics point of view is discussed extensively in Hastie, Tibshirani and Friedman.)
No Free Lunch: there is no single best classifier, so we need to select classifiers, ideally based on their inductive bias.
Empirically, many classifiers are specialized: very good (or very confident) in some part of the space and poor in others.
Idea: combine many classifiers into one big, overarching “committee” classifier that is confident and good in all parts of the space. There are many approaches; the keyword is ensemble methods. Many of them originate in statistics.
Bootstrap
Slides 6-9
Cross validation estimates the test error by training on random subsets and testing on others, repeating the procedure and averaging the results. Statistics has a whole family of methods following this principle: the bootstrap.
The bootstrap method
We want to estimate a parameter Θ of an unknown distribution (for example the test error of a classifier) and have a sample X1,…,Xn and an estimate Θ^. To judge the estimate we would like to know its distribution (its variance, confidence sets), but the distribution is unknown.
Idea: construct an empirical distribution of the estimate. Draw a subsample of m points from the original sample (with or without replacement), compute the estimate on it, and repeat B times. The bootstrap estimates Θ^1,…,Θ^B form an empirical distribution that approximates the distribution of Θ^: use it for the mean, the variance, confidence sets.
Why and when does it make sense?
If the Θ^b were independent, the Glivenko-Cantelli theorem would say their empirical distribution approximates the true one.
But they are not independent: they are computed on largely overlapping samples. The question of bootstrap theory is under which conditions the empirical distribution is still a good approximation.
Intuitively this works if random reweighting of the observed data mimics real sampling variability. It tends to work for statistics based on averaging (mean, variance), and tends not to for extreme value statistics (maximum or minimum of a distribution).
Standard textbooks: Efron and Tibshirani, An Introduction to the Bootstrap; Shao and Tu, The Jackknife and Bootstrap (more mathematical).
Mini example (not on the slides): how many points does a bootstrap sample miss?
Drawing n points with replacement from n, a fixed point is never drawn with probability (1−n1)n→e−1≈0.368. So each bootstrap sample contains only about 63% of the distinct original points; the rest can serve as “out-of-bag” test points.
Bagging to reduce the variance
Slides 10-11
Bagging (bootstrap aggregation)
Generate B bootstrap samples, compute the estimate Θ^1,…,Θ^B on each, and take the average as the final estimate:
Θ^bag=mean(Θ^1,…,Θ^B)
The hope is that Θ^bag has a much smaller variance than each individual Θ^b.
Variance of the bagged estimate
If the Θ^b are identically distributed with variance σ2:
i.i.d.:Var(Θ^bag)=σ2/B, a reduction by the factor B;
pairwise correlation ρ>0:
Var(Θ^bag)=ρσ2+(1−ρ)Bσ2
For small ρ and large B this is still good. Whether bagging succeeds depends on how independent we manage the Θ^b to be.
Bagging reduces variance, not bias: averaging many estimates with the same systematic error keeps that error. For B→∞ the variance does not go to 0 but to ρσ2.
Memory aid
The shared part stays, the private part averages out:ρσ2+(1−ρ)σ2/B.
Each tree of an ensemble predicts at a fixed test point with variance σ2=4 and bias 0.5; any two trees have correlation ρ=0.2.
(a) (1 P, easy) Compute the variance of the average of B=10 trees and of B→∞ trees.
(b) (1.5 P, harder) How many trees are needed so that the variance is within 10% of its limit? What is the expected squared error of the infinite ensemble at this point (squared bias plus variance)?
(c) (1.5 P, transfer) A random forest decorrelates the trees by choosing each split among a random subset of dimensions, which lowers ρ to 0.05 but raises σ2 to 5. Is this a good trade for a large forest? What does bagging do to the bias?
(b) Need (1−ρ)σ2/B≤0.08: 3.2/B≤0.08⟺B≥40. Error of the infinite ensemble: 0.52+0.8=1.05 (a single tree: 0.25+4=4.25). (1.5 P)
(c) Limit variance 0.05⋅5=0.25<0.8: yes, for large B the lower correlation wins (with B=1 it would be worse, 5>4). The bias stays 0.5: averaging does not change the bias. (1.5 P)
Two opposing principles: bagging vs. boosting
Slide 12
Random forests: start with an ensemble of many deep decision trees that completely overfit, then build a naive average over many such trees and obtain a prediction function that generalizes well.
Boosting: use an ensemble of super-simple classifiers (decision stumps: trees of depth 1 or 2) that completely underfit, then build a specifically weighted average and obtain a prediction function that generalizes well.
Currently, random forests and boosting are about the most successful algorithms for machine learning on tabular data.
Random forests
Bagging decision trees
Slides 13-15
(Literature: Breiman, “Random forests”, Machine Learning 2001; overview: Biau and Scornet, “A random forest guided tour”, Test 2016; Hastie, Tibshirani and Friedman Ch. 8, 9, 15; Shalev-Shwartz and Ben-David Ch. 18; Tang, Garreau and von Luxburg, “When do random forests fail?”, NeurIPS 2018; Haghiri, Garreau and von Luxburg, “Comparison-based random forests”, ICML 2018.)
Apply bagging to regression or classification: repeatedly take a subsample, train a baseline algorithm on it to get f1,…,fB, and for a test point average the outputs, ybag=mean(f1(x),…,fB(x)).
Choosing the baseline algorithm:
The procedure is computationally expensive, so use a reasonably simple baseline.
Bagging reduces the variance most if there is little correlation between the classifiers: this is what we need to achieve.
If the classifiers have a strong bias, bagging cannot do anything about it.
A standard choice is decision trees, aggregated to a “forest”.
Spatial decision trees
Slides 16-19
Slide 16: a spatial partition tree on ℝᵈ. Left the partition of the space, right the tree.
Spatial decision tree (high-level)
Construct the tree recursively: for each cell, consider various splits in different dimensions and select one; keep splitting until cells contain a predefined number of points.
Split criterion (one example): split the points of a cell into A and Ac, predict the means Y^A and Y^Ac and compute
errorsplit=i∈A∑(Y^A−Yi)2+i∈Ac∑(Y^Ac−Yi)2
Typically axis-parallel splits: for every dimension k=1,…,d find the best splitting point sk (greedily) with error errorsplit,k; use the dimension with the smallest error.
Prediction: find the cell of the test point and predict the average of the training labels in the cell (regression) or the majority vote (classification).
Depth of the tree / leaf size. Keep splitting until a cell has fewer than nleaf points.
For a consistent single tree, the number of points per leaf has to increase slowly with n, for example nleaf=logn: shallow trees.
Random forests often use deep trees with a constant number of points per leaf (in the extreme nleaf=1). A single such tree would be a disaster (overfitting), but a forest of them can be consistent.
The random forest algorithm
Slides 20-22
Random forest
A random forest uses bagging to combine many spatial decision trees. Each tree is constructed randomly: on a random sample of the input points, and each split chooses the splitting dimension among a random subset of the dimensions.
Input: data points in ℝ^p. Parameters: B, N, n_min, m.
1. For b = 1 to B:
(a) Draw a bootstrap sample Z* of size N from the training data.
(b) Grow a random-forest tree T_b on Z* by recursively repeating, for each
terminal node, until the minimum node size n_min is reached:
i. select m variables at random from the p variables,
ii. pick the best variable / split point among the m,
iii. split the node into two daughter nodes.
2. Output the ensemble {T_b}, b = 1..B.
Regression: f(x) = (1/B) Σ_b T_b(x). Classification: majority vote of the T_b(x).
(Algorithm 15.1 of Hastie, Tibshirani and Friedman.)
Parameters:
the subsample size: reasonably large, with or without replacement (without replacement one often takes the size of the original sample);
the number m of dimensions from which the best one is picked: typically around d/3;
the number B of trees: large;
the leaf size nmin: deep trees (nmin=1, then B must be large) or shallow trees (n≈logn).
In principle the algorithm is not extremely sensitive to many of the parameters, but in a completely bad regime the trees can under- or overfit (Biau’s guided tour; “When do random forests fail?”).
Consistency of random forests
Slides 23-26
Consistency
A single spatial decision tree is consistent if the diameter of all cells converges to 0 and at the same time the number of points per cell tends to infinity as n→∞ (can you prove it?).
If all individual trees are consistent, so is the random forest (Biau, “Analysis of a random forests model”, JMLR 2012).
Curiously, a random forest can be consistent even if all its individual trees are not, in particular for deep trees (Scornet, “On the asymptotics of random forests”, Journal of Multivariate Analysis 2016). This is not obvious and depends on the exact setup (“When do random forests fail”, Tang, Garreau and von Luxburg 2018).
Slide 23: consistency of a single tree: diam(cell) → 0 and #points per cell → ∞.Slide 25: each deep tree has one point per cell, but the forest averages over many points that come from a larger region.
Outlook: comparison-based random forests. Random forests need a Euclidean representation. Alternative, the comparison tree: in the current cell pick two random points x1,x2, and split according to whether each point is closer to x1 or to x2. This can also lead to consistent classification and regression (Haghiri, Garreau and von Luxburg 2018) and works really well empirically.
Slide 26: splits of a comparison-based tree.
Boosting
Strong and weak learners
Slides 27-30
(Literature: Shalev-Shwartz and Ben-David Sec. 10; Hastie, Tibshirani and Friedman (a long chapter on boosting and gradient boosting); Schapire and Freund, Boosting: Foundations and Algorithms (a whole, very readable book); original paper Schapire and Freund 1995.)
Strong and weak learners, intuitively
A strong learner approximates the true solution up to a small error ε; constructing strong learners is the goal of machine learning, but they are often hard to construct and computationally expensive. A weak learner is just slightly better than random guessing: for balanced classes its 0-1 loss is 0.5−ε (its accuracy 0.5+ε).
The idea of boosting is to combine many weak learners to obtain a strong learner.
Weak and strong PAC learners (formally)
Data space X with distribution D, hypothesis class H, and the true classifier lives in it: y=h(x) for a deterministic h∈H (PAC = probably approximately correct).
H is strongly PAC-learnable if there is an algorithm such that for every ε,δ>0, every D and every h∈H, run on n(δ,ε) training points, it returns h^ with 0-1 loss at most ε with probability at least 1−δ.
H is weakly PAC-learnable if for some γ>0 there is an algorithm that takes n(δ) examples and returns h^ with ℓ01(h^)≤21−γ with probability at least 1−δ.
Efficiently weak / strong PAC-learnable: the algorithm runs in polynomial time (in particular sees only polynomially many samples).
For some time researchers wondered whether weak learnability is “easier” than strong learnability; see the end of this lecture.
Boosting: the outline and a toy example
Slides 31-36
Boosting, the outline
Given n training points, the algorithm proceeds in T rounds.
Training points have weights wi that change from round to round and always add up to 1.
In each round, train the weak classifier on the weighted points, then update the weights: increase the weight of misclassified points, decrease the weight of correctly classified points.
The final classifier is a weighted sum of the weak classifiers of all rounds.
Slide 32: uniform weights D₁ and the weak classifier h₁ (circled: its mistakes).Slide 33: new weights D₂ (symbol size) and h₂, which gets the heavy points right.Slide 34: weights D₃ and the third weak classifier h₃.
Slide 35: the combination H = sign(0.42·h₁ + 0.65·h₂ + 0.92·h₃), a weighted majority vote (figures from the Schapire/Freund book).
First remarks (slide 36):
Unlike random forests (randomness through subsampling points and dimensions), the training set in boosting is always the same; only the weights change.
By reweighting, the algorithm focuses on examples it finds difficult or on aspects overlooked so far.
Once a point has accumulated weight larger than 0.5, the weak learner will get it right. But it is not obvious that this helps the final classifier, because there are many points to get right. The question is how to combine the evidence of the weak classifiers into a strong classifier.
The AdaBoost algorithm
Slides 37-39
AdaBoost (slide 38, from Understanding Machine Learning)
Input: training set S=(x1,y1),…,(xm,ym) with yi∈{±1}, weak learner WL, number of rounds T.
Initialize the sample weights D(1)=(m1,…,m1).
Fort=1,…,T:
invoke the weak learner ht=WL(D(t),S);
compute the error at step t: εt=i=1∑mDi(t)1[yi=ht(xi)];
let the update factorwt=21log(εt1−1);
update Di(t+1)=∑j=1mDj(t)exp(−wtyjht(xj))Di(t)exp(−wtyiht(xi)) for all i.
Output the hypothesis hs(x)=sign(t=1∑Twtht(x)).
Why is it plausible that it works?
If the final classifier hs errs on a training point x, then (being a weighted majority vote) most weak classifiers got x wrong. So the weight of x was increased very often and must still be large after the final round. But only few points can have large weights, because all weights add up to 1. So only few points can be misclassified by the final classifier.
Computing the update by hand
Since yiht(xi)=+1 for correct and −1 for wrong points, and ewt=(1−εt)/εt:
correct points are multiplied by e−wt, wrong points by ewt;
after normalizing, the misclassified points together have weight exactly 21: each wrong point gets Di(t)/(2εt), each correct point Di(t)/(2(1−εt)).
Consequence: the old ht has weighted error exactly 21 under D(t+1), so the next weak learner has to do something different.
Special cases of εt
εt=21: wt=21log1=0. The weak learner is useless, the weights do not change, and AdaBoost makes no progress.
εt>21: wt<0; the classifier is flipped (for stumps, the flipped stump is in the class anyway).
εt=0: wt=∞; one weak learner already classifies everything correctly.
AdaBoost with axis-parallel decision stumps. Point size is the current weight, the orange line the last stump and its circled mistakes, the shading the sign of f_T. The tables list εₜ, wₜ and all weights, like in the exam. The preset "Task" is the data of the task below, "XOR" shows the case εₜ = ½.
Memory aid
Better than a coin flip → positive voteα=21lnε1−ε. After the update the mistakes carry exactly half of the weight, so the next learner has to fix them.
Theorem 1: the training error bound
Slides 40-45
Theorem 1 (training error of AdaBoost)
Run AdaBoost on a training set of size n for T rounds, and assume that in each round t the weak learner returns a function with weighted training 0-1 error εt≤21−γ for some γ>0. Then the training 0-1 error of the final output function is at most
exp(−2γ2T)
The training error decreases exponentially in the number of rounds.
Proof
Step 1: bound the 0-1 loss by the exponential loss. Let ft=∑p≤twphp (with f0≡0) and
Zt=n1i=1∑nexp(−yift(xi)),Z0=1
the empirical exponential loss. A point is misclassified iff yifT(xi)≤0, and 1{z≤0}≤e−z. So
training error(fT)=n1i∑1{signfT(xi)=yi}≤n1i∑e−yifT(xi)=ZT
(For ±1-valued h: 1(h(x)=y) is 0 or 1, while e−yh(x) is 1/e≈0.37 or e≈2.7.)
Step 2: telescoping. Since Z0=1,
ZT=ZT−1ZT⋅ZT−2ZT−1⋯Z0Z1
and it suffices to show ZtZt+1≤exp(−2γ2) for every factor.
Step 3: each factor. By induction, Di(t+1)=∑jexp(−yjft(xj))exp(−yift(xi)). Since ft+1=ft+wt+1ht+1,
(Details: Shalev-Shwartz and Ben-David Sec. 10, Schapire and Freund Sec. 3.1.)
Why wt=21log(εt1−1)?
The factor (1−ε)e−w+εew is minimized exactly at e2w=(1−ε)/ε: AdaBoost chooses the vote that decreases the exponential loss Zt as much as possible in each round.
Memory aid
Each round multiplies the bound by at most e−2γ2: the edge γ over a coin flip counts squared, so a weak learner with ε=0.4 needs about 350 rounds for 10−3.
Task: AdaBoost by hand
Exam-style task: AdaBoost with decision stumps (4 P)
Five points on the real line: xi=i for i=1,…,5 with labels y=(+1,+1,−1,−1,+1). The weak learners are decision stumps hθ,s(x)=s if x>θ and −s otherwise, with s∈{±1} and thresholds θ∈{1.5,2.5,3.5,4.5} (no constant classifiers). In each round the weak learner returns the stump with the smallest weighted error. Use the formulas of the AdaBoost algorithm.
(a) (1 P, easy) Determine h1, ε1 and w1.
(b) (1.5 P, harder) Compute D(2) (normalized) and determine h2, ε2 and w2.
(c) (1.5 P, transfer) Give the combined classifier sign(w1h1+w2h2) on the five points and its training error, and compare with the bound Z2=∏t2εt(1−εt). Then consider the XOR configuration (0,0),(1,1) with label +1 and (1,0),(0,1) with label −1 and stumps on either coordinate: what happens in the first round, and why?
Solution
(a) With uniform weights 51, the stump ”+1 for x<2.5, −1 for x>2.5” (θ=2.5, s=−1) only misclassifies x=5; every other stump makes at least two mistakes. ε1=51, w1=21log(5−1)=21log4=log2≈0.693. (1 P)
(b) Wrong point x=5: 51⋅elog2=52; correct points: 51⋅e−log2=101. Sum =4⋅101+52=54. So D(2)=(81,81,81,81,21) (the mistake now carries half the weight) (0.5 P). Weighted errors of the stumps that get x=5 right (+1 at x=5): θ=4.5,s=+1 errs on x=1,2: 41; θ=3.5,s=+1 errs on 1,2,4: 83; θ=2.5,s=+1 errs on 1,2,3,4: 21; θ=1.5,s=+1 errs on 1,3,4: 83. Stumps with −1 at x=5 already pay 21. So h2: ”+1 for x>4.5”, ε2=41, w2=21log3≈0.549. (1 P)
(c)f2=0.693h1+0.549h2: at x=1,2: 0.693−0.549>0, +1 ✓; at x=3,4: −0.693−0.549<0, −1 ✓; at x=5: −0.693+0.549<0, −1 ✗. Training error 51. Bound: 251⋅54⋅241⋅43=0.8⋅0.866≈0.69≥0.2 ✓ (0.75 P). XOR: every stump splits the square into two halves that each contain one + and one −, so every stump has weighted error exactly 21. Then w1=0, the weights stay uniform and every later round finds the same situation: AdaBoost never makes progress. The weak learning assumption εt≤21−γ fails for stumps on XOR; one needs richer base learners (trees of depth 2). (0.75 P)
AdaBoost runs on n=1000 training points, and every weak learner has weighted error at most 0.4.
(a) (1 P, easy) Give γ and the bound of Theorem 1 (training error of AdaBoost) after T=50 rounds.
(b) (1.5 P, harder) After how many rounds is the training error guaranteed to be zero?
(c) (1.5 P, transfer) Using the sharper per-round factor 2ε(1−ε) with ε=0.4, how many rounds suffice? Why does zero training error not mean that you should stop?
(b) The training error is a multiple of n1; if it is below n1 it is 0. e−2γ2T<10001⟺T>2γ2ln1000=0.026.91≈345.4, so T=346 rounds. (1.5 P)
(c)20.4⋅0.6≈0.980, so we need 0.980T<10−3: T>−ln0.980ln1000≈0.02046.91≈339 rounds. After zero training error the margins can still grow, and the margin bound (below) says the test error can keep decreasing; the VC bound, in contrast, gets worse with T. (1.5 P)
Bounding the test error of AdaBoost
A generalization bound based on VC theory
Slides 46-54
(Literature: Understanding Machine Learning.) Does the test error also improve during boosting? Yes, and there are many approaches to prove it; the lecture covers two.
The boosting class
If AdaBoost uses weak classifiers from a base class B (for example decision stumps), the final classifier lives in
HT={sign(t=1∑Twtht(x))w∈RT,ht∈B}
Theorem 2 (VC dimension of the boosting class)
For a base class B and the corresponding boosting class HT, T∈N:
VC(HT)≤T⋅VC(B)log(T⋅VC(B))
Proof sketch
Take a set C={x1,…,xn} shattered by HT. A labeling of C is produced by f(x)=∑twtht(x): first choose h1,…,hT∈B, then apply a linear classifier with weights w to the vector (h1(x),…,hT(x))∈RT. Count the labelings:
Let d=VC(B). By Sauer-Shelah, the base class realizes at most (en/d)d labelings of C; choosing T of them gives (en/d)d⋅T possibilities.
Linear classifiers on RT have VC dimension about T (Lecture 3), so they combine the base functions in at most (en/T)T ways.
Together: about (en/d)dT⋅(en/T)T≤n(d+1)T classifiers.
To shatter C we need 2n functions, which is possible as long as 2n≤n(d+1)T. The n where this stops to hold is the VC dimension; solving the equality gives n≤2log2(d+1)Tloglog2(d+1)T. Ignoring constants, this is the claim. □
Final generalization bound
With the VC bound of Lecture 3 (constants ignored):
R(fT)≤Rn(fT)+ndlog(n/d)−log(δ),d=dH=T⋅dB
The key quantity is TdB/n. The base class is simple (small constant dB), so we get generalization from training to test error if T/n→0.
Two ways to use it:
train few rounds T, live with the training error reached so far, and conclude by VC arguments that the test error is of the same order;
or train until the training error is really small and check how many rounds were needed: if T is still small compared to n, the test error is small too; if T is large compared to n, we have likely overfitted.
A generalization bound based on margins
Slides 55-57
The success of boosting is described even better by a margin-based theory. Normalize the non-negative weights of f(x)=∑t=1Twtht(x) such that ∑twt=1. Then yf(x)∈[−1,1] is the margin of the sample (x,y): it says how close or how far the point is from being misclassified.
Margin bound (Schapire and Freund, Theorem 5.5)
Let the base classifiers have VC dimension d and let S be a sample of m≥d≥1 i.i.d. examples. With probability at least 1−δ, every weighted average f∈co(H) (the convex hull of the base class; AdaBoost functions are contained in it) satisfies
Left side: the test error. First term on the right: not the training error, but the fraction of training points with margin at most θ.
If the margin is large, choose θ as a large constant: few points lie in the margin (small first term), and the complexity term is small too because θ is not close to 0.
The complexity term contains the VC dimension of the base classifier, not of the final classifier: the number T of rounds does not enter the bound.
This matches the empirical observation that boosting often keeps improving after the training error is already 0: the margin θ can still increase, while increasing T does not hurt.
Equivalence of weak and strong PAC learnability
Slides 58-59
Theorem 3 (weak = strong PAC learnability)
A hypothesis class H is (efficiently) weakly PAC-learnable if and only if it is (efficiently) strongly PAC-learnable.
Do you find it surprising? The proof (Schapire and Freund, Sec. 4.3) is not very difficult, but needs a boosting variant based on resampling instead of reweighting, so it is skipped.
Gradient boosting
AdaBoost as stagewise additive modeling
Slides 60-63
(Literature: Hastie, Tibshirani and Friedman Sec. 10; original paper: Friedman, “Greedy Function Approximation: A Gradient Boosting Machine”, Annals of Statistics 2001; the implementation that made it popular: Chen and Guestrin, “XGBoost: A scalable tree boosting system”, KDD 2016.)
Gradient boosting combines ideas of random forests with variants of boosting: optimizing the next model can be interpreted as gradient descent on the residuals (the errors we still make), which generalizes to other models and losses. It is extremely successful in practice (XGBoost).
Forward stagewise additive modeling
AdaBoost learns an additive model f(x)=∑t=1Twtht(x) with simple ht. More generally (“forward modeling”): fix a loss ℓ; fit a first base function h1 and freeze it; then add h2, optimize its parameters and w2, freeze them; and so on. With base functions hθ parameterized by θ, step t solves
AdaBoost is equivalent to this stagewise additive modeling with the exponential lossℓ(f(x),y)=exp(−yf(x)). That is pretty cool. For general losses and complicated base classes, solving each step analytically can be quite a challenge: this is where gradient boosting comes in.
Gradient boosting
Slides 64-66
Ideally one would run gradient descent on the step problem, but the base function classes are sometimes not even differentiable in their parameters θt. Approximation: compute the gradient of the loss with respect to the function values on all data points, and fit wthθt(xi) to be as close as possible to the negative gradient.
One step of gradient boosting
Given ft−1:
For all training points compute the gradient with respect to the prediction value y^=ft−1(xi) (a real number, not the parameters of ft−1):
ri:=∂ft−1(xi)∂ℓ(yi,ft−1(xi))
It tells in which direction y^ has to move to improve the loss.
2. Fit a base function to the negative gradient on all training points (a small regression problem):
θt=θargmini=1∑n(−ri−hθ(xi))2
Line search for the step size: wt=argminw∑iℓ(yi,ft−1(xi)+whθt(xi)).
Set ft=ft−1+wthθt.
Trap
Slide 66 writes step 2 as θt=argminθ∑i(ri−hθ(xi)). It needs a square (a regression fit), and the base function should approximate the negative gradient −ri (or equivalently the step size wt becomes negative).
Mini example: squared loss = fitting the residuals
With ℓ(y,y^)=21(y−y^)2 the gradient is ri=−(yi−ft−1(xi)), so −ri is the residual. Labels y=(3,5,10) and f0≡6 (the mean): residuals (−3,−1,4). The next tree is fitted to (−3,−1,4); if it predicts them exactly and w1=1, f1=f0+h1 fits the data perfectly.
XGBoost and boosted trees vs. random forests
Slides 67-68
XGBoost is one of the most popular implementations of gradient boosting; it applies gradient boosting to decision trees as base classifiers.
Random forest
Boosted trees
training
in parallel, trees as independent as possible
sequentially, each tree corrects the errors of the previous ones
combination
simple average
weighted sum (gradient step)
base learner
deep, overfitting trees
shallow trees (stumps)
targets
the variance of the estimator
the bias (and perhaps the variance as well), by directly minimizing the loss by gradient descent
Summary
Bagging / random forest
AdaBoost
Gradient boosting
idea
average many decorrelated estimates
reweight points, weighted vote of weak learners
fit each new learner to the negative gradient
key formula
Var=ρσ2+(1−ρ)σ2/B
wt=21log(εt1−1), mistakes get weight 21
ri=∂ℓ/∂ft−1(xi)
guarantee
consistency (cells shrink, points per cell grow)
training error ≤e−2γ2T; margin bound independent of T
stagewise minimization of the loss
reduces
variance
bias
bias
Self-Test
Question cards (13)
Describe the bootstrap and when it tends to work.
Answer
Recompute the estimate on B resamples of the data and use the B values as an empirical distribution of the estimate (variance, confidence sets). The resamples overlap, so the estimates are dependent; it works well for averaging statistics (mean, variance), badly for extreme value statistics (max, min).
What is bagging, and what is the variance of a bagged estimate?
Answer
The average of B bootstrap estimates. With variance σ2 and pairwise correlation ρ: ρσ2+(1−ρ)σ2/B; for independent estimates σ2/B. It reduces variance, not bias.
Contrast the two principles behind random forests and boosting.
Answer
Random forests average many deep, overfitting trees (low bias, high variance) and reduce the variance. Boosting combines many underfitting weak learners (high bias) with specific weights and reduces the bias.
How is a spatial decision tree grown, and what makes a single tree consistent?
Answer
Recursively split cells along axis-parallel directions, choosing per cell the dimension and point with the smallest split error (for example the sum of squared deviations from the cell means), until the leaf size is reached. Consistent if cell diameters go to 0 and the number of points per cell goes to infinity.
What makes a random forest random, and what are its parameters?
Answer
Each tree is grown on a random (bootstrap) sample, and each split chooses among m randomly selected dimensions (typically m≈d/3). Parameters: subsample size, m, number of trees B, leaf size nmin.
Can a random forest be consistent if its trees are not?
Answer
Yes, in particular for deep trees with one point per cell (Scornet 2016): each tree overfits, but the forest averages over many points from a larger region. It depends on the exact setup.
Define weak and strong PAC learnability.
Answer
Strong: for every ε,δ, every distribution and every true h∈H, n(δ,ε) samples give error ≤ε w.p. ≥1−δ. Weak: for some fixed γ>0, error ≤21−γ w.p. ≥1−δ. By Theorem 3 (weak = strong PAC learnability) they are equivalent.
After an AdaBoost update, what is the total weight of the points ht got wrong, and why does this matter?
Answer
Exactly 21 (each wrong point gets Di/(2εt), each correct one Di/(2(1−εt))). So ht has error 21 under the new weights and the next weak learner must be different.
State Theorem 1 (training error of AdaBoost) and give the steps of its proof.
Answer
If εt≤21−γ, training error ≤e−2γ2T. Steps: training error ≤ZT=n1∑ie−yifT(xi); telescoping ZT=∏Zt+1/Zt; each factor equals 2εt+1(1−εt+1)≤1−4γ2≤e−2γ2.
What does the VC-based test error bound of AdaBoost require?
Answer
VC(HT)≲TdBlog(TdB), so the bound needs TdB/n→0: few rounds relative to n.
Why does the margin bound explain that boosting keeps improving after zero training error?
Answer
The test error is bounded by the fraction of training points with margin ≤θ plus O(θ1dlogn/n) with the base class VC dimension; T does not appear. More rounds can increase the margins without increasing the complexity term.
How does gradient boosting work, and how is AdaBoost related?
Answer
Stagewise: compute the gradient ri of the loss w.r.t. the current predictions, fit a base learner to −ri by least squares, line-search the step wt, add wtht. For the squared loss this fits the residuals. AdaBoost is stagewise additive modeling with the exponential loss.
Multiple Choice
Multiple choice (8)
What does bagging reduce?
the bias of the base estimator
the variance of the base estimator
both bias and variance by the factor B
the number of training points needed
Explanation
Averaging identically distributed estimates keeps their mean (bias) and reduces the variance to ρσ2+(1−ρ)σ2/B.
Bagged estimates with variance σ2 and pairwise correlation ρ. As B→∞, the variance of the average tends to
0
σ2/B
ρσ2
(1−ρ)σ2
Explanation
The term (1−ρ)σ2/B vanishes; the correlated part remains. This is why random forests decorrelate their trees.
In round t the weak learner has weighted error εt=21. Then
wt=∞ and AdaBoost stops
wt=0 and the weights do not change
wt<0 and the classifier is flipped
the misclassified points get weight 1
Explanation
wt=21log(2−1)=0; the update factors are e0=1. This is what happens for stumps on XOR.
εt=0.2. By which factor is the (unnormalized) weight of a misclassified point multiplied?
4
2
21
2
Explanation
ewt=(1−ε)/ε=4=2; correct points get 21. After normalization the mistakes carry weight 21 in total.
Which statement about Theorem 1 (training error of AdaBoost) is true?
It bounds the test error of AdaBoost by e−2γ2T.
It bounds the training error by e−2γ2T if every εt≤21−γ.
It needs the base class to have finite VC dimension.
It holds for any choice of the weights wt.
Explanation
It is a training error bound, uses the weak learning assumption and the specific wt of AdaBoost (which minimize each factor Zt+1/Zt); VC dimensions only enter the test error bounds.
In the margin bound for AdaBoost, which quantity does NOT appear in the complexity term?
the VC dimension of the base class
the margin parameter θ
the number of rounds T
the sample size
Explanation
The key point of the margin bound: T does not enter, in contrast to the VC bound with VC(HT)≈TdBlog(⋅).
AdaBoost is equivalent to forward stagewise additive modeling with which loss?
Which statement about random forests and boosted trees is true?
Both train their trees sequentially.
Random forests mainly reduce variance; boosted trees mainly reduce bias.
Random forests use decision stumps, boosting uses deep trees.
Boosting draws a bootstrap sample for each tree.
Explanation
Slide 68: forests average independent deep trees in parallel; boosting builds shallow trees sequentially on the same (reweighted) data to correct previous errors.
Cheat sheet and full integration tasks
The two tasks below use every calculation of this lecture once: three rounds of AdaBoost by hand on a plot, then the variance of bagging, the training error bound and one step of gradient boosting. Write your own sheet first, solve the tasks with it next to you, then open the sheet at the bottom and compare. The letters in brackets name the block of the sheet that a subtask needs.
Six points: (1,1), (1,2), (3,1) with label +1 and (1,3), (2,1), (3,3) with label −1. The weak learners are decision stumps on one coordinate j∈{1,2}: h(x)=s if x(j)>θ and −s otherwise, with s∈{±1} and θ∈{1.5,2.5}. In every round the weak learner returns the stump with the smallest weighted error. The AdaBoost formulas are given: εt=∑iDi(t)1[yi=ht(xi)], wt=21log(εt1−1), Di(t+1)∝Di(t)exp(−wtyiht(xi)).
(a) (2 P, block A) Determine h1, ε1 and w1.
(b) (2 P, block A) Compute D(2), normalized, and check it.
(c) (3 P, block A) Determine h2, ε2 and w2.
(d) (3 P, blocks A and C) Give the combined classifier sign(w1h1+w2h2) on the six points and its training error. Compare with the bound Z2=∏t2εt(1−εt).
(e) (3 P, block A) Compute D(3). The third stump is h3: +1 for x(1)>2.5 and −1 otherwise. Compute ε3 and w3 and the final classifier on all six points.
(f) (3 P, block B) Now take the XOR configuration (1,1),(2,2) with label +1 and (1,2),(2,1) with label −1. What happens in the first round, and why? And what does AdaBoost do with a stump that has εt>21?
Solution
(a) With uniform weights 61, count the mistakes of every stump. The stump ”−1 for x(2)>2.5, +1 otherwise” only misclassifies (2,1). Every other stump makes at least two mistakes. So h1 is this stump, ε1=61 and w1=21log5≈0.805. (2 P)
(b) The wrong point gets Di/(2ε1)=61⋅3=21, every correct point Di/(2(1−ε1))=61⋅53=101. So D(2) is 21 at (2,1) and 101 at the other five points. Check: 21+5⋅101=1, and the mistake carries exactly half of the weight. (2 P)
(c) Weighted errors under D(2), best orientation of each line:
Stump
Mistakes
Weighted error
x(2)>2.5→−1 (the old h1)
(2,1)
21
x(2)>1.5→+1
(1,1), (3,1), (1,3), (3,3)
104
x(1)>1.5→−1
(3,1), (1,3)
102
x(1)>2.5→+1
(1,1), (1,2), (3,3)
103
So h2: +1 for x(1)<1.5 and −1 for x(1)>1.5, with ε2=51 and w2=21log4≈0.693. (3 P)
(d)f2=0.805h1+0.693h2. Where the two stumps disagree, h1 wins because its vote is larger.
Point
y
h1
h2
f2
correct?
(1,1)
+
+
+
1.498
yes
(1,2)
+
+
+
1.498
yes
(3,1)
+
+
−
0.112
yes
(1,3)
−
−
+
−0.112
yes
(2,1)
−
+
−
0.112
no
(3,3)
−
−
−
−1.498
yes
Training error 61. Bound: Z2=261⋅65⋅251⋅54=0.745⋅0.8≈0.60≥61. (3 P)
(e) Under D(2) the mistakes of h2 are (3,1) and (1,3): each gets 101/(2⋅51)=41. Correct points are divided by 2⋅54=58: (2,1) gets 21⋅85=165, and (1,1), (1,2), (3,3) get 161 each. Check: 41+41=21 and the total is 1. h3 misclassifies (1,1), (1,2) and (3,3): ε3=163 and w3=21log313≈0.733.
Final values f3=0.805h1+0.693h2+0.733h3: (1,1) and (1,2): 0.805+0.693−0.733=0.765. (3,1): 0.805−0.693+0.733=0.845. (1,3): −0.805+0.693−0.733=−0.845. (2,1): 0.805−0.693−0.733=−0.622. (3,3): −0.805−0.693+0.733=−0.765. All six signs are right: training error 0 after three rounds, although every single stump makes mistakes. (3 P)
(f) Every stump cuts the square into two halves, and each half contains one + and one −. So every stump has weighted error exactly 21, the vote is w1=21log1=0 and the weights stay uniform. Every later round finds the same situation: AdaBoost makes no progress, because the weak learning assumption εt≤21−γ fails. A stump with εt>21 gets a negative vote, which is the same as using the flipped stump with error 1−εt. (3 P)
Full integration task: bagging, the bound and one gradient step (12 P)
(a) (2 P, block D) Each tree of an ensemble predicts at a fixed test point with variance σ2=9 and bias 1. Any two trees have correlation ρ=0.25. Compute the variance of the average of B=12 trees and of B→∞ trees.
(b) (2 P, block D) How many trees bring the variance within 10% of its limit? Compare the expected squared error of the infinite ensemble with that of a single tree.
(c) (3 P, block C) AdaBoost runs on n=500 points, and every weak learner has weighted error at most 0.3. Give γ, the bound on the training error after T=20 rounds, and the number of rounds after which the training error is guaranteed to be 0.
(d) (1 P, block C) How many rounds suffice with the sharper factor 2ε(1−ε) per round?
(e) (2 P, block E) The test error of a boosted model keeps falling after the training error has reached 0. Which of the two test error bounds explains this, and which one gets worse with more rounds?
(f) (2 P, block E) Gradient boosting with the squared loss 21(y−y^)2 on three points with labels y=(1,4,10), starting from the mean f0≡5. The next base function is a stump that separates the first two points from the third and predicts the mean of its targets on each side. Compute the targets, the stump and f1 with step size 1.
Solution
(a)Var=ρσ2+(1−ρ)Bσ2=0.25⋅9+0.75⋅129=2.25+0.5625≈2.81. For B→∞: ρσ2=2.25. (2 P)
(b) The part that still shrinks must be at most 10% of the limit: B0.75⋅9≤0.225⟺B≥30. Squared error of the infinite ensemble: 12+2.25=3.25. A single tree: 1+9=10. The bias stays, only the variance falls. (2 P)
(c)γ=0.5−0.3=0.2. After 20 rounds: exp(−2⋅0.04⋅20)=e−1.6≈0.20. The training error is a multiple of n1, so it is 0 as soon as the bound is below 5001: T>2γ2ln500=0.086.21≈77.7, so T=78 rounds. (3 P)
(d)20.3⋅0.7≈0.917. 0.917T<5001⟺T>−ln0.917ln500≈0.0876.21≈71.3, so 72 rounds. (1 P)
(e) The margin bound explains it: it contains the VC dimension of the base class and the margin θ, but not the number of rounds, and the margins can keep growing after the training error is 0. The VC bound uses d=T⋅dB and gets worse with every round. (2 P)
(f) For the squared loss the negative gradient is the residual yi−f0(xi): targets (−4,−1,5). The stump predicts the mean on each side: −2.5 for the first two points and 5 for the third. f1=f0+h1=(2.5,2.5,10), with the new residuals (−1.5,1.5,0). (2 P)
Cheat sheet: bagging and boosting (6 blocks)
A. One round of AdaBoost by hand
Stump. For every candidate line and both orientations, add the weights of the points on the wrong side. Take the smallest sum: that is ht with error εt.
Vote.wt=21logεt1−εt.
New weights. A wrong point gets 2εtDi, a correct point 2(1−εt)Di. No exponentials needed.
Checks. The wrong points together have weight exactly 21, and all weights add up to 1.
Combined classifier. One row per point with h1,h2,… and the sum ∑twtht(x). Its sign is the prediction.
εt
vote wt
factor 2εt(1−εt)
21
0
1
0.4
0.20
0.98
31
0.35
0.94
41
0.55
0.87
51
0.69
0.80
61
0.80
0.75
0.1
1.10
0.60
The factor is the amount by which one round multiplies the bound of block C.
B. Reading the plot and special cases
You see
It means
a stump as a line with a + side and a − side
its error is the weight of the points on the wrong side
the flipped stump
error 1−ε. Use whichever orientation is below 21
a stump with εt=21
vote 0, the weights do not change, no progress
every stump has one + and one − on each side (XOR)
ε=21 for all stumps: boosting stumps fails, it needs deeper trees
a point with weight 21
the next stump has to get it right, otherwise its error is at least 21
the old stump under the new weights
error exactly 21, so the next stump must be a different one
two stumps disagree at a point
the one with the larger vote decides
Left: the error of a stump is the weight of the circled points, the ones on the wrong side. Right: on XOR every stump is wrong on exactly half of the weight.
C. Training error bound
Edge γ=21−ε (with the largest error of the weak learners).
Training error ≤ZT=∏t≤T2εt(1−εt)≤exp(−2γ2T).
Zero training error is guaranteed once the bound is below n1: T>2γ2lnn, or with the sharper factor T>−ln(2ε(1−ε))lnn. Round up.
D. Bagging
Var(average of B)=ρσ2+(1−ρ)Bσ2
Independent (ρ=0): σ2/B. Limit for B→∞: ρσ2.
Within a fraction q of the limit: B≥qρ1−ρ.
The bias does not change. Squared error = bias2+ variance.
A bootstrap sample misses a fixed point with probability (1−n1)n≈0.37.
E. Test error and the three methods
You see
It means
VC bound with d=T⋅dB
gets worse with every round, needs T/n→0
margin bound
T does not appear: the test error can fall after the training error is 0
deep trees, averaged in parallel
bagging or random forest: lowers the variance
stumps, added one after the other with votes
boosting: lowers the bias
gradient boosting with the squared loss
the next tree is fitted to the residuals yi−ft−1(xi)
F. Traps
Normalize the new weights. With the shortcut of block A they already add up to 1.
Use the weighted error under the current D(t), not the number of mistakes.
The combined classifier is the sign of the weighted sum, not a majority of the stumps.
The bound ZT can be far above the true training error. It is still a valid check.
Bagging cannot repair a bias, and its variance does not go to 0 if the trees are correlated.
References
All sources cited on the slides, in slide order (19 entries)
Slide
Source
Key point
4
Hastie, Tibshirani and Friedman, The Elements of Statistical Learning (online)
statistics view of ensembles
9
Efron and Tibshirani, An Introduction to the Bootstrap
standard bootstrap textbook
9
Shao and Tu, The Jackknife and Bootstrap
mathematical treatment
13
Breiman, “Random forests”, Machine Learning, 2001
original random forest paper
13
Biau and Scornet, “A random forest guided tour”, Test 25(2):197-227, 2016
overview
13
Hastie, Tibshirani and Friedman, Ch. 8, 9, 15; Shalev-Shwartz and Ben-David, Ch. 18
textbooks
13, 22, 24
Tang, Garreau and von Luxburg, “When do random forests fail?”, NeurIPS 2018
failure regimes of forests
13, 26
Haghiri, Garreau and von Luxburg, “Comparison-Based Random Forests”, ICML 2018
comparison trees
21
Hastie, Tibshirani and Friedman, Algorithm 15.1
random forest pseudocode
23
Biau, “Analysis of a random forests model”, JMLR, 2012
consistent trees give a consistent forest
24
Scornet, “On the asymptotics of random forests”, Journal of Multivariate Analysis, 2016
forests of inconsistent deep trees
27
Shalev-Shwartz and Ben-David, Understanding Machine Learning, Sec. 10 (online)
boosting
27, 32-35, 56
Schapire and Freund, Boosting: Foundations and Algorithms
boosting book, toy example, margin bound
27
Schapire and Freund, 1995
original AdaBoost paper
38
Understanding Machine Learning
AdaBoost pseudocode
44
Shalev-Shwartz and Ben-David Sec. 10; Schapire and Freund Sec. 3.1