Tutorials › Exam SRM - Statistics for Risk Modeling › Bootstrap Sample Size And OOB Inclusion

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

Bootstrap Sample Size And OOB Inclusion

Relate bootstrap sample size to distinct-case and out-of-bag probabilities, and see how those quantities change across trees.

Advanced 10 min read

What You'll Learn

  • Calculate the probability that a training case is omitted from one bootstrap sample.
  • Find the expected distinct in-bag count and expected number of out-of-bag cases.
  • Compare bootstrap samples with different draw counts.
  • Distinguish per-tree OOB probability from coverage across an ensemble.
  • Explain how changing draw count affects tree fitting and OOB availability.

Bootstrap Draws and Distinct Training Cases

A bootstrap sample is formed by drawing training cases with replacement. Its draw count is not necessarily the number of distinct cases it contains: the same case can appear several times, while another case may not be selected at all. This distinction matters in bagging because the draw count affects both the data available to fit each tree and the cases left out for that tree.

Let a training set contain \(n\) cases. Suppose one tree is fitted using \(m\) independent draws, each made uniformly from those \(n\) cases with replacement. A case is in-bag for this tree if it appears at least once in the \(m\) draws, and out-of-bag (OOB) if it does not appear. Here, \(m\) counts draws, including repeated selections; it does not count distinct cases.

Definition: For a bootstrap sample of \(m\) draws from \(n\) training cases, the probability that a specified case is OOB is \(q=(1-1/n)^m\). Its probability of appearing at least once is \(1-q\). The expected number of distinct in-bag cases is \(n(1-q)\), and the expected number of OOB cases is \(nq\).

These are expectations and probabilities, not guarantees for a particular bootstrap sample. For example, the expected number of distinct cases can be non-integer, even though every realized sample has an integer number of distinct cases. The formulas also assume that each draw is uniform over the same \(n\) cases. They do not apply unchanged if the resampling scheme gives different cases different selection probabilities.

Why the Inclusion Formula Holds

Consider one specified training case. On any one draw, the probability of selecting a different case is \(1-1/n\). For the specified case to be OOB, every one of the \(m\) draws must select a different case. Because the draws are independent, multiply the probability of omission across draws:

$$ P(\text{specified case is OOB})= \underbrace{\left(1-\frac{1}{n}\right)\cdots \left(1-\frac{1}{n}\right)}_{m\ \text{independent draws}} =\left(1-\frac{1}{n}\right)^m. $$

The in-bag probability is the complementary event, so it is \(1-(1-1/n)^m\). To obtain the expected count of distinct in-bag cases, define \(I_j=1\) if case \(j\) appears at least once and \(I_j=0\) otherwise. The distinct in-bag count is \(\sum_{j=1}^{n} I_j\). By linearity of expectation,

$$ E\left[\sum_{j=1}^{n} I_j\right] =\sum_{j=1}^{n} E[I_j] =\sum_{j=1}^{n}P(I_j=1) =n\left[1-\left(1-\frac{1}{n}\right)^m\right]. $$

This reasoning does not require the indicators for different cases to be independent. They are not: selecting one case on a draw makes it slightly less likely that another case was selected on that same draw. Linearity of expectation is sufficient. Similarly, if \(J_j=1\) when case \(j\) is OOB and \(0\) otherwise, then the OOB count is \(\sum_{j=1}^{n}J_j\), with expectation \(n(1-1/n)^m\).

Worked Example: Expected Counts for a Standard-Size Bootstrap

A hypothetical claims dataset has \(n=10\) training cases. One bagged tree is fitted from \(m=10\) independent draws with replacement. Find the probability that a specified case is OOB, the expected OOB count, and the expected number of distinct in-bag cases.

Method. Use the per-case omission probability and the expectation formulas. The fact that there are ten draws does not mean all ten cases must appear.

For a specified case, the probability of missing it on one draw is \(9/10=0.9\). The probability of missing it on all ten draws is

$$ q=(0.9)^{10}=0.3486784401. $$

Thus its probability of appearing at least once is

$$ 1-q=1-0.3486784401=0.6513215599. $$

There are ten cases, so the expected OOB count is

$$ E[\text{OOB count}]=10(0.3486784401)=3.486784401. $$

The expected number of distinct in-bag cases is

$$ E[\text{distinct in-bag count}] =10(0.6513215599)=6.513215599. $$

Rounded to four decimal places, the OOB probability is \(0.3487\), the expected OOB count is \(3.4868\) cases, and the expected distinct in-bag count is \(6.5132\) cases. As a check, the expected in-bag and OOB counts sum to \(6.513215599+3.486784401=10\), the full training-set size.

Changing the Number of Draws

For fixed \(n\), increasing \(m\) decreases the OOB probability \(q=(1-1/n)^m\), because \(0<1-1/n<1\) when \(n>1\). It therefore increases the probability that each case appears at least once and increases the expected distinct in-bag count. A larger draw count does not add new training cases; it gives more opportunities to select cases already in the fixed dataset.

When the conventional choice \(m=n\) is used, the OOB probability is \((1-1/n)^n\). For large \(n\), this is approximately \(e^{-1}\), or about \(0.3679\), and the expected in-bag fraction is about \(1-e^{-1}\), or \(0.6321\). These are large-\(n\) approximations, not exact values for every dataset. For example, with \(n=10\), the exact OOB fraction is \(0.9^{10}=0.3487\), not \(0.3679\).

More generally, if the draw count is approximately \(m=\alpha n\), where \(\alpha\) is a positive constant, then for large \(n\),

$$ \left(1-\frac{1}{n}\right)^{\alpha n} \approx e^{-\alpha}. $$

Thus using fewer than \(n\) draws tends to leave a larger fraction of cases out of each tree, while using more than \(n\) draws tends to leave a smaller fraction out. The approximation is useful for intuition; for a finite dataset, calculate the exact power when accuracy matters.

Worked Example: Comparing Half-Size and Full-Size Samples

A hypothetical training set contains \(10\) policy records. Compare one bootstrap sample of \(m=5\) draws with one of \(m=10\) draws. For each draw count, calculate the expected distinct in-bag count and the expected OOB count.

Method. Apply \(q=(1-1/n)^m\) separately at each draw count. The difference between \(m\) and \(n\) is intentional: a bootstrap sample may contain fewer draws than there are training cases.

For \(m=5\), the per-case OOB probability is

$$ q_5=(0.9)^5=0.59049. $$

The expected OOB count is \(10(0.59049)=5.9049\), and the expected distinct in-bag count is

$$ 10(1-0.59049)=10(0.40951)=4.0951. $$

For \(m=10\), the per-case OOB probability is

$$ q_{10}=(0.9)^{10}=0.3486784401. $$

The expected OOB count is \(10(0.3486784401)=3.486784401\), and the expected distinct in-bag count is

$$ 10(1-0.3486784401)=10(0.6513215599)=6.513215599. $$

Rounded to four decimal places, the half-size sample has expected counts of \(4.0951\) distinct in-bag cases and \(5.9049\) OOB cases. The full-size sample has expected counts of \(6.5132\) and \(3.4868\), respectively. In each comparison, the two expectations sum to \(10\). A realized sample can differ from either expectation.

OOB Inclusion Across an Ensemble

OOB inclusion can refer to two different events: a case being OOB for one particular tree, or being OOB for at least one tree in an ensemble. Keep the events separate. Suppose \(B\) trees are built using independent bootstrap samples, each with \(m\) draws from the same \(n\) cases. For one fixed case, the probability of being OOB for a single tree is \(q=(1-1/n)^m\). The probability of being in-bag for that tree is \(1-q\). To be in-bag for every one of the \(B\) trees, the case must be in-bag \(B\) times, giving probability \((1-q)^B\). Therefore its probability of being OOB at least once is \(1-(1-q)^B\). The expected number of trees for which it is OOB is \(Bq\).

These ensemble formulas rely on independence of the bootstrap resamples across trees. They describe whether predictions could be formed for a case from trees that left it out; they do not calculate the resulting OOB prediction or its error. The number \(B\) affects how often a case is left out across the ensemble, while \(m\) determines the OOB probability for each individual tree.

Worked Example: OOB Coverage Across Three Trees

A hypothetical dataset has \(n=4\) training cases. Each of \(B=3\) trees uses \(m=2\) independent draws with replacement. Find the probability that a specified case is OOB for a tree, the expected number of OOB trees for that case, and the probability it is OOB at least once.

Method. First calculate the one-tree OOB probability, then use independence across the three bootstrap samples.

For one tree, the specified case is missed on each draw with probability \(3/4\). Hence

$$ q=\left(\frac{3}{4}\right)^2=\frac{9}{16}=0.5625. $$

The expected number of OOB trees for the specified case is

$$ Bq=3\left(\frac{9}{16}\right)=\frac{27}{16}=1.6875. $$

The probability it is not OOB for any of the three trees is the probability it is in-bag for all three:

$$ (1-q)^3=\left(\frac{7}{16}\right)^3 =\frac{343}{4096}=0.083740234375. $$

Therefore the probability of being OOB at least once is

$$ 1-\frac{343}{4096} =\frac{3753}{4096}=0.916259765625. $$

Rounded to four decimal places, the one-tree OOB probability is \(0.5625\), the expected OOB-tree count is \(1.6875\), and the probability of OOB inclusion at least once is \(0.9163\). The last answer is larger than the one-tree OOB probability because it concerns three independent opportunities for omission.

Implications for Fitting Trees

Changing \(m\) changes the resampled training data for each tree. With fewer draws, the tree is built from fewer total selections and typically has fewer distinct cases available; repeated selections can still occur. This may make an individual tree more sensitive to the particular resample, depending on the splitting and stopping rules. It also increases the OOB probability per tree, so each case is eligible to be left out more often.

With more draws, the expected number of distinct in-bag cases increases, but it cannot exceed \(n\). The sample still contains only cases from the original training set, and the bootstrap can still repeat cases. As \(m\) becomes very large for fixed \(n\), the probability that any particular case is never drawn approaches zero, so OOB opportunities for that tree become scarce. These are structural consequences of the resampling scheme; they do not guarantee that predictive performance improves or worsens. Tree depth, minimum node size, the data, and other fitting choices also matter.

Increasing \(B\) is different from increasing \(m\). Increasing \(B\) supplies more independently resampled trees, while leaving the per-tree draw count unchanged. It can increase the chance that each training case is OOB for at least one tree, but it does not change the expected distinct in-bag count for any one tree. In particular, a small per-tree OOB probability can still produce useful coverage across many independent trees, although coverage should be checked rather than assumed.

Common Mistakes

A tempting shortcut is to assume that \(m\) draws select \(m\) different cases. For \(n=10\) and \(m=10\), that shortcut gives the wrong OOB fraction:

$$ \text{Incorrect: }1-\frac{m}{n}=1-\frac{10}{10}=0 \qquad\text{versus}\qquad \text{Correct: }\left(1-\frac{1}{10}\right)^{10}=0.3487. $$

The incorrect calculation treats the sample as a selection without replacement. In a bootstrap sample, a case can be selected repeatedly, so ten draws need not cover ten distinct cases. The correct calculation tracks the probability of missing one specified case on every draw.

  • Confusing draws with distinct cases. The bootstrap sample has \(m\) draws, but its number of unique cases is random.
  • Calling \(q\) the in-bag probability. \(q=(1-1/n)^m\) is the OOB probability; the in-bag probability is \(1-q\).
  • Using an approximation as an exact value. The \(e^{-1}\) approximation applies to \((1-1/n)^n\) for large \(n\), not to every finite sample size.
  • Mixing up \(m\) and \(B\). \(m\) controls sampling within each tree; \(B\) controls the number of trees over which OOB opportunities accumulate.
  • Treating expected counts as realized counts. An expected count such as \(6.5132\) describes an average over repeated resampling, not a fractional number of cases in one tree.
Key takeaway: For \(m\) draws with replacement from \(n\) cases, one case is OOB with probability \((1-1/n)^m\). Multiply that probability by \(n\) for the expected OOB count, and use independent-tree calculations when asking about coverage across an ensemble.

Check Your Understanding

For each problem, distinguish the number of draws from the number of distinct cases and state whether the question concerns one tree or an ensemble.

  1. A hypothetical dataset contains \(8\) records, and one tree uses \(m=4\) bootstrap draws. Find the exact probability that a specified record is OOB and the expected number of distinct in-bag records. (Answer: \(P(\mathrm{OOB})=(7/8)^4=2401/4096\approx0.5862\); expected distinct in-bag count \(=8(1-2401/4096)=1695/512\approx3.3105\).)
  2. A tree uses \(m=3\) draws from \(n=5\) cases. Find the expected OOB count and expected distinct in-bag count. (Answer: \(q=(4/5)^3=0.512\); expected OOB count \(=5(0.512)=2.56\), and expected distinct in-bag count \(=5(0.488)=2.44\).)
  3. For \(n=6\), compare the per-case OOB probabilities for \(m=6\) and \(m=12\). Give both to four decimal places and state which draw count gives the larger expected distinct in-bag count. (Answer: \(m=6:\ (5/6)^6=0.3349\); \(m=12:\ (5/6)^{12}=0.1122\). The \(m=12\) sample has the larger expected distinct in-bag count.)
  4. A dataset has \(n=3\), and each of \(B=2\) independently generated trees uses \(m=1\) draw. Find the probability that a specified case is OOB for at least one tree. (Answer: \(q=2/3\), so the probability is \(1-(1-q)^2=1-(1/3)^2=8/9\approx0.8889\).)
  5. A team doubles the draw count \(m\) for every tree but keeps \(n\) and \(B\) fixed. State the direction of change in (a) expected distinct in-bag cases per tree and (b) per-case OOB probability per tree. Explain why this does not by itself determine whether predictive performance improves. (Answer: (a) increases or stays below the maximum \(n\); (b) decreases, since \((1-1/n)^m\) decreases as \(m\) increases for \(n>1\). Predictive performance also depends on the data and tree-fitting choices, so these resampling counts alone do not determine it.)
Clinical Biostats