ContentsChapter 7 · Trees and ensembles2 of 3

7.2

Bagging and random forests

In this chapter
  1. 7.1Decision trees
  2. 7.2Bagging and random forests
  3. 7.3Boosting
Before you readChange one training sample and a tree may choose a different first split. How could you make its prediction less sensitive to that one sample?
Watch: Random Forests Part 1: Building, Using and Evaluating · StatQuest with Josh Starmer

Instead of trusting one tree, train many and combine their predictions. In bagging (bootstrap aggregating), make a training set for each tree by drawing nn rows from the original nn with replacement. A row can appear more than once; another may never be drawn. Fit the trees separately, then vote for a class or average their predictions for regression.

Combining trees reduces variance when the trees’ errors don’t all move together. But if one feature is much more useful than the others, many bagged trees might split on it first and make similar mistakes. A random forest draws a fresh random subset of features at each split, then picks the best split among those features. Bootstrap samples vary the rows the trees see; feature sampling varies the questions they can ask.

00.250.50.7511255075100
Variance, 1 tree: 1100 trees: 0.258
Each tree's error has variance σ2=1\sigma^2=1 and each pair has error correlation ρ\rho The curve shows the variance of the average, ρσ2+(1−ρ)σ2/B\rho\sigma^2+(1-\rho)\sigma^2/B for BB trees. The dashed line is the floor ρσ2\rho\sigma^2 What happens when every pair makes perfectly correlated errors?

A row not drawn for a particular tree is out of bag for that tree. Predict each training row using only trees for which it was out of bag. Comparing those predictions with the labels gives an estimate of performance on unseen data without reserving a separate validation split for this estimate.

Recall
What are the two steps in bagging?
Recall
What does a random forest add to bagging, and why?
Exercise
Three trees have bootstrap samples [1,1,3,4][1,1,3,4] [2,3,3,4][2,3,3,4] and [1,2,2,4][1,2,2,4] Which tree can make an out-of-bag prediction for row 2?
Exercise
Two forests have equally accurate individual trees. In one forest the trees almost always make mistakes on the same rows. In the other their mistakes rarely coincide. Which is more likely to gain from voting?