TL;DR

  1. 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).
  2. Bootstrap approximates the distribution of an estimate by recomputing it on resamples. Bagging averages the bootstrap estimates: with pairwise correlation the variance is instead of , so success depends on how independent the estimates are.
  3. Random forests: bagged spatial decision trees, each grown on a random subsample with the split dimension chosen from a random subset of dimensions. A forest can be consistent even if its individual (deep) trees are not.
  4. AdaBoost: start with uniform weights; in round fit a weak learner with weighted error , give it the vote , multiply the weights by and renormalize. Output .
  5. Theorem 1 (training error of AdaBoost): if every , the training error is at most . Proof: , telescoping with .
  6. Test error: VC bound with (needs ); the margin bound does not depend on 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 , , , the new weights (with normalization) and , then comment on the behaviour, for example whether stumps can solve an XOR configuration or what happens when . 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 and derive from . 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).
  • Everything in one go: the cheat sheet with two full integration tasks at the end of this note.

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 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 points from the original sample (with or without replacement), compute the estimate on it, and repeat times. The bootstrap estimates 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 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 points with replacement from , a fixed point is never drawn with probability . 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 bootstrap samples, compute the estimate on each, and take the average as the final estimate:

The hope is that has a much smaller variance than each individual .

Variance of the bagged estimate

If the are identically distributed with variance :

  • i.i.d.: , a reduction by the factor ;
  • pairwise correlation :

For small and large this is still good. Whether bagging succeeds depends on how independent we manage the to be.

Trap

Bagging reduces variance, not bias: averaging many estimates with the same systematic error keeps that error. For the variance does not go to 0 but to .

Memory aid

The shared part stays, the private part averages out: .

Task: the variance of bagging

Exam-style task: bagging (4 P)

Math: variance of an average

Each tree of an ensemble predicts at a fixed test point with variance and bias ; any two trees have correlation .

(a) (1 P, easy) Compute the variance of the average of trees and of 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 but raises to . Is this a good trade for a large forest? What does bagging do to the bias?

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 , and for a test point average the outputs, .

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

Left: a partition of the plane into rectangles by axis-parallel splits; right: the corresponding binary tree with split conditions
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 and , predict the means and and compute
  • Typically axis-parallel splits: for every dimension find the best splitting point (greedily) with error ; 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 points.

  • For a consistent single tree, the number of points per leaf has to increase slowly with , for example : shallow trees.
  • Random forests often use deep trees with a constant number of points per leaf (in the extreme ). 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 of dimensions from which the best one is picked: typically around ;
  • the number of trees: large;
  • the leaf size : deep trees (, then must be large) or shallow trees ().

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 (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).
A partition with a highlighted cell; a decision tree is consistent if the cell diameters go to zero and the number of points per cell goes to infinity
Slide 23: consistency of a single tree: diam(cell) → 0 and #points per cell → ∞.
Three deep trees whose cells each contain one point; overlaid, the forest averages over many points from a larger region
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 , and split according to whether each point is closer to or to . This can also lead to consistent classification and regression (Haghiri, Garreau and von Luxburg 2018) and works really well empirically.

Three steps of a comparison tree: pairs of points define splitting lines between them
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 (its accuracy ).

The idea of boosting is to combine many weak learners to obtain a strong learner.

Weak and strong PAC learners (formally)

Data space with distribution , hypothesis class , and the true classifier lives in it: for a deterministic (PAC = probably approximately correct).

  • is strongly PAC-learnable if there is an algorithm such that for every , every and every , run on training points, it returns with 0-1 loss at most with probability at least .
  • is weakly PAC-learnable if for some there is an algorithm that takes examples and returns with with probability at least .
  • 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 training points, the algorithm proceeds in rounds.
  • Training points have weights 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.
Round 1: ten points with uniform weights and a vertical stump; three positive points are misclassified
Slide 32: uniform weights D₁ and the weak classifier h₁ (circled: its mistakes).
Round 2: the three misclassified points have larger weights; the new stump classifies them correctly but makes other mistakes
Slide 33: new weights D₂ (symbol size) and h₂, which gets the heavy points right.
Round 3: new weights and a horizontal stump
Slide 34: weights D₃ and the third weak classifier h₃.
The final classifier H = sign(0.42 h1 + 0.65 h2 + 0.92 h3) and the resulting partition that classifies all points correctly
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 with , weak learner WL, number of rounds .

Initialize the sample weights .

For :

  • invoke the weak learner ;
  • compute the error at step : ;
  • let the update factor ;
  • update for all .

Output the hypothesis .

Why is it plausible that it works?

If the final classifier errs on a training point , then (being a weighted majority vote) most weak classifiers got wrong. So the weight of 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 for correct and for wrong points, and :

  • correct points are multiplied by , wrong points by ;
  • after normalizing, the misclassified points together have weight exactly : each wrong point gets , each correct point .

Consequence: the old has weighted error exactly under , so the next weak learner has to do something different.

Special cases of

  • : . The weak learner is useless, the weights do not change, and AdaBoost makes no progress.
  • : ; the classifier is flipped (for stumps, the flipped stump is in the class anyway).
  • : ; 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 . 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 for rounds, and assume that in each round the weak learner returns a function with weighted training 0-1 error for some . Then the training 0-1 error of the final output function is at most

The training error decreases exponentially in the number of rounds.

Why ?

The factor is minimized exactly at : AdaBoost chooses the vote that decreases the exponential loss as much as possible in each round.

Memory aid

Each round multiplies the bound by at most : the edge over a coin flip counts squared, so a weak learner with needs about 350 rounds for .

Task: AdaBoost by hand

Exam-style task: AdaBoost with decision stumps (4 P)

Math: logs and exponentials

Five points on the real line: for with labels . The weak learners are decision stumps if and otherwise, with and thresholds (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 , and .

(b) (1.5 P, harder) Compute (normalized) and determine , and .

(c) (1.5 P, transfer) Give the combined classifier on the five points and its training error, and compare with the bound . Then consider the XOR configuration with label and with label and stumps on either coordinate: what happens in the first round, and why?

Task: how many rounds?

Exam-style task: the training error bound (4 P)

Math: solving e^(-cT) < δ

AdaBoost runs on training points, and every weak learner has weighted error at most .

(a) (1 P, easy) Give and the bound of Theorem 1 (training error of AdaBoost) after 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 with , how many rounds suffice? Why does zero training error not mean that you should stop?

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 (for example decision stumps), the final classifier lives in

Theorem 2 (VC dimension of the boosting class)

For a base class and the corresponding boosting class , :

Final generalization bound

With the VC bound of Lecture 3 (constants ignored):

The key quantity is . The base class is simple (small constant ), so we get generalization from training to test error if .

Two ways to use it:

  • train few rounds , 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 is still small compared to , the test error is small too; if is large compared to , 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 such that . Then is the margin of the sample : 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 and let be a sample of i.i.d. examples. With probability at least , every weighted average (the convex hull of the base class; AdaBoost functions are contained in it) satisfies

for all . Somewhat simplified, ignoring constants: for all ,

What the margin bound says

  • 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 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 does not hurt.

Equivalence of weak and strong PAC learnability

Slides 58-59

Theorem 3 (weak = strong PAC learnability)

A hypothesis class 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 with simple . More generally (“forward modeling”): fix a loss ; fit a first base function and freeze it; then add , optimize its parameters and , freeze them; and so on. With base functions parameterized by , step solves

AdaBoost is equivalent to this stagewise additive modeling with the exponential loss . 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 . Approximation: compute the gradient of the loss with respect to the function values on all data points, and fit to be as close as possible to the negative gradient.

One step of gradient boosting

Given :

  1. For all training points compute the gradient with respect to the prediction value (a real number, not the parameters of ):

It tells in which direction has to move to improve the loss. 2. Fit a base function to the negative gradient on all training points (a small regression problem):

  1. Line search for the step size: .
  2. Set .

Trap

Slide 66 writes step 2 as . It needs a square (a regression fit), and the base function should approximate the negative gradient (or equivalently the step size becomes negative).

Mini example: squared loss = fitting the residuals

With the gradient is , so is the residual. Labels and (the mean): residuals . The next tree is fitted to ; if it predicts them exactly and , 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 forestBoosted trees
trainingin parallel, trees as independent as possiblesequentially, each tree corrects the errors of the previous ones
combinationsimple averageweighted sum (gradient step)
base learnerdeep, overfitting treesshallow trees (stumps)
targetsthe variance of the estimatorthe bias (and perhaps the variance as well), by directly minimizing the loss by gradient descent

Summary

Bagging / random forestAdaBoostGradient boosting
ideaaverage many decorrelated estimatesreweight points, weighted vote of weak learnersfit each new learner to the negative gradient
key formula, mistakes get weight
guaranteeconsistency (cells shrink, points per cell grow)training error ; margin bound independent of stagewise minimization of the loss
reducesvariancebiasbias

Self-Test

Multiple Choice

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.

Full integration task: AdaBoost by hand (16 P)

Math: logs and exponentials

Six training points on a grid: (1,1), (1,2) and (3,1) with label +1, and (1,3), (2,1) and (3,3) with label -1

Six points: , , with label and , , with label . The weak learners are decision stumps on one coordinate : if and otherwise, with and . In every round the weak learner returns the stump with the smallest weighted error. The AdaBoost formulas are given: , , .

(a) (2 P, block A) Determine , and .

(b) (2 P, block A) Compute , normalized, and check it.

(c) (3 P, block A) Determine , and .

(d) (3 P, blocks A and C) Give the combined classifier on the six points and its training error. Compare with the bound .

(e) (3 P, block A) Compute . The third stump is : for and otherwise. Compute and and the final classifier on all six points.

(f) (3 P, block B) Now take the XOR configuration with label and with label . What happens in the first round, and why? And what does AdaBoost do with a stump that has ?

Full integration task: bagging, the bound and one gradient step (12 P)

Math: variance of an average · solving e^(-cT) < δ

(a) (2 P, block D) Each tree of an ensemble predicts at a fixed test point with variance and bias 1. Any two trees have correlation . Compute the variance of the average of trees and of 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 points, and every weak learner has weighted error at most . Give , the bound on the training error after 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 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 on three points with labels , starting from the mean . 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 with step size 1.

References