A random forest averages deep, unpruned trees grown on bootstrap samples, each split searching a random $m$ of the $p$ inputs. An average of $B$ trees, each with variance $\sigma^2$ and pairwise correlation $\rho$, has variance $\rho\sigma^2 + (1-\rho)\sigma^2/B$: more trees remove only resampling noise, and smaller $m$ lowers the floor $\rho\sigma^2$ at some cost in bias. On Friedman's problem (200 training sets of 200 cases), bagging's trees have $\rho = 0.112$ and the lowest test error, 5.98, comes at $m = 7$ of 10. On 569 breast cancer tumors a forest's 10-fold cross-validated accuracy is 0.961 against 0.923 for one tree, and its out-of-bag accuracy (0.965) needs no refitting. On the diabetes data a forest ($R^2$ 0.443) beats a pruned tree but not linear regression (0.484).
A single decision tree is easy to read but unreliable. Introduction to Decision Trees fitted depth-2 trees to 200 bootstrap samples of the same 569 breast cancer tumors and found five different measurements at the root, with the original tree's root question appearing in only 13 of them; two such trees disagreed on a median 6.3% of the diagnoses. That variability is the main reason a tree predicts new cases less well than it seems to fit its training data. A random forest grows hundreds of trees, each on a resampled copy of the data and each forced to vary its choices, and averages them. The result predicts better than any of its trees and is far more stable, at the price of the single readable tree.
The method is due to Breiman (2001), who combined two ideas: bagging, his own earlier method of averaging models fitted to bootstrap samples (Breiman, 1996a), and random selection of the inputs considered at each split, which he traces to Amit and Geman's (1997) search over random subsets of features at each node and to Ho's (1998) random subspace method, which gives each tree a random subset of the features. This article derives why the combination works, measures the quantities the derivation depends on, and shows how a forest estimates its own error without a test set.
Bagging in brief
Bagging, short for bootstrap aggregating, is a general way to reduce the variance of any unstable method, and the Ensemble Techniques topic treats it in full. Applied to trees it takes three steps (James, Witten, Hastie and Tibshirani, 2021, §8.2.1):
- Draw $B$ bootstrap samples from the $n$ training cases: each is $n$ cases drawn at random with replacement, so some cases appear more than once and others not at all (see The Bootstrap Method; The Plug-In Principle and Why the Bootstrap Works explains when resampling one sample imitates drawing new ones).
- Grow a tree on each sample. The trees are grown deep and not pruned, so each has low bias and high variance.
- Predict by averaging the $B$ trees' predictions for a regression problem, or by majority vote over their predicted classes for a classification problem.
On the breast cancer data, 10-fold cross-validated accuracy rises from 0.923 for one fully grown tree to 0.961 for an average of 500 bagged trees. The improvement comes from averaging, not from better trees: each bagged tree is grown by the same procedure as the single tree, on a resampled copy of the same data. How much averaging can achieve depends on how similar the trees are, and that is the question random forests address.
The variance of an average
Fix an input $x$ and consider the prediction $T_b$ that tree $b$ makes at $x$. Over the random draw of the training data and the bootstrap sample, $T_b$ is a random variable. All $B$ trees are produced by the same procedure, so they have the same distribution; write $\sigma^2$ for the variance of one tree's prediction and $\rho$ for the correlation between the predictions of any two different trees, so that their covariance is $\rho \sigma^2$. The forest predicts the average $\bar{T} = \frac{1}{B} \sum_{b=1}^{B} T_b$. Its variance is
$$\operatorname{Var}\bigl(\bar{T}\bigr) = \frac{1}{B^2} \operatorname{Var}\Bigl(\sum_{b=1}^{B} T_b\Bigr) = \frac{1}{B^2} \Bigl[\sum_{b} \operatorname{Var}(T_b) + \sum_{b \ne b'} \operatorname{Cov}(T_b, T_{b'})\Bigr].$$
There are $B$ variance terms, each $\sigma^2$, and $B(B-1)$ ordered pairs of different trees, each with covariance $\rho\sigma^2$. So
$$\operatorname{Var}\bigl(\bar{T}\bigr) = \frac{B\sigma^2 + B(B-1)\rho\sigma^2}{B^2} = \rho\,\sigma^2 + \frac{1 - \rho}{B}\,\sigma^2.$$
(Hastie, Tibshirani and Friedman, 2009, eq. 15.1, who leave the derivation as their Exercise 15.1.) When the trees are independent, $\rho = 0$ and the familiar result $\sigma^2 / B$ appears: averaging $B$ independent predictions divides the variance by $B$, the fact James et al. (2021, §8.2.1) use to motivate bagging. When they are correlated, only the second term shrinks as trees are added. The first term, $\rho\sigma^2$, does not depend on $B$ at all, and it is the variance of a forest with infinitely many trees.
Where the correlation comes from
The trees in a forest are not correlated because they influence each other; each is grown independently. They are correlated because they are grown from the same training data. Write $Z$ for the training set. Given $Z$, the only remaining randomness is the bootstrap sample and the forest's other random choices, which are drawn independently for each tree. Two facts then follow from conditioning on $Z$. By the law of total variance, the variance of one tree splits into
$$\sigma^2 = \operatorname{Var}_Z\bigl(\mathrm{E}[T_b \mid Z]\bigr) + \mathrm{E}_Z\bigl[\operatorname{Var}(T_b \mid Z)\bigr],$$
a part due to which training set was drawn and a part due to the resampling given the training set. And because two trees are independent given $Z$, their conditional covariance is zero, and the law of total covariance leaves only the covariance of their conditional means, which is the first part, since the two conditional means are the same function of $Z$:
$$\operatorname{Cov}(T_b, T_{b'}) = \operatorname{Var}_Z\bigl(\mathrm{E}[T_b \mid Z]\bigr), \qquad\text{so}\qquad \rho = \frac{\operatorname{Var}_Z\bigl(\mathrm{E}[T_b \mid Z]\bigr)}{\sigma^2}.$$
The floor $\rho\sigma^2$ is the variance that comes from the training data itself, the part that would remain even after averaging every possible bootstrap tree. Averaging removes the resampling noise, $(1 - \rho)\sigma^2$, at the rate $1/B$. To lower the floor, the trees have to depend less on the particular training set, or, put the other way, the randomization within the forest has to account for a larger share of each tree's variability. Hastie et al. (2009, §15.4.1) give the same decomposition, and warn that this $\rho$ is a correlation over draws of the training set, not the correlation between the fitted trees of one forest.
Why bagged trees are alike
Bagging leaves the floor high when a few inputs dominate. Every bagged tree searches all inputs for its root split and, on most bootstrap samples, finds the same strong input there; with the same root, the trees tend to share their next splits too, and their predictions move together. James et al. (2021, §8.2.2) describe exactly this case: with one very strong predictor, "most or all of the trees will use this strong predictor in the top split", the trees "will look quite similar to each other", and averaging highly correlated quantities "does not lead to as large of a reduction in variance".
The breast cancer data show it. In 500 bagged trees fitted to all 569 tumors, only five different measurements ever appear at the root, and worst perimeter alone accounts for 207 of the 500 roots. All five describe either the size of the nuclei or the concavity of their outlines.
The random forest
Breiman's (2001) change is small. Each tree is still grown on a bootstrap sample, deep and unpruned, but at every split the algorithm first draws a random subset of $m$ of the $p$ inputs and searches for the best split among those $m$ only. A fresh subset is drawn at each split. With $m = p$ the method is bagging. With smaller $m$, the strong input is not even available at most splits: on average a fraction $(p - m)/p$ of splits cannot consider it (James et al., 2021, §8.2.2), and other inputs get their turn.
For the breast cancer forest with $m = 5$ of the 30 measurements, the 500 roots use 19 different measurements, and the most common, worst perimeter, appears at only 72 of them. The individual trees are usually weaker than bagged trees, since many of their splits use a second-best input, but they are less alike; the measurements on Friedman's problem below put numbers on both effects. Whether the trade pays depends on the balance between the two effects, which the variance formula makes precise: lowering $\rho$ lowers the floor, while each tree's own error rises.
Breiman (2001) expressed the same balance in two bounds. For classification, the forest's generalization error is at most $\bar{\rho}(1 - s^2)/s^2$, where $s$ is the strength of the trees (how far, on average, the vote for the correct class exceeds the largest vote for any other class), assumed positive, and $\bar{\rho}$ is the mean correlation between trees. For regression, assuming each tree's predictions have the same mean as the outcome, the forest's mean squared error is at most $\bar{\rho}$ times the average error of a single tree, with $\bar{\rho}$ a weighted correlation between the trees' residuals (his Theorem 11.2). In both, accuracy needs strong trees and low correlation, and the randomization, in his words about regression (his §11), "needs to aim at low correlation" without costing too much strength.
Common choices of $m$ are about $\sqrt{p}$ for classification and $p/3$ for regression, the defaults of the R package randomForest (James et al., 2021, §8.3.3). Breiman (2001) found classification results "insensitive to the number of features selected to split each node", with one or two inputs often close to the best. Hastie et al. (2009, §15.3) give the same defaults as the inventors' recommendations and add that they "should be treated as tuning parameters". scikit-learn's RandomForestClassifier uses $\sqrt{p}$ by default, but RandomForestRegressor uses all $p$ inputs by default, which makes it bagging unless max_features is set; its documentation (version 1.9.1, checked 23 November 2026) says that "the default of 1.0 is equivalent to bagged trees".
Correlation and variance, measured
The quantities in the derivation can be measured directly when fresh training sets can be drawn at will. Friedman's (1991) first test problem, as used by Breiman (1996a) to evaluate bagging, has ten inputs, each uniform on $[0, 1]$, and the outcome
$$y = 10 \sin(\pi x_1 x_2) + 20 (x_3 - 0.5)^2 + 10 x_4 + 5 x_5 + \varepsilon, \qquad \varepsilon \sim N(0, 1),$$
so five inputs matter, in a mix of nonlinear, interacting and linear ways, and five are noise. For each of 200 independently drawn training sets of 200 cases, forests of $B = 100$ trees were grown for $m = 1, 2, 3, 5, 7$ and 10, and their predictions recorded at 500 fixed test points. Because the true function is known, each forest's expected squared error can be split into squared bias, variance and the noise variance of 1. The variance $\sigma^2$ of one tree, the correlation $\rho$ between two trees grown on the same training set, and the forest's variance are averaged over the test points. All 100 trees of every forest are used: at each test point the spread of the 100 trees within a forest, averaged over the training sets, estimates $\mathrm{E}_Z[\operatorname{Var}(T_b \mid Z)]$; the variance of the forest's average over the training sets, less that spread divided by $B$, estimates the covariance $\rho\sigma^2$; and $\sigma^2$ is their sum.
| $m$ | One tree's variance $\sigma^2$ | Correlation $\rho$ | Floor $\rho\sigma^2$ | Forest variance, 100 trees | 10 trees: measured | 10 trees: formula |
|---|---|---|---|---|---|---|
| 1 | 20.50 | 0.025 | 0.50 | 0.70 | 2.51 | 2.50 |
| 2 | 17.39 | 0.034 | 0.58 | 0.75 | 2.26 | 2.26 |
| 3 | 15.33 | 0.042 | 0.65 | 0.80 | 2.10 | 2.12 |
| 5 | 12.81 | 0.066 | 0.84 | 0.96 | 2.06 | 2.04 |
| 7 | 11.62 | 0.087 | 1.01 | 1.12 | 2.07 | 2.07 |
| 10 (bagging) | 10.86 | 0.112 | 1.22 | 1.32 | 2.22 | 2.18 |
With $\sigma^2$ and $\rho$ estimated this way, the formula $\rho\sigma^2 + (1-\rho)\sigma^2/B$ reproduces the variance of the 100-tree forests by construction, so it is checked on smaller forests instead: the averages of each forest's first 10 trees, whose variance the formula with $B = 10$ predicts to within 0.04 for every $m$. Three further observations follow.
The correlations are small, between 0.02 and 0.12, yet they dominate. With 100 trees in the bagged forest, the floor $\rho\sigma^2 = 1.22$ accounts for almost all of the forest variance of 1.32, and the resampling part, $(1-\rho)\sigma^2/B$, is the small remainder. Averaging has already cut the variance from 10.86 for one tree to 1.32, and adding trees cannot take it much lower. Only lowering $\rho$ can.
Smaller $m$ lowers the correlation, from 0.112 for bagging to 0.025 for $m = 1$, and with it the forest's variance, from 1.32 to 0.70. But it raises the bias, because a tree that may only split on a randomly chosen input often splits on one of the five useless ones. At $m = 1$ the squared bias is 8.88, against 3.78 for bagging.
| $m$ | Squared bias | Forest variance | Test MSE |
|---|---|---|---|
| 1 | 8.88 | 0.70 | 10.59 |
| 2 | 6.04 | 0.75 | 7.79 |
| 3 | 4.91 | 0.80 | 6.70 |
| 5 | 4.07 | 0.96 | 6.03 |
| 7 | 3.86 | 1.12 | 5.98 |
| 10 (bagging) | 3.78 | 1.32 | 6.10 |
The two effects balance at an intermediate value. The expected test error is lowest at $m = 7$ (5.98), close for $m = 5$ (6.03) and bagging (6.10), and much worse for $m = 1$ (10.59). In this problem, with half the inputs irrelevant, a large $m$ is needed so that most splits can find a relevant input, which matches Breiman's (2001, §12) observation that regression forests need a relatively large number of features per split (in his experiments each feature was a random linear combination of two inputs). Every forest is far better than a single tree, whose expected test error ranges from 15.64 to 30.38.
More trees do not overfit
The number of trees $B$ is not a tuning parameter in the usual sense. Breiman (2001, Theorem 1.2) showed, using the strong law of large numbers, that as trees are added the forest's generalization error converges to a limit, and drew the conclusion that random forests "do not overfit as more trees are added, but produce a limiting value of the generalization error". The forest can still overfit in the ordinary sense, through deep trees fitting noise, but adding trees only moves it closer to the infinite forest. James et al. (2021, §8.2.1) give the practical rule: use a value of $B$ large enough that the error has settled down.
On a held-out set of 171 tumors (30% of the data, stratified), a single fully grown tree makes 16 errors, an error rate of 0.094. With 500 trees, bagging makes 12 errors (0.070) and the random forest 8 (0.047). A test set of 171 cases cannot separate the two ensembles reliably: with 10-fold cross-validation on all 569 tumors both reach an accuracy of 0.961. For these data the gain comes from averaging, and decorrelation adds little, consistent with Breiman's finding that classification error is insensitive to $m$. Out-of-bag error for forests with $m$ = 1, 2, 3, 5, 8, 12, 20 and 30, averaged over three seeds each, lies between 0.034 and 0.041.
Out-of-bag error
A bootstrap sample of size $n$ is drawn by $n$ independent draws, each picking any particular case with probability $1/n$. A given case is missed by one draw with probability $1 - 1/n$, so it is missed by all $n$ draws, and left out of the sample, with probability
$$\Bigl(1 - \frac{1}{n}\Bigr)^n \to e^{-1} \approx 0.368 \quad\text{as } n \to \infty$$
which is why Breiman (1996b) describes each bootstrap sample as leaving out "about 37%" of the cases. The limit is reached quickly: the probability is 0.3487 for $n = 10$ and 0.3676 for $n = 569$. So each tree is grown on about 63% of the distinct cases, and the remaining 37% are its out-of-bag (OOB) cases, which it has never seen.
That gives a forest a built-in test set. For each training case, collect the predictions of only those trees for which it was out of bag, and combine them by averaging or by vote; this is the case's OOB prediction. The OOB error is the error of these predictions over all $n$ cases (Breiman, 1996b; James et al., 2021, §8.2.1). Each prediction comes from trees that did not see the case, so the OOB error is an honest estimate of the error on new data, obtained at no extra computing cost. In the 500-tree forest on all 569 tumors, each tumor is out of bag for 183.5 trees on average (between 149 and 224), a share of 0.367.
Two cautions come from Breiman (2001). The OOB prediction for a case uses only about a third of the trees, so with few trees it is the prediction of a smaller and weaker forest, and the OOB error "will tend to overestimate the current error rate"; the figure shows this at the left, where with 5 trees the forest's OOB error is 0.126 against a test error of 0.058 (Problem 1 takes this number apart). With enough trees the bias disappears, and James et al. (2021, §8.2.1) note that for large $B$ the OOB error is "virtually equivalent" to leave-one-out cross-validation. On the breast cancer data the forest's OOB accuracy, 0.965, is close to its 10-fold cross-validated accuracy, 0.961, which required fitting ten forests rather than one.
The OOB error makes tuning cheap. Choosing $m$ for the breast cancer forest by OOB error, as above, takes one forest per candidate value instead of ten.
Which inputs matter?
A forest of 500 trees cannot be read, but it can be summarized. Two measures of variable importance are standard.
Mean decrease in impurity adds up, for each input, the reduction in the Gini index (for classification) or RSS (for regression) produced by every split on that input, weighted by the cases reaching the split, and averages over the trees (James et al., 2021, §8.2.1). It is a by-product of growing the forest and costs nothing. Because it is computed on the training data from the splits the trees chose, it measures how much each input was used, which is not quite the same as how much it helps prediction.
Permutation importance measures prediction directly (Breiman, 2001, §10): shuffle the values of one input among the cases of a test set (or the OOB cases), breaking its link with the outcome while keeping its distribution, and record how much the forest's accuracy drops. An input the forest relies on causes a large drop; an irrelevant one causes none.
For the breast cancer forest the impurity measure ranks worst perimeter first (0.151), followed by worst radius, worst concave points, worst area and mean concave points. Permutation on the held-out tumors ranks worst radius first (a drop in accuracy of 0.021), then worst area and worst concave points, and puts worst perimeter only fifth. Worst perimeter, worst radius and worst area measure nearly the same thing, so the forest can substitute one for another: shuffling any one of them costs little because the others remain, while the impurity measure divides credit among them according to which happened to be chosen. Correlated inputs share importance under either measure, and neither measure says that an input causes the outcome. Problem 3 shuffles the three size measurements together and finds a drop seven times larger than any one of them causes alone. Features for ranking proves that a tree's split gains add up to the squared error it removes, and measures both kinds of importance for a learned ranker. Worst texture shows the opposite discrepancy. It is rarely chosen for splits, ranking 13th of 30 by impurity, but when it is shuffled accuracy drops by 0.016, the fourth largest drop: it carries information that the size and shape measurements do not.
Random forests for regression
On the diabetes data used throughout the regression articles, 10-fold cross-validated $R^2$ (with the folds of Multiple Linear Regression) is 0.419 for bagging ($m = 10$), 0.443 for a random forest with $m = 3$, about $p/3$, and 0.435 with $m = 1$. All three improve substantially on the best pruned regression tree, 0.332 (see Regression Trees). None matches a linear regression on the ten inputs, 0.484. A forest averages step functions, and when the true relationship is close to a sum of straight-line effects, as it appears to be here, a linear model estimates it more efficiently from 442 cases. A random forest is a strong general-purpose method, not a guaranteed improvement over a well-chosen simpler model, and comparing the two by cross-validation is part of the job (see Model Selection).
The OOB $R^2$ values (0.425, 0.453 and 0.445 for $m = 10$, 3 and 1) are close to the cross-validated ones and rank the three forests the same way.
Strengths and costs
A random forest keeps most of what makes trees convenient: no scaling of inputs, natural handling of interactions and of several classes, and few assumptions about the form of the relationship. It adds stability and accuracy, works well with default settings, gives an error estimate for free, and grows its trees independently, so they can be built in parallel. Breiman (2001) also reported that forests were "relatively robust to outliers and noise".
The costs are the loss of the single interpretable tree, a model that is large to store and slower to evaluate (500 trees of about 21 leaves each for the breast cancer forest, against one tree of 22), and the limitations it inherits from trees: like every tree, a forest predicts a constant beyond the range of its training data, and a forest of deep trees can still fit noise in small datasets. The main alternative ensemble of trees is Boosting, which grows trees in sequence, each correcting the errors of those before, rather than independently. The library note Using Claude Science to Produce the First Complete Map of the Sky in UV Light describes such an ensemble of small regression trees in use, predicting the unmeasured pixels of an ultraviolet sky map from 90 features and validated by spatial cross-validation.
Worked problems
These problems were written for this article. The script tools/experiments/data-science/random-forests.py computes every number in them and asserts it, in its review block.
Problem 1 (how many trees vote for a case out of bag). Derive the distribution of the number of trees for which a given case is out of bag, check it on the 500-tree forest, and use it to explain why the out-of-bag error of the 5-tree forest in the figure, 0.126, is so far above its test error.
Solution. Each tree draws its own bootstrap sample, independently of the others, and leaves a given case out with probability $q = (1 - 1/n)^n$, derived above. The number of trees for which the case is out of bag is therefore a sum of $B$ independent indicators, each 1 with probability $q$, which is the binomial distribution with mean $Bq$ and standard deviation $\sqrt{Bq(1 - q)}$. For the 500-tree forest on all 569 tumors, $q = 0.3676$, so a tumor should be out of bag for 183.8 trees on average with a standard deviation of 10.8. The forest's tumors averaged 183.5, and the extremes, 149 and 224, lie 3.2 standard deviations below and 3.7 above the mean. The spread of the counts across this forest's tumors, 9.9, is below the binomial 10.8 by chance. Recounting with the bootstrap samples of forests with seeds 0 to 39 (seed 0 is this forest) gives spreads from 9.9 to 11.5 with a median of 10.8, so this forest has the smallest of the forty. The counts of different tumors are slightly dependent, since a bootstrap sample of fixed size that includes one tumor more often leaves fewer draws for the rest, but the covariance is only about $-0.12$ per pair of tumors over 500 trees, which raises the expected spread by less than 0.01.
With few trees the same distribution has a large mass at 0 and 1. For the 398 training tumors ($q$ now computed with $n = 398$) and $B = 5$, a tumor has no out-of-bag tree with probability $(1 - q)^5 = 0.1013$, about 40 tumors in expectation; in the figure's 5-tree forest it was 36, and another 262 had only one or two. The out-of-bag "forest" for most cases is then a single tree or a pair, which is Breiman's caution in its extreme form. One more detail of the software inflates the number further. scikit-learn 1.6.1 gives a case with no out-of-bag tree an all-zero vote, warns that "Some inputs do not have OOB scores", and scores the case anyway with the first class, malignant. Of the 36 unscored tumors, 22 are benign, and they account for 22 of the 5-tree forest's 50 out-of-bag errors. On the 362 tumors that had at least one out-of-bag tree the error is 0.077, still above the test error of 0.058 for the ordinary reason, that most of those votes come from one or two trees. With 25 trees the chance that a tumor has no out-of-bag tree is about one in 94,000, and the problem is gone.
Problem 2 (how many trees are enough?). Using the measured $\rho$ and $\sigma^2$ on Friedman's problem, find how many trees bring a forest's variance within 5% of its floor $\rho\sigma^2$, and say what changes in the comparison of $m$ when the number of trees is unlimited.
Solution. The forest's variance exceeds the floor by the resampling part $(1 - \rho)\sigma^2/B$. Requiring it to be at most a share $r$ of the floor gives
$$\frac{(1 - \rho)\sigma^2}{B} \le r\,\rho\sigma^2 \quad\Longleftrightarrow\quad B \ge \frac{1 - \rho}{r\,\rho},$$
which depends on $\rho$ alone; $B$ is the smallest whole number satisfying it. With $r = 0.05$, bagging ($\rho = 0.112$) needs 158 trees, while $m = 1$ ($\rho = 0.025$) needs 792. These counts are only as precise as $\rho$: an estimate of $\rho$ from 10 pairs of trees per training set, used in a first version of this article, gave 0.022 for $m = 1$ and 873 trees. The less correlated the trees, the more of them a forest needs to reach its own floor, because the floor is lower and the resampling noise each tree carries is larger. At the $B = 100$ of the experiment, the resampling part is 0.08 of the floor for bagging and 0.40 of it for $m = 1$ (0.200 against 0.50), which is why the $m = 1$ forest's variance, 0.70, sits well above its floor.
So the experiment's comparison at 100 trees slightly handicaps small $m$. With infinitely many trees each forest's variance falls to its floor, and its squared bias does not change, because the expected prediction of the average is the expected prediction of one tree. The expected test errors become 10.39, 7.62, 6.56, 5.91, 5.88 and 6.00 for $m$ = 1, 2, 3, 5, 7 and 10. The ranking is the same as at 100 trees and $m = 1$ is still far worst. The gap between $m = 5$ and $m = 7$ shrinks to 0.035; a bootstrap over the 200 training sets gives it a standard error of 0.014, so $m = 7$ is probably better on this problem, by a margin of about 0.6% of its error.
Problem 3 (permuting correlated inputs together). Shuffling worst radius, worst perimeter or worst area alone costs the forest little accuracy. What does shuffling all three together cost, and what does that say about the permutation measure?
Solution. Permute the rows of the 171 test tumors once and apply the same permutation to all three columns, so that each tumor's three size measurements stay consistent with each other but no longer belong to it. Over 10 permutations (the script's own, so the single-input values differ slightly from those of the figure), the mean drop in test accuracy is 0.0234 for worst radius alone, 0.0146 for worst perimeter and 0.0211 for worst area, but 0.1749 for the three together, seven and a half times the largest single drop. With one size measurement shuffled, the forest reads the size from the other two. With all three shuffled, the size information is gone.
Permutation importance therefore measures what the forest loses when one input is broken and the others are intact. It does not measure how much the information an input carries matters, when other inputs carry the same information. Shuffling correlated inputs one at a time understates the importance of the group they form; shuffling them as a group, or reading the importances of a group together, answers the other question. Shuffling a single input also breaks its link with the inputs it is correlated with, and creates combinations of values, a large radius with a small area, that never occur in the data, and the drop partly reflects how the forest extrapolates to them.
Open questions
- Is impurity importance biased toward inputs with many split points here? Strobl, Boulesteix, Zeileis and Hothorn (2007) showed that impurity-based importance favors inputs with more possible splits. Adding to the breast cancer data noise inputs with 2, 10 and 500 distinct values, over 30 seeds, and recording the importance each receives by impurity and by permutation would measure the bias on these data.
- How should importance be shared among correlated inputs? Problem 3 shows the group of three size measurements matters far more than any one of them. Comparing grouped permutation, permutation conditional on the other inputs, and dropping a column and refitting, on the same split, would show which of them separates the size group from the shape group most clearly.
- How uncertain is a forest's prediction? The forest reports no standard error. The infinitesimal jackknife that Wager, Hastie and Efron (2014) apply to random forests (The Jackknife) could be computed for the diabetes forest and checked against the spread of predictions over bootstrap resamples of the 442 patients.
Where it leads
A random forest averages deep trees grown on bootstrap samples with a random choice of inputs at each split. Its variance is $\rho\sigma^2 + (1 - \rho)\sigma^2/B$, so averaging removes the resampling noise and decorrelation lowers the floor, at some cost in bias; on Friedman's problem the best balance was seven of ten inputs per split, and on the breast cancer data every $m$ did about equally well. The out-of-bag error gives the estimate of new-case error at no extra cost once there are enough trees. This closes the unit Tree Models in Practice. The Ensemble Techniques section of the collection takes up averaging and its alternative for any method: Bagging treats bootstrap aggregation in general, and Boosting grows trees in sequence, each correcting the errors of those before, which reduces bias rather than variance. The theory of what a training error says about new cases is in the Statistics unit Statistical Learning Theory, and Prediction Error and Model Choice proves what the cross-validation used throughout this unit estimates.
In Python
from sklearn.datasets import load_breast_cancer
from sklearn.ensemble import RandomForestClassifier
from sklearn.inspection import permutation_importance
from sklearn.model_selection import train_test_split
data = load_breast_cancer()
X_train, X_test, y_train, y_test = train_test_split(
data.data, data.target, test_size=0.3, stratify=data.target, random_state=0)
forest = RandomForestClassifier(n_estimators=500, max_features="sqrt",
oob_score=True, random_state=0, n_jobs=-1)
forest.fit(X_train, y_train)
print(1 - forest.oob_score_) # out-of-bag error estimate
print(1 - forest.score(X_test, y_test)) # test error: 0.047, 8 of 171
perm = permutation_importance(forest, X_test, y_test, n_repeats=10, random_state=0)
for i in perm.importances_mean.argsort()[::-1][:5]:
print(data.feature_names[i], round(perm.importances_mean[i], 4))
max_features is $m$; max_features=None gives bagging. oob_score=True computes the out-of-bag estimate during fitting. feature_importances_ holds the impurity-based importances. The code was run with scikit-learn 1.6.1; the classes and parameters it uses are unchanged in the 1.9.1 documentation (checked 23 November 2026). For regression, RandomForestRegressor has the same interface, but set max_features explicitly, since its default uses all inputs. The numbers in this article are computed by tools/experiments/data-science/random-forests.py in the site's repository.
References
- Amit, Y., and Geman, D. (1997). Shape quantization and recognition with randomized trees. Neural Computation, 9(7), 1545–1588. record
- Breiman, L. (1996a). Bagging predictors. Machine Learning, 24(2), 123–140. record · 4 pages
- Breiman, L. (1996b). Out-of-bag estimation [Technical report]. Department of Statistics, University of California, Berkeley. record
- Breiman, L. (2001). Random forests. Machine Learning, 45(1), 5–32. record · 3 pages
- Friedman, J. H. (1991). Multivariate adaptive regression splines. The Annals of Statistics, 19(1), 1–67. record · 5 pages
- Hastie, T., Tibshirani, R., and Friedman, J. (2009). The Elements of Statistical Learning (2nd ed.). Springer. record · 39 pages
- Ho, T. K. (1998). The random subspace method for constructing decision forests. IEEE Transactions on Pattern Analysis and Machine Intelligence, 20(8), 832–844. record
- James, G., Witten, D., Hastie, T., and Tibshirani, R. (2021). An Introduction to Statistical Learning with Applications in R (2nd ed.). Springer. record · 39 pages
- Strobl, C., Boulesteix, A.-L., Zeileis, A., and Hothorn, T. (2007). Bias in random forest variable importance measures: Illustrations, sources and a solution. BMC Bioinformatics, 8, 25. record
- Wager, S., Hastie, T., and Efron, B. (2014). Confidence intervals for random forests: The jackknife and the infinitesimal jackknife. Journal of Machine Learning Research, 15, 1625–1651. record · 2 pages
- Wolberg, W., Mangasarian, O., Street, N., and Street, W. (1993). Breast Cancer Wisconsin (Diagnostic) [Data set]. UCI Machine Learning Repository. https://doi.org/10.24432/C5DW2B record · 15 pages
Reviewed: verified, 23 Nov 2026 · citations checked, 23 Nov 2026 · editorial review, 23 Nov 2026 · 9 revisions