2.3.9 · D2Tree-Based & Instance Methods

Visual walkthrough — Out-of-bag error estimation

1,765 words8 min readBack to topic

This page draws the one number that makes OOB error work: why about of your data is "left out" of every tree. We build it picture by picture, touching no symbol before it earns its place.

We are studying bootstrap sampling — the with-replacement draw that bagging and random forests are built on. The whole magic reduces to a single question:

If I pull a name out of a hat times (putting it back each time), what is the chance one particular name never comes out?

Answer that, and you understand where OOB samples come from.


Step 1 — The dataset is a bag of numbered balls

WHAT. Picture your training set as a physical bag. Every training point is one ball, painted with a number: ball , ball , up to ball . Here (say it "en") is just the number of training points — the count of rows in your data.

WHY start here. A bootstrap sample is literally drawing balls from this bag. If we can see the bag, we can see the drawing, and the whole probability becomes counting.

PICTURE. Look at the bag below: balls, each equally likely to be grabbed. The dashed arrow is your hand reaching in.

Figure — Out-of-bag error estimation

Step 2 — One draw: the chance of missing ball

WHAT. Fix your eye on one specific ball — call it ball (the -th point). In a single grab, what is the chance you do not pull ball ?

WHY this tool — simple counting of equally likely outcomes. Every ball is equally likely, so probability is just favourable outcomes over total outcomes. There are balls total, and of them are "not ball ". No calculus needed yet — just fractions.

Term by term: the top counts every ball except ; the bottom counts all balls; their ratio is the fraction of the bag that is "safe" from being . Rewriting as just says "the whole bag () minus ball 's share ()."

PICTURE. The pie shows the bag split into ball 's slice (pink, ) and the "miss" region (blue, ). One grab landing anywhere in blue is a miss.

Figure — Out-of-bag error estimation

Step 3 — All draws: multiply the misses

WHAT. A bootstrap sample is not one grab — it is grabs, putting the ball back each time. Ball is out-of-bag only if it is missed on grab 1 and grab 2 and ... and grab .

WHY multiplication — independence. Because we replace the ball after every grab, the bag is identical for every draw. Independent "and" events combine by multiplying their probabilities. That is the only reason we get a clean power here.

Term by term: each bracket is the same one-draw miss chance from Step 2 (identical bag every time). The exponent counts how many grabs must all be misses. "With replacement" is exactly what makes all brackets equal.

PICTURE. A ladder of independent grabs; each rung multiplies in another . Ball survives to the bottom only if every rung is a miss.

Figure — Out-of-bag error estimation

Step 4 — Watch the number settle as the bag grows

WHAT. Plug in growing and watch :

WHY it doesn't just go to zero. Two forces fight: the base creeps up toward (each miss gets easier), while the exponent grows (more grabs to survive). They balance, and the product homes in on a fixed value near — not , not .

PICTURE. The curve of against , flattening onto a dashed horizontal line. The tug-of-war is visible: it plunges from then bends and levels off.

Figure — Out-of-bag error estimation

Step 5 — Name the limit: it's

WHAT. The value the curve settles on is exactly , where is Euler's number.

WHY appears — it is the definition of . The number is defined by the fact that approaches as grows. Our expression is that pattern with :

Term by term: is the "per-step nudge" ( here, because each grab subtracts one ball's share ); is the number of steps; the limit turns "many tiny multiplicative nudges" into a single exponential. We reach for the exponential precisely because it is the one function that collapses an -fold product of near- factors into a closed number.

PICTURE. Same curve as Step 4, now with the dashed line labelled and the in-bag remainder shaded above it.

Figure — Out-of-bag error estimation

Step 6 — Edge cases: don't skip the ends

Limits are honest only if the boundaries behave. Check every corner.

. One ball, one grab — you always pick it. . Chance of OOB is : with a single point, nothing is ever left out. ✔ matches the table.

. . Already sensible — a full quarter of the time the point is missed both grabs.

Small in practice. For we got , and Worked Example 1 in the parent measured on one actual sample. Both are fine: the value is the long-run average, and any single tree's OOB fraction rattles around it. Small more rattle.

. The limit ; the fraction stops moving. This is the regime real datasets live in, which is why " OOB" is a safe rule of thumb.

PICTURE. A number line from to with the sequence's values dropped as ticks — at , then climbing to and crowding just under the pale-yellow mark.

Figure — Out-of-bag error estimation

Step 7 — From "" to a usable test set

WHAT. Turn the probability into the payoff. If a point is OOB for a tree with chance , then across trees it is OOB for about of them — a ready-made mini test panel of trees that never saw it.

WHY this closes the loop. OOB error predicts each point using only those un-trained trees (majority vote for classification, average for regression), then averages the loss. The we just derived is precisely what guarantees every point has enough "honest" judges — provided is large.

Term by term: is the total number of trees; is our ; their product is the expected size of the honest sub-ensemble that votes on point .

PICTURE. A row of trees; for one highlighted point, the blue-tinted trees () are its OOB voters, the faded ones trained on it and are ignored.

Figure — Out-of-bag error estimation

The one-picture summary

Everything in one frame: bag one-draw miss multiply over grabs curve settles OOB, in-bag honest voters per point.

Figure — Out-of-bag error estimation
Recall Feynman: the whole walkthrough in plain words

Put every training point as a numbered ball in a bag. To build one tree you grab a ball, write it down, and drop it back, over and over, times. Pick one ball and ask: what's the chance it never gets grabbed? In one grab, missing it is easy — . But you grab times, and because you keep dropping the ball back, each grab is the same fresh chance, so you multiply: . As the bag gets huge, missing any one ball gets easier () but there are more grabs to survive ( up) — the two pushes balance and the number stops at about , which is , the very number that defines . So roughly of points sit outside each tree's training. Those "left-out" points are a free test set: quiz each point using only the trees that never studied it, average the mistakes, and you get an honest estimate of how the forest handles new data — no separate validation set required.


Connections