Tutorials › Exam SRM - Statistics for Risk Modeling › Choosing The Number Of Trees By OOB Convergence

Exam SRM · Bagging and Random Forests · Tutorial 621 of 926

Choosing The Number Of Trees By OOB Convergence

Use OOB error trajectories, coverage checks, and an explicit stability rule to choose a practical random forest size.

Advanced 12 min read

What You'll Learn

  • Define OOB error at a tree-count checkpoint for classification and regression
  • Explain why OOB error can rise or fall when trees are added
  • Check OOB prediction coverage before comparing early checkpoints
  • Apply a stated plateau rule and verify every earlier candidate window
  • Choose an adequate tree count while accounting for metric choice and computation

Why Monitor OOB Error as a Forest Grows?

A random forest combines predictions from many trees. Increasing the number of trees can make the aggregate prediction more stable, but it does not guarantee that a particular measured error decreases at every step. An out-of-bag (OOB) error curve helps assess whether adding trees is still changing predictive performance enough to justify the additional computation.

The practical question is not simply, “Which tree count has the smallest observed OOB error?” Small ups and downs can reflect changes in the trees and OOB votes rather than a meaningful improvement or deterioration. A more defensible choice uses a stated stability rule, checks that OOB predictions have adequate coverage, and identifies the tree count at which the rule is first met.

Definition: At a checkpoint of \(B\) trees, an observation is OOB for a tree if it was not included in that tree’s bootstrap sample. Its OOB prediction is formed using only trees for which it was OOB. The OOB error at \(B\) is a chosen loss, averaged over observations with an available OOB prediction. For classification, a common loss is the proportion misclassified; for regression, a common loss is mean squared error (MSE).

For observation \(i\), let \(T_i(B)\) be the set of the first \(B\) trees for which \(i\) was OOB. In regression, its OOB prediction is the average of those trees’ predictions. In classification, the OOB class is commonly assigned by majority vote; a predicted class probability can instead be calculated from the OOB votes. An observation with no OOB trees yet has no OOB prediction and cannot contribute to that checkpoint’s error.

$$ \widehat{y}_{i,\mathrm{OOB}}(B) = \frac{1}{|T_i(B)|} \sum_{b\in T_i(B)}\widehat{y}_{ib} $$

Here \(\widehat{y}_{ib}\) is tree \(b\)’s prediction for observation \(i\). For a fixed set of \(n\) observations with OOB predictions, classification error is the number misclassified divided by \(n\). Regression MSE is the sum of squared differences between observed and OOB-predicted responses, divided by \(n\). State which loss is being monitored: a plateau in classification error need not mean that probability estimates, regression error, or another measure have also plateaued.

Why the OOB Curve Can Fluctuate

The OOB predictions are cumulative, but each observation generally has a different set and number of OOB trees. Adding a tree may add a new vote for some observations and no vote for others. In regression, if an observation has \(k\) OOB predictions with current average \(\bar{z}_k\), and the next eligible tree predicts \(z_{k+1}\), the updated average is

$$ \bar{z}_{k+1} = \frac{k\bar{z}_k+z_{k+1}}{k+1} = \bar{z}_k+\frac{z_{k+1}-\bar{z}_k}{k+1}. $$

This identity follows by adding the new prediction to the sum \(k\bar{z}_k\) and dividing by the new total of \(k+1\) predictions. The change can be positive or negative, depending on whether the new tree’s prediction is above or below the current average. Squared prediction errors therefore need not decrease. In classification, a new vote can also change a majority-vote class in either direction. Thus an OOB error curve is not required to be monotone.

There is a further issue at small \(B\): some observations may have few OOB votes, or none. The set of observations contributing to the reported error may change as trees are added. Before interpreting early changes, check the OOB vote count or prediction count for each observation. A practical analysis can require a minimum count per observation, or compare checkpoints on a fixed eligible set. The requirement should be stated; there is no universal count that makes all applications reliable.

Worked Example: Finding the Earliest Stable Classification Window

A hypothetical insurer fits a random forest to classify whether a submitted equipment claim will require a specialist review. Each checkpoint below uses the same 1,000 claims and the same misclassification definition. The minimum OOB vote count for every claim is at least 60 at each listed checkpoint. The analyst defines a stable window as four consecutive checkpoints whose error range is at most 0.8 percentage point. Choose the smallest tree count at which this rule is met.

Trees \(B\)OOB misclassification error
5018.0%
10015.0%
15014.0%
20013.5%
25013.0%
30013.2%
35012.6%
40012.4%
45012.5%
50012.3%

Method. Compute the range, meaning the maximum error minus the minimum error, in every four-checkpoint window. The first four-checkpoint window, from 50 through 200 trees, has range \(18.0-13.5=4.5\) percentage points. The 100–250 window has range \(15.0-13.0=2.0\) points. The 150–300 window has range \(14.0-13.0=1.0\) point. The 200–350 window has range \(13.5-12.6=0.9\) point. None of these earlier windows meets the 0.8-point rule.

The next window, 250–400 trees, has maximum 13.2% and minimum 12.4%, so its range is \(13.2-12.4=0.8\) percentage point. It qualifies. The earliest qualifying window therefore begins at 250 trees, and the analyst can choose 400 trees, the final checkpoint in that window. The later values, 12.5% and 12.3%, are consistent with a continuing plateau, although they were not needed to establish the earliest qualifying window.

Check. The nonmonotone move from 13.0% at 250 trees to 13.2% at 300 trees is included in the range calculation. Ignoring it would incorrectly report a smaller range. The method avoids both assuming monotonic improvement and claiming an earliest window after checking only the immediately preceding one.

Choosing and Applying a Stability Rule

A plateau is an operational definition, not a theorem about the true prediction error. It should be specified in the analysis rather than selected after inspecting the curve to produce a preferred answer. A useful rule states the checkpoint spacing, the number of consecutive checkpoints, the allowable error variation, and any minimum OOB coverage requirement. For example, one might require four consecutive checkpoints to span no more than 0.5 percentage point, provided every observation has at least a specified number of OOB predictions.

The threshold depends on context. A difference of 0.5 percentage point may matter in one application and be negligible in another. The purpose is to make the decision reproducible and to distinguish a relatively stable region from a single favorable checkpoint. If results are reported for a fixed data set, it is also useful to report the metric values and rule, not only the selected \(B\).

1
Choose the metric and checkpoints.
Specify the OOB loss, the spacing between tree-count checkpoints, and the observations used in the calculation.
2
Verify coverage.
Check that observations have enough OOB predictions for the chosen comparison, or use the same eligible observations at each checkpoint.
3
State the stability criterion.
Set a window length and allowable range or another explicit measure of variation before selecting a tree count.
4
Check every earlier window.
Calculate the criterion for all candidate windows before the proposed one. This is necessary to support a claim that it is the earliest qualifying window.
5
Select the endpoint and report the tradeoff.
For a range-based rule, a natural choice is the final checkpoint in the earliest qualifying window. Report the rule and recognize that the choice is about adequate stability, not guaranteed minimum future error.

Worked Example: Computing OOB MSE and Reading a Fluctuation

A hypothetical model predicts the severity score of four kinds of commercial refrigeration failure. At each checkpoint, the values below are OOB predictions for the same four observations. Calculate the OOB MSE and decide whether the sequence supports assuming that error must fall whenever trees are added.

Observed scorePrediction at 100 treesPrediction at 200 treesPrediction at 300 treesPrediction at 400 trees
101110.51110
121112.51212
151414.51315
2018191819.5

Method. At 100 trees, the residuals (observed minus predicted) are \(-1,1,1,2\). Their squared values are \(1,1,1,4\), so the MSE is \((1+1+1+4)/4=1.75\).

At 200 trees, the residuals are \(-0.5,-0.5,0.5,1\). Their squared values are \(0.25,0.25,0.25,1\), giving MSE \((0.25+0.25+0.25+1)/4=1.75/4=0.4375\).

At 300 trees, the residuals are \(-1,0,2,2\). Their squares are \(1,0,4,4\), giving MSE \((1+0+4+4)/4=2.25\). At 400 trees, the residuals are \(0,0,0,0.5\); the squared values sum to \(0.25\), so MSE is \(0.25/4=0.0625\).

The sequence is therefore 1.75, 0.4375, 2.25, and 0.0625. The error rises from 200 to 300 trees and then falls at 400. These four values do not establish a stable plateau, and the increase at 300 does not by itself establish that 300 trees is a better stopping point. More checkpoints and a stated stability rule are needed. The calculation checks out by summing squared residuals at each checkpoint and dividing by the same four observations.

Interpretation, Limits, and Common Traps

The selected number of trees is an adequate ensemble size under the stated monitoring rule and modeling setup. It is not necessarily a unique optimum. Once OOB error has stabilized sufficiently for the intended use, extra trees may add computation without a meaningful reduction in the monitored error. Conversely, a noisy or inadequately covered curve does not justify stopping merely because one checkpoint has a low value.

OOB error is an internal estimate based on the training observations and the forest’s OOB predictions. It is useful for monitoring the forest as it grows, but it is not identical to an independent test-set assessment. The earlier material on OOB error and test error distinguishes these evaluation approaches. If a final performance claim is needed, it should be evaluated with an appropriate validation or test strategy.

  • Assuming monotonic improvement. A new tree can change regression averages or classification votes in a direction that raises the measured error.
  • Calling one low point a plateau. A plateau requires a defined stability criterion across multiple checkpoints, not one favorable value.
  • Checking only the adjacent window. To claim the earliest qualifying window, calculate the criterion for every earlier candidate window.
  • Ignoring OOB coverage. Early checkpoints may have too few OOB predictions for some observations, or may use a changing eligible set.
  • Changing the metric unnoticed. Stable classification error does not imply stable probabilities or stable regression loss. Choose the metric that matches the prediction task.
  • Treating the rule as universal. Window length and tolerance are practical choices that should be justified for the application, not mistaken for general statistical guarantees.
Key takeaway: Monitor a clearly defined OOB metric at repeated checkpoints, establish adequate OOB coverage, and use an explicit stability rule. Verify every earlier candidate window before calling a qualifying window the earliest. A forest’s OOB error need not fall at every increase in tree count.

These ideas are aligned with the SOA Exam SRM (Statistics for Risk Modeling) syllabus: interpret an OOB error trajectory carefully, separate fluctuation from a stable region, and justify an adequate ensemble size without claiming that more trees always improve accuracy.

Check Your Understanding

For each problem, apply the stated metric and rule exactly as given.

  1. A classification forest has OOB error rates of 9.2%, 8.4%, 8.1%, 8.3%, and 8.0% at five equally spaced checkpoints. A three-checkpoint window qualifies when its range is at most 0.5 percentage point. Which is the earliest qualifying window, and at which checkpoint would you stop under the endpoint rule? (Answer: The second through fourth checkpoints have range \(8.4-8.1=0.3\) percentage point; stop at the fourth checkpoint.)
  2. For three observations, the responses are \(5,9,12\), and their OOB predictions at a particular checkpoint are \(4,10,10\). Find the OOB MSE. (Answer: Residuals are \(1,-1,2\), squared residuals sum to \(1+1+4=6\), and MSE is \(6/3=2\).)
  3. At a checkpoint, a classifier misclassifies 6 of 80 observations with available OOB predictions. What is its OOB misclassification error as a percentage? (Answer: \(6/80=0.075\), or 7.5%.)
  4. A monitoring plan requires at least 25 OOB predictions for every observation. The smallest per-observation OOB counts at 50, 60, and 75 trees are 17, 22, and 26, respectively. What is the first checkpoint eligible under this rule? (Answer: 75 trees, because 26 is the first reported minimum count that meets or exceeds 25.)
  5. Four consecutive checkpoint errors are 11.0%, 10.4%, 10.8%, and 10.3%. A four-checkpoint window qualifies if its range is at most 0.8 percentage point. Does it qualify, and what is the range? (Answer: Yes; the range is \(11.0-10.3=0.7\) percentage point.)
Clinical Biostats