Tutorials › Exam PA - Predictive Analytics › Why Bagging Reduces Prediction Variance

Exam PA · Random Forests and Ensemble Behavior · Tutorial 522 of 966

Why Bagging Reduces Prediction Variance

Learn why averaging tree predictions reduces variance, how imperfect correlation limits that reduction, and when the usual variance formula applies.

Advanced 12 min read

What You'll Learn

  • Define the prediction variance being studied and the randomness over which it is calculated
  • Derive the variance of an average of equally variable, equicorrelated tree predictions
  • Calculate how ensemble size and tree-error correlation affect variance
  • Distinguish variance reduction from bias reduction and irreducible outcome noise
  • Recognize when conditional independence of bootstrap fits changes the calculation
  • Avoid applying the regression averaging formula directly to hard class votes

Why Average Predictions From Many Trees?

A fitted tree can change substantially when its training data change. A small change in the data may alter a split, which changes the observations in descendant nodes and can lead to different predictions. This sensitivity is one reason an individual tree can have high prediction variance. Bagging addresses it by fitting trees to bootstrap samples and averaging their predictions.

The key qualification is that the trees must not make exactly the same prediction errors. If each tree repeats the same error, averaging leaves that error unchanged. If their errors vary and are not perfectly aligned, averaging can make the ensemble prediction more stable. The reduction depends both on the number of trees and on how strongly their prediction errors move together.

Definition: At a fixed predictor value \(x\), let \(\hat f_b(x)\) be the prediction from tree \(b\), for \(b=1,\ldots,B\). The bagged prediction for a regression target is \(\bar f_B(x)=\frac{1}{B}\sum_{b=1}^B\hat f_b(x)\). Prediction variance means the variance of these predictions over a stated source of randomness, such as repeated training samples or repeated bootstrap fitting. The source of randomness must be clear when interpreting the variance.

For the usual variance calculation, assume the \(B\) tree predictions at \(x\) have a common variance \(\sigma^2\), and every distinct pair has the same correlation \(\rho\). These are simplifying assumptions, not requirements of bagging itself. They let us isolate the effect of averaging. In applications, tree variances and pairwise correlations need not be identical.

The correlation here is the correlation between prediction errors across repeated fits, at the same \(x\). It is not the correlation between two predictors in the data, nor the correlation between predictions at two different values of \(x\). If the trees have a common mean prediction, correlating their predictions is equivalent to correlating their centered prediction errors.

The Variance of an Average

The general variance identity for a sum includes both each prediction’s variance and every pairwise covariance. Under the equal-variance, equal-correlation assumptions, each pair has covariance \(\rho\sigma^2\). Dividing the sum by \(B\) gives the variance of the average:

$$ \begin{aligned} \operatorname{Var}\!\left(\bar f_B(x)\right) &=\operatorname{Var}\!\left(\frac{1}{B}\sum_{b=1}^{B}\hat f_b(x)\right)\\ &=\frac{1}{B^2}\left(B\sigma^2+B(B-1)\rho\sigma^2\right)\\ &=\sigma^2\left(\rho+\frac{1-\rho}{B}\right). \end{aligned} $$

The first term inside the parentheses, \(\rho\), represents the variance that averaging cannot remove under this model. The second term, \((1-\rho)/B\), shrinks as the number of trees increases. A single tree has variance \(\sigma^2\); for \(B>1\), the ensemble variance is smaller when \(\rho<1\). When \(\rho=1\), the trees move together perfectly, so the average has the same variance as one tree.

For a valid equal-correlation covariance structure, \(\rho\) cannot be arbitrary: it must satisfy \(-1/(B-1)\leq \rho\leq 1\). In common tree-ensemble settings, the correlation is typically nonnegative. With \(\rho=0\), the formula reduces to \(\sigma^2/B\), the variance of an average of independent, equally variable predictions.

Key result: With \(B\) equally variable tree predictions and common pairwise correlation \(\rho\), the variance of their average is \(\sigma^2\left(\rho+\frac{1-\rho}{B}\right)\). Increasing \(B\) reduces the second term, but does not eliminate the \(\rho\sigma^2\) term when \(\rho>0\).

Why the Formula Holds

The derivation follows from expanding the variance of a sum. For any random variables \(Z_1,\ldots,Z_B\),

$$ \operatorname{Var}\!\left(\sum_{b=1}^{B}Z_b\right) =\sum_{b=1}^{B}\operatorname{Var}(Z_b) +2\sum_{1\leq b<c\leq B}\operatorname{Cov}(Z_b,Z_c). $$

There are \(B\) individual variance terms, each equal to \(\sigma^2\). There are \(B(B-1)/2\) distinct pairs, each with covariance \(\rho\sigma^2\); the factor of 2 in the identity counts each pair in both orders. Thus the covariance contribution is \(B(B-1)\rho\sigma^2\). Since the ensemble prediction divides the sum by \(B\), its variance divides by \(B^2\). Combining those terms yields the displayed result. This argument depends on the equal-variance and equal-correlation assumptions; without them, retain the individual variances and covariances rather than using the simplified expression.

Worked Calculations

Worked Example: Four Trees With Positive Correlation

At one fixed risk profile, suppose four regression trees have prediction variance \(25\) (in squared prediction units) over repeated training samples. Their prediction errors have common pairwise correlation \(0.20\). Find the variance of their average prediction and compare it with the variance of one tree.

Method. Use the equal-variance, equal-correlation formula with \(B=4\), \(\sigma^2=25\), and \(\rho=0.20\):

$$ \begin{aligned} \operatorname{Var}(\bar f_4(x)) &=25\left(0.20+\frac{1-0.20}{4}\right)\\ &=25\left(0.20+\frac{0.80}{4}\right)\\ &=25(0.20+0.20)\\ &=25(0.40)=10. \end{aligned} $$

The variance falls from \(25\) for one tree to \(10\) for the average. The reduction is \(25-10=15\), or \(15/25=0.60\), which is a 60% reduction in variance. The standard deviation of one tree is \(\sqrt{25}=5\); that of the average is \(\sqrt{10}\approx3.1623\) prediction units.

Check. The equivalent covariance calculation gives \(4(25)+4(3)(0.20)(25)=100+60=160\) for the variance of the sum. Dividing by \(4^2=16\) gives \(160/16=10\). The common mistake is to assume independence and report \(25/4=6.25\); that ignores the positive covariance between tree errors and understates the ensemble variance.

Worked Example: More Trees Do Not Remove Shared Variation

A collection of regression trees has individual prediction variance \(16\) and common pairwise error correlation \(0.25\) at a particular profile. Calculate the ensemble variance for \(B=9\). Then find the limiting variance as the number of trees grows without bound under the same assumptions.

For nine trees, substitute \(B=9\), \(\sigma^2=16\), and \(\rho=0.25\):

$$ \begin{aligned} \operatorname{Var}(\bar f_9(x)) &=16\left(0.25+\frac{1-0.25}{9}\right)\\ &=16\left(0.25+\frac{0.75}{9}\right)\\ &=16(0.25+0.083333\ldots)\\ &=16\left(\frac{1}{3}\right)=\frac{16}{3}\approx5.3333. \end{aligned} $$

As \(B\) grows, \((1-\rho)/B\) tends to zero. The limiting variance is therefore \(16(0.25)=4\), not zero. The nine-tree variance, approximately \(5.3333\), is above that limit by \(5.3333-4=1.3333\). Adding trees can reduce the part due to finite ensemble size, but cannot remove the shared component represented by positive correlation.

Check. The result is less than the single-tree variance of \(16\) and greater than the limiting value of \(4\), as expected. The common mistake is to conclude that indefinitely many trees must give zero variance. That conclusion would require \(\rho=0\); here the nonzero correlation leaves a positive floor.

Worked Example: Lower Variance Does Not Guarantee Lower Prediction Error

At a hypothetical customer profile, the target conditional mean is \(100\). A single tree’s predictions have mean \(104\) and variance \(36\). Suppose four trees have the same mean and variance, and their pairwise error correlation is \(1/6\). Find the mean squared error for estimating the target conditional mean using one tree and using the four-tree average.

Method. For an estimator \(\hat f(x)\) of a fixed target \(m(x)\), its mean squared error is \(\operatorname{Var}(\hat f(x))+\{\operatorname{E}[\hat f(x)]-m(x)\}^2\). The squared bias is needed as well as the variance.

For one tree, the bias is \(104-100=4\), so the squared bias is \(4^2=16\). Its mean squared error is \(36+16=52\).

For the average of four trees, first calculate its variance:

$$ \begin{aligned} \operatorname{Var}(\bar f_4(x)) &=36\left(\frac{1}{6}+\frac{1-\frac{1}{6}}{4}\right)\\ &=36\left(\frac{1}{6}+\frac{5}{24}\right)\\ &=36\left(\frac{4}{24}+\frac{5}{24}\right)\\ &=36\left(\frac{3}{8}\right)=13.5. \end{aligned} $$

The mean of the average remains \(104\), because averaging four predictions with mean \(104\) still has mean \(104\). Its bias is therefore \(4\), and its squared bias remains \(16\). The ensemble mean squared error is \(13.5+16=29.5\), lower than the single-tree value \(52\). The variance reduction improves mean squared error here, but it does not correct the bias.

Check. The ensemble variance \(13.5\) is below \(36\), and the unchanged squared bias \(16\) is added once, not divided by four. The common mistake is to assume that averaging necessarily removes systematic prediction error; under these assumptions, the mean prediction stays \(104\), four units above the target.

What Bagging Does and Does Not Reduce

A bootstrap sample is formed by drawing observations with replacement from the available training data. Fitting a tree to each resample creates a collection of predictions that can differ at the same \(x\). Averaging those predictions smooths some of the variation across fits. The formula explains why the gain depends on both the variability of individual trees and their error correlation.

Be precise about the source of randomness. If the original training data are held fixed and each tree is fitted using an independently generated bootstrap resample, then, for a deterministic fitting procedure, the fits are independent conditional on those fixed data. Under that conditional calculation, their covariance is zero and the bootstrap-randomness component of the average’s variance is \(\sigma^2/B\). Across repeated original training samples, however, all bootstrap fits are built from data that share the same original sample. Their predictions can consequently be correlated. The variance identity applies to whichever randomness is being analyzed, but the variance and correlation must be defined over that same distribution of repeated fits.

Bagging directly changes the variability of the prediction by averaging. It does not, by averaging alone, guarantee that the expected prediction is closer to the target. If every tree has the same bias, the averaged prediction retains it. For a future response \(Y\), outcome noise also remains: even a prediction exactly equal to the conditional mean \(m(x)=\operatorname{E}[Y\mid X=x]\) cannot predict the random deviation of that future outcome from its mean. These are distinct contributions from the variance of fitted predictions.

The displayed formula concerns an arithmetic average of numerical predictions, as used for regression predictions or estimated class probabilities. It is not automatically a formula for the class label produced by majority vote. Converting probabilities or numerical predictions into a class label is a nonlinear operation, so the variance of the average does not directly give the error rate of that vote.

Common Exam Traps

  • Assuming independence without being told to. The shortcut \(\sigma^2/B\) applies when the pairwise covariances are zero. With positive correlation, use \(\sigma^2\left(\rho+\frac{1-\rho}{B}\right)\).
  • Dividing the correlation term by the number of trees. The shared component is \(\rho\sigma^2\), not \(\rho\sigma^2/B\). It remains in the limit as \(B\) increases.
  • Confusing a variance reduction with a bias reduction. The variance formula alone does not say how close the expected prediction is to the target. For mean squared error, include squared bias.
  • Leaving the randomness unspecified. State whether variance is across repeated training sets, bootstrap fits conditional on a fixed data set, or some other repeated-fitting procedure. The relevant covariance depends on that choice.
  • Using the result for hard class labels without qualification. The formula is for averages of numerical predictions under its assumptions, not directly for majority-vote classification error.
Key takeaway: Averaging reduces the variable part of tree predictions when their errors are not perfectly correlated. With common pairwise correlation \(\rho\), the variance approaches \(\rho\sigma^2\) as the ensemble grows; adding trees cannot remove shared variation or guarantee removal of bias.

Check Your Understanding

For each problem, use the stated variance assumptions and show how the number of trees and correlation enter the calculation.

  1. Five tree predictions have variance \(20\) and zero pairwise correlation. Find the variance of their average. (Answer: \(4\))
  2. Six tree predictions have variance \(12\) and common pairwise correlation \(0.40\). Find the variance of their average. (Answer: \(6\))
  3. Ten tree predictions have variance \(9\) and common pairwise correlation \(0.25\). Find the variance of their average. (Answer: \(2.925\))
  4. Four tree predictions have variance \(8\) and common pairwise correlation \(0.50\). Find the ensemble variance and the percentage reduction from one tree’s variance. (Answer: variance \(5\); reduction \(37.5\%\))
  5. Tree predictions have variance \(20\) and common pairwise correlation \(0.10\). What is the smallest integer number of trees for which the ensemble variance is at most \(6\)? (Answer: \(5\) trees)
Clinical Biostats