2.3.6 · D1Tree-Based & Instance Methods

Foundations — Bagging and bootstrap aggregating

2,346 words11 min readBack to topic

Before you can read the parent note comfortably, you need to earn every symbol it throws at you. This page starts from a smart 12-year-old with zero notation and builds each piece, one on top of the last. Nothing here contradicts the parent — it is the scaffolding underneath it.

Prerequisite vault stops on the way: Bootstrap (statistics), Decision Trees, Bias-Variance Tradeoff, and the destination is the parent Bagging topic (and later Random Forests, Ensemble Methods).


0. What is a "prediction" and why call it a random thing?

Imagine you want to guess a house's price from its size. A model is a rule that eats an input and spits out a number. We write the input as (the house's size) and the model's guess as — read aloud: "f-hat of x".

Why does the parent treat as random? Because if you had collected a slightly different dataset (a different sample of houses), you'd have fit a slightly different rule and gotten a slightly different guess for the very same house. The guess wobbles depending on which data you happened to see. A number that changes with luck-of-the-draw is exactly what we mean by a random variable.

Figure — Bagging and bootstrap aggregating

Look at the red dot in the figure: same house , but three different datasets gave three different predictions. That spread is the randomness we're about to name and measure.


1. The dataset and its size — where the randomness lives

Why does the topic need ? Because the whole magic number of bagging — that of points get left out — is really a statement about how big your dataset is, in the limit of large .


2. Sampling "with replacement" — the heart of bootstrap

Here is the one physical action bagging is built on.

Figure — Bagging and bootstrap aggregating

In the figure, card was drawn twice (duplicate) and card was never drawn (a gap — this becomes an out-of-bag point). This single "replace the card" step is what the bootstrap means, and it's why some points go missing.


3. Building many models: the count and the average

Bagging fits many models, one per resample. We need a name for "how many."

Now that and are defined, we can safely use them below.


4. The centre and spread of one model: and

Every prediction is a random variable (it depends on the lucky draw ). Two numbers summarise its cloud — and both are for a fixed input , so we keep the visible.

Figure — Bagging and bootstrap aggregating

The figure shows two clouds with the same centre but different widths — small (tight) vs large (loose). Bagging's whole promise is: keep fixed, shrink the width.


5. How two models relate: covariance and correlation

To predict what happens when we average models, one model's spread isn't enough — we must know whether two models err together.


6. Putting it together — deriving the variance of the average

We want the spread of the bagged prediction . Two rules do the whole job.

Rule A — expectation is linear (the centre is unchanged).

Rule B — variance of a sum (the spread does shrink). Here is why covariance had to enter.

Now plug in , , and (from §5) . There are diagonal terms and off-diagonal pairs:

Divide through by and simplify:

Read it with your new vocabulary: the shared-wobble part comes straight from the covariance cross-terms and never shrinks; the personal-wobble part comes from the diagonal and melts as grows. If that sentence makes sense, you're ready for the parent page.


7. The exponential and the number

The parent claims . Where does come from?

Why and not just "compute the number"? Because changes from problem to problem, but the answer barely moves once is a few hundred — it locks onto the constant . That stability is why the parent can quote a single "37%" for any large dataset.


Prerequisite map

Population urn: i.i.d. draws

Dataset D of size n

Model prediction f-hat of x

Prediction as a random variable

Draw with replacement

Bootstrap sample D_b

Number of models B and average

Centre mu of x

Variance sigma-squared of x

Covariance and correlation rho

Bagged predictor f-bar

Linearity of expectation

Bias unchanged

Variance formula

Exponential e gives 37 percent OOB

BAGGING topic


Equipment checklist

Test yourself — each line is a question ::: answer reveal.

What does the hat in mean?
An estimate from data, not the true unknown value.
Why is a single prediction treated as random?
The dataset was a lucky i.i.d. draw; redraw it and the fitted rule (and its guess) changes.
What does "i.i.d." mean for the data?
Each pair is drawn independently from the same population — the true source of randomness.
What does "with replacement" physically mean?
Pick a data point, note it, put it back, repeat — the same point can be chosen more than once.
What does stand for?
The number of examples (rows) in the dataset .
What does stand for?
The number of base models we build, one per bootstrap resample.
In plain words, what is ?
The centre the predictions at input average to over many datasets.
In plain words, what is ?
The spread of one model's prediction at : .
Define covariance in words.
The average product of the two models' errors — positive if they tend to be wrong the same way.
How do covariance and correlation relate here?
— correlation is covariance rescaled by the spreads.
What does mean?
The long-run average (expectation) over all possible datasets.
State linearity of expectation in words.
The centre of the average equals the centre of one model; constants pull out.
What are the two parts of ?
A diagonal plus off-diagonal cross-terms .
Where does come from?
for large — the chance a point is missed by a resample.
Which quantity does averaging leave unchanged, per linearity?
The bias / centre — bagging only shrinks variance.