Search

Search papers and lessons

A Random Forest Guided Tour

Gérard Biau, Erwan Scornet · 2016

Biau and Scornet's 2016 survey explains what Breiman's random forest does, why its theory lags its practice, and which simplified forests have proven guarantees.

On this page

  • Colour = topic mix
  • Probability
  • Discrete math
  • Classical models
  • Learning basics
  • Calculus
  • Inference
  • Sign in to see your progress

TL;DR

A Random Forest predicts by averaging many randomised trees, each grown on a bootstrap sample of the data, and each allowed to split on only a random subset of the features. Leo Breiman introduced it in 2001, and it remains one of the most reliable general-purpose predictors. Its theory has lagged its practice, because bagging and the CART split rule are hard to analyse together.

The survey by Gérard Biau and Erwan Scornet is a guided tour of that theory. It describes Breiman's algorithm in full, then studies simplified forests that can be analysed. For each one it states what is proved: consistency, rates of convergence, and the link to nearest-neighbour averages. Consistency is defined in Statistical Consistency.

Where you'll see it: tabular prediction problems with many features and modest sample sizes, variable importance rankings in applied statistics, and as a strong baseline in machine learning competitions.

The problem

Modern datasets can be large, with many features, and a predictor must scale with them while remaining statistically efficient. Random forests meet both needs in practice. They handle many features, need little tuning, and parallelise easily. Breiman's 2001 paper gave the best-known theoretical result, an upper bound on the generalisation error in terms of how strong each tree is and how correlated the trees are.

The gap is that the algorithm is a combination of several interacting parts. It resamples the data, it picks features at random, it grows trees by a greedy split rule, and it averages the trees. Each part is simple, but the whole is hard to analyse. As a result, most theory studies a stripped-down version, and it has been unclear how far the results carry over to the real algorithm. The survey's job is to lay out what each theoretical approach proves and what it leaves out.

Key idea

A forest is an average of trees, and each tree is a local averager. A tree splits the input space into boxes, and predicts by averaging the responses of the training points that fall in the same box as the query. Each tree is therefore a nearest-neighbour style estimate with its own shape of neighbourhood. Averaging many such trees, each built on different random data and features, smooths out the erratic edges of any single tree. The forest's bias is roughly that of a deep tree, and its variance is pushed down by averaging.

The survey's central observation is that the randomness does two jobs. Resampling makes trees differ, and feature selection decorrelates them. Both reduce the variance of the average, but both also change the bias, so the theory has to track each one.

The method

The forest estimate

Write the training sample as Dn=((X1,Y1),…,(Xn,Yn))\mathcal{D}_n = ((\mathbf{X}_1, Y_1), \dots, (\mathbf{X}_n, Y_n)), where each Xi\mathbf{X}_i is a vector of pp features and each YiY_i is a real response. The goal is to estimate the regression function m(x)=E[Y∣X=x]m(\mathbf{x}) = \mathbb{E}[Y \mid \mathbf{X} = \mathbf{x}], the Conditional Expectation of the response given the features. This is the best prediction under squared error, as the survey notes.

Each tree jj uses an independent random variable Θj\Theta_j that controls both the resampling and the feature choices. The tree's prediction at x\mathbf{x} is

mn(x;Θj,Dn)=∑i∈Dn⋆(Θj)1Xi∈An(x;Θj) YiNn(x;Θj)m_n(\mathbf{x}; \Theta_j, \mathcal{D}_n) = \sum_{i \in \mathcal{D}_n^{\star}(\Theta_j)} \frac{\mathbf{1}_{\mathbf{X}_i \in A_n(\mathbf{x}; \Theta_j)}\, Y_i}{N_n(\mathbf{x}; \Theta_j)}

Here Dn⋆(Θj)\mathcal{D}_n^{\star}(\Theta_j) is the set of resampled points, An(x;Θj)A_n(\mathbf{x}; \Theta_j) is the cell of the tree that contains x\mathbf{x}, and NnN_n counts the resampled points in that cell. The indicator 1\mathbf{1} equals one when the condition holds and zero otherwise. So the tree averages the responses of the points that share its cell with x\mathbf{x}.

The forest averages MM trees:

mM,n(x)=1M∑j=1Mmn(x;Θj,Dn)m_{M,n}(\mathbf{x}) = \frac{1}{M} \sum_{j=1}^{M} m_n(\mathbf{x}; \Theta_j, \mathcal{D}_n)

Letting MM grow without limit gives the infinite forest, which averages over Θ\Theta itself. The law of large numbers justifies this step: the finite forest converges to the infinite one as MM grows, given the data. The R package randomForest uses M=500M = 500 trees by default.

Breiman's algorithm

The survey gives three parameters and the default values in the R package for regression.

  1. ana_n, the number of points drawn for each tree. The default is an=na_n = n, drawn with replacement, which is bootstrap sampling. Bagging is this same idea applied to any model.
  2. mtry\texttt{mtry}, the number of features considered at each split. Each split picks mtry\texttt{mtry} features at random and searches only those. The default is ⌈p/3⌉\lceil p/3 \rceil for regression.
  3. nodesize\texttt{nodesize}, the size below which a cell is not split. The default is 5 for regression. Trees are not pruned.

At each cell, the tree tries every cut position on the chosen features and keeps the best one. The split score is the CART criterion of Breiman and colleagues. It measures the drop in variance of the response caused by the cut. The survey points out that this is the one part of the algorithm the theory has trouble with, because the best cut depends on the data in a way that resists analysis.

Out-of-bag error

Each bootstrap sample leaves some points out. Those points were not used to grow that tree, so they form a test set for it. Averaging each point's prediction over only the trees that did not see it gives the out-of-bag error. It is a built-in estimate of test error that needs no validation split, which is why the default parameters can be checked without holding data back.

Consistency

The survey judges a regression estimate by whether it is consistent: its mean squared error goes to zero as nn grows. Breiman's forest is hard to analyse, so the theory is built on simpler models. The first is the centred forest. Each node picks a coordinate uniformly at random and splits the cell at its midpoint. The tree is grown to kk levels, so each leaf holds about n/2kn / 2^k points when the features are uniform. Averaging the responses in the leaf of x\mathbf{x} gives the estimate.

The survey cites results from Breiman (2004), Biau and colleagues (2008), and Scornet (2015) showing that the centred forest is consistent provided

k→∞andn2k→∞k \to \infty \qquad \text{and} \qquad \frac{n}{2^k} \to \infty

The first condition says the trees get finer, so the bias goes away. The second says each leaf keeps growing, so the average in each leaf becomes accurate. Both are needed. The natural choice k≈log⁡nk \approx \log n, which matches Breiman's advice not to prune, breaks the second condition, and the survey says so plainly.

Forests as nearest-neighbour averages

Some points in the training set are "layered nearest neighbours" of x\mathbf{x} if the box spanned by x\mathbf{x} and that point contains no other training point. If each leaf holds only one point and the trees ignore resampling, the forest estimate is a weighted average of the responses of the layered nearest neighbours of x\mathbf{x}, with weights that sum to one. Lin and Jeon (2006) pointed out this link. Under uniform features on a pp-dimensional cube, they show that the mean squared error of such estimates cannot shrink faster than order 1/(nmax⁡(log⁡n)p−1)1 / (n_{\max} (\log n)^{p-1}), where nmax⁡n_{\max} is the largest number of points in a leaf. The (log⁡n)p−1(\log n)^{p-1} factor is why such averages converge slowly in many dimensions. The exact weights of Breiman's own forest are unknown, so this connection gives a route to analysis rather than a full theory.

Results

The survey has no experiments of its own. Its results are theorems about simplified forests, and the paper states each with its assumptions.

  • Centred forests, sparse signal. If only ∣S∣|\mathcal{S}| of the pp features matter, and the forest splits on each relevant feature with probability about 1/∣S∣1/|\mathcal{S}|, then under a Lipschitz smoothness condition the squared error of the infinite forest is of order n−0.75/(∣S∣log⁡2+0.75)n^{-0.75 / (|\mathcal{S}| \log 2 + 0.75)}. The rate depends on ∣S∣|\mathcal{S}|, not on pp. The survey notes this is faster than the usual n−2/(p+2)n^{-2/(p+2)} whenever ∣S∣≤⌊0.54 p⌋|\mathcal{S}| \le \lfloor 0.54\, p \rfloor. The result assumes the forest finds the relevant features, which is a strong assumption.
  • Purely uniform forests, one feature. For p=1p = 1, the error of this model is of order n−2/3n^{-2/3} under a Lipschitz assumption. The survey notes this matches the best possible rate over Lipschitz functions, so no estimator can do better in that class.
  • Variance reduction. The survey explains that a single fully grown tree has high variance, and that averaging many randomised trees lowers it. For simplified forests this shows up as better rates than a single tree gets. The survey flags that the picture for Breiman's own forest is still incomplete.

The survey's main message from these results is that the forest's advantage over a single tree is mostly in the estimation error, while the approximation error comes from the tree's shape and is harder to reduce.

Why it mattered

Breiman's forests became a default method in applied statistics, in machine learning and in competitions. The survey documents their use in air-quality prediction, chemoinformatics, ecology, object recognition and bioinformatics. Its authors cite claims that ensembles of trees have been among the most successful general-purpose methods in practice, and they contrast this with how little is known about the mathematics.

The survey's value is in organising the theory. It separates what is proven for simplified forests from what is observed for the real algorithm, and it shows how each simplification changes the analysis. That map is what later theory work has built on.

Reading guide

Read the survey roughly in this order, with these prerequisites in hand. Section names are descriptive, so match them to the survey's headings.

  1. Introduction. Needs Random Forest and Ensemble Learning for the idea of averaging predictors, and Overfitting for why averaging helps.
  2. Basic principles of the forest estimate. Needs Conditional Expectation for the regression function, and Law of Large Numbers for the step to an infinite forest.
  3. Breiman's algorithm. Needs Bootstrap Sampling and Bagging for the resampling, and Decision Tree for cells and splits. Work the split criterion slowly.
  4. Classification. Needs Entropy only as background. The survey uses the Gini impurity here, which is the classification counterpart of the variance criterion.
  5. Parameter tuning. Needs Bias-Variance Tradeoff to see why more trees cannot overfit, and Overfitting for the out-of-bag estimate.
  6. Simplified models and consistency. Needs Statistical Consistency and Smooth Function for the Lipschitz condition. Read the centred-forest consistency result first.
  7. Forests and neighbours. Needs Local Linear Regression as a comparison point for local averaging. Read it for the link to nearest-neighbour estimates.
  8. Theory for Breiman's own forest. This covers the resampling and the splitting criterion, and builds on the simplified models, so read it last.

Check yourself

QuestionWhy does a random forest use random feature subsets at each split, in addition to resampling the data?Show answer
Resampling makes trees differ, but if one feature is very strong, every tree will split on it first and the trees stay correlated. Choosing only a random subset of features at each split lets other features get used, which decorrelates the trees. Averaging correlated trees removes less variance than averaging uncorrelated ones.
QuestionCompute the CART-style gain for a split. A node has 6 points with response class 1 and 4 with class 0. The split sends 5 points left, containing 4 of class 1 and 1 of class 0, and 5 points right, containing 2 of class 1 and 3 of class 0. What is the gain using p0 times p1?Show answer
Parent: p1 = 0.6, p0 = 0.4, product 0.24. Left: p1 = 0.8, p0 = 0.2, product 0.16. Right: p1 = 0.4, p0 = 0.6, product 0.24. Weighted children: 0.5 times 0.16 plus 0.5 times 0.24 = 0.20. Gain: 0.24 minus 0.20 = 0.04. The split is worth taking, since the gain is positive.
QuestionA forest of M trees has tree prediction variance sigma squared equal to 4 and pairwise correlation rho. What is the forest variance when rho is 0.25 and M is 100?Show answer
The formula is rho times sigma squared plus (1 minus rho) times sigma squared over M. That gives 0.25 times 4 plus 0.75 times 4 over 100, which is 1.00 plus 0.03, so 1.03. Most of the variance remains because the correlation is high. Adding more trees cannot push it below rho times sigma squared, which is 1.00 here.
QuestionWhy does the choice k equal log n, which matches Breiman's advice not to prune, fail the survey's consistency condition for centred forests?Show answer
The condition needs n divided by 2 to the k to go to infinity. With k of order log n, 2 to the k is of order n, so n divided by 2 to the k stays bounded. Each leaf then holds a bounded number of points and the leaf averages do not become accurate, so the proof does not cover this choice.
QuestionA bootstrap sample of size n is drawn with replacement. For large n, about what fraction of points are left out, and why does this matter?Show answer
Each draw misses a given point with probability 1 minus 1 over n. Over n draws the chance of missing it is (1 minus 1 over n) to the power n, which tends to 1 over e, about 0.368. This is the survey's "about one-third" in round terms. The left-out points form a test set for that tree, which gives the out-of-bag error.

Sources

Read the full paper

Gérard Biau, Erwan Scornet, 2016. arXiv:1511.05741