Where session 1 left you
You hand-built a split on the Mango Lane data, then watched a depth-6 tree score 75.0 on training and 58.0 on holdout - a 17-point gap made of memorized noise. Tonight's promise is specific and measured: the same trees, bagged and decorrelated, land at 68.0 holdout - averaging is worth ten points on this data. Not a slide claim; session 3's live engine re-measures it in your browser.
★ What you walk out with tonight. Breiman's instability argument, quoted, so you know why bagging works and when it will not. The one idea that makes a forest more than bagged trees - random feature subsets - with its honest credit lineage. And out-of-bag error, the free lunch: a validation score you did not have to pay a test set for.
LiveThe recipe in one breath2 min▶
A random forest is four decisions, and you already understand three of them from session 1:
- Bootstrap sample per tree - each tree trains on 200 customers drawn WITH replacement from the 200. Different tree, different world.
- Random feature subset per split - at every node, a tree may only consider a random handful of the six features. This is the part that is actually new, and the part that earns the name.
- Deep trees, on purpose - the instability that ruined the single tree is the fuel here. Do not prune the very thing you are about to average away.
- Vote - sixty churn calls per customer, majority wins.
Everything in the next forty minutes is one of these four decisions examined properly.
Self-studySay it before you build it2 min▶
Before class, try saying the recipe out loud without the page. The order matters: bootstrap gives each tree its own sample, feature subsetting gives each tree its own perspective, depth keeps each tree opinionated, and the vote turns sixty opinionated witnesses into one calm verdict. If you can say why each step exists, session 3's boosting - which deletes the vote and replaces it with a chain - will land in minutes.
Bagging: many worlds, one vote
7 min liveBagging is 1996 Breiman, and his own sentence still explains it better than any textbook paraphrase: "The vital element is the instability of the prediction method. If perturbing the learning set can cause significant changes in the predictor constructed, then bagging can improve accuracy." Read that twice - it names both the disease and the entry requirement for the cure.
LiveThe mechanism: sampling with replacement, deep on purpose4 min▶
To bootstrap the Mango Lane training set, draw a customer at random from the 200, write it down, put it back, and repeat 200 times. Some customers appear twice or three times; others never appear at all. Do this sixty times and you have sixty overlapping-but-different training sets - sixty perturbed worlds.
Now recall session 1: a deep tree is spectacularly sensitive to its sample - move ten customers and the upper tree reshapes. Bagging turns that sensitivity into diversity. Sixty worlds produce sixty genuinely different trees, and that is why the recipe says deep trees, unpruned: instability is the fuel. Tame the trees and you starve the average.
A team at a retailer once "improved" their forest by heavily pruning every tree to make each one individually respectable. The forest got worse. Sixty polite, stable, nearly identical trees have nothing to argue about - and the argument was the value.
LiveWhy the variance cancels - and why bagging logistic regression does nothing3 min▶
Each deep tree's error has two parts: the signal it caught, and private mistakes tied to its particular bootstrap sample - which duplicates it saw, which noise-labeled customers it happened to memorize. The signal part is shared across trees; the private part is independent-ish, pointing in different directions tree by tree. Average sixty of them and the shared signal survives while the disagreements cancel toward zero. That is variance reduction, in one sentence.
The same logic says when bagging is useless. Bag sixty logistic regressions and each fit lands on nearly the same coefficients - it is a stable method, exactly the case Breiman's sentence excludes. Sixty copies of the SAME mistake do not cancel; averaging identical errors changes nothing. The cure only works on the disease.
Self-studyThe measured payoff on the course data2 min▶
| Model | Train | Holdout | Read |
|---|---|---|---|
| Single tree, depth 6 | 75.0 | 58.0 | memorized fragments, generalizes worst |
| Bagged forest, 60 trees d6, feature subsample | 88.5 | 68.0 | variance averaged away: +10 holdout |
Notice the train number went UP too, 75 to 88.5 - the forest is not weaker on the training data, it is stronger everywhere, because sixty perspectives recover signal any single perturbed tree missed. And the train-holdout gap shrank from 17 points to about 20 on a much higher base - the noise-chasing got diluted. Session 3's engine fits this exact forest live so you can watch both numbers move.
The random in random forest is not the bootstrap
6 min liveHere is the part most blog posts flatten: bagging trees does NOT make a random forest. Breiman's 2001 definition: "Random forests are a combination of tree predictors such that each tree depends on the values of a random vector sampled independently..." - and the random vector he means governs a second randomization: at every split, the tree may only consider a random subset of the features.
LiveWhy subsetting decorrelates, on Mango Lane's own columns4 min▶
On this data, daysSinceOrder is the loudest feature - you found that yourself in session 1's hand-split. Left unconstrained, every one of the sixty trees grabs daysSinceOrder at the root, because it wins the split search in nearly every bootstrap world. Sixty trees, one skeleton: the forest degenerates into sixty near-copies, their votes redundant, and the averaging math from part 1 quietly dies - correlated errors do not cancel.
Force each split to choose from a random handful of features and some trees must open with tickets, or sessions30d, or discountShare. Those trees carve the customers along genuinely different boundaries, make genuinely different private mistakes - and the vote becomes what it pretends to be: independent witnesses, not one witness with sixty microphones.
Breiman measured what this buys: random feature selection "yields error rates that compare favorably to Adaboost... but are more robust with respect to noise." Hold that phrase - our lab data has 10 percent label noise by construction, and robustness to noise is exactly why the forest handles it with grace.
Self-studyCredit where it is due2 min▶
The lineage matters, and Breiman himself is careful about it: his 2001 paper credits Ho 1998 (the random subspace method) and Amit & Geman 1997 as precursors of the random-feature idea. So when someone tells you "random forest is just bagged trees", you now hold two corrections: it is bagging PLUS per-node feature subsetting, and the subsetting idea has its own family tree. Precision about credit is the same muscle as precision about scope - session 1 taught you the second, this is the first.
Out-of-bag error: the free lunch
5 min liveLook back at the bootstrap picture: each world is missing customers. Breiman noticed the leftovers are not waste - "about one-third of the instances are left out" of each bootstrap sample, which means every customer has roughly twenty trees (of sixty) that never saw it. Score each customer using only those trees and you get a validation estimate without spending a single row on a test set.
LiveWhat Breiman claimed for it, and the caveat that keeps it honest3 min▶
Breiman's claim is bold and verbatim: "using the out-of-bag error estimate removes the need for a set aside test set", and he reports the OOB estimates are "unbiased". For every customer, some trees never saw her - their votes are honest tests, not recall. Aggregate those honest votes across all 200 training customers and you have a generalization estimate that cost you nothing.
The caveat you must carry: OOB overestimates error early in training. With only a handful of trees grown, each customer's OOB committee is tiny - two or three trees instead of twenty - and a tiny committee votes badly. The unbiasedness arrives once enough trees are grown, not at tree five. Watch a forest's OOB curve and you will see it start pessimistic and settle as the committee fills out.
One-third, from first principles. Each draw misses a given customer with probability 199/200. After 200 draws with replacement, the chance she was never drawn is (199/200)^200, about 0.37 - Breiman's "about one-third of the instances are left out" is that number, not a design choice.
Self-studyWhen you still want a true holdout anyway3 min▶
OOB is forest-internal - it validates a random forest against resamples of its own training data. Two situations where that is not enough:
- Time-based splits. Churn is a future-prediction problem: in production you train on last quarter and predict next quarter. Bootstrap resampling shuffles time away, so OOB cannot tell you whether the model survives the drift between quarters. A holdout cut by date can.
- Comparing across model families. Next session's booster has no bootstrap and therefore no OOB. To put a forest, a booster and a logistic regression on one honest leaderboard, they must all face the SAME unseen customers - which is exactly why this course keeps its 100-customer holdout even though tonight's model comes with free validation built in.
So the working rule: OOB to monitor and tune the forest, the true holdout to judge it against everything else.
Build the forest's logic by hand
★ 18 min · everyone buildsSixty trees is a job for code, but every mechanism in the recipe - bootstrap, forced feature subsets, the vote, out-of-bag - fits on paper at ten customers and two trees. Get your session 1 10-customer excerpt and a die.
Bootstrap your excerpt. Number your 10 customers 0-9. Roll a die (or use a phone's random digit) 10 times, writing down the customer each roll picks - with replacement, so repeats stay. Look at your list: some customers appear twice, some never. You are holding bootstrap world A, and the missing customers are its out-of-bag set. Keep the list.
Grow paper tree A under a feature handcuff. Rule: this tree may only split on {tickets, aov} - a forced random subset. Find your best split by counting, exactly like session 1. Notice what just happened: your best feature, daysSinceOrder, was not on the menu, so this tree carved the customers along a boundary your session 1 tree never considered. That difference IS the decorrelation from part 2.
Grow paper tree B on a second bootstrap with the subset {daysSinceOrder, sessions30d}. Roll a fresh bootstrap first. This tree probably roots on daysSinceOrder like your session 1 tree - but on a different sample, so its threshold lands somewhere new.
Hold the vote. Pick three customers from the excerpt and run each through paper tree A, paper tree B, and your session 1 tree: three churn calls per customer, majority wins. Find a customer where the vote overrules one wrong tree - that single overrule, times sixty trees and two hundred customers, is the entire ten-point payoff.
Compute a tiny OOB set. For each paper tree, list the customers its bootstrap never drew. Those customers can be scored by that tree as honest unseen tests - you just computed an out-of-bag set by hand. If a customer is out-of-bag for both trees, both may vote on her; that committee-of-honest-votes is Breiman's free lunch at miniature scale.
Bring this intuition to session 3. Voting averages away mistakes, but it cannot add signal no tree ever found - if all sixty trees miss a pattern, the vote misses it too. Session 3 replaces the vote with a chain: each new tree is trained on exactly what the previous ones got wrong. Averaging fixes variance; chaining goes after what averaging cannot touch.
Before session 3
30 min- Finish the paper forest: add a third bootstrap and a third feature handcuff ({discountShare, orders90d}), grow paper tree C, and re-run the three-customer vote with four voters. Did any verdict flip?
- Say the recipe from memory - bootstrap per tree, random subset per split, deep trees, vote - and for each step, one sentence on what breaks without it. The subsetting sentence is the one most working data scientists cannot produce.
- Explain to a colleague why bagging their logistic regression will not help, using Breiman's instability sentence. If they ask "so instability is good now?", you have the conversation this session prepared you for.
- Read Breiman 2001, section 1 only (stat.berkeley.edu/~breiman/randomforest2001.pdf) - watch him credit Ho and Amit & Geman by name, and find the definition sentence this session quoted.
- Optional: work out (199/200)^200 on any calculator and confirm the one-third for yourself. Small proofs you own beat big claims you rent.
Three questions
Clear all three and session 2 gets stamped in your passport.
1 · Bagging sixty deep trees buys ten holdout points on the course data, but bagging sixty logistic regressions barely moves the needle. Why?
Breiman 1996, verbatim: "The vital element is the instability of the prediction method. If perturbing the learning set can cause significant changes in the predictor constructed, then bagging can improve accuracy." Instability is the entry requirement - bagging helps unstable learners like deep trees and does little for stable ones. The flaw that ruined session 1's single tree is the fuel here.
2 · Your teammate says "a random forest is just bagged decision trees". What is missing?
RF = bagging PLUS per-node random feature subsetting - "each tree depends on the values of a random vector sampled independently", in Breiman's definition. Without it, all sixty Mango Lane trees root on daysSinceOrder and become near-copies whose correlated errors do not cancel. And credit travels with the idea: Breiman himself cites Ho 1998 and Amit & Geman 1997 as precursors of the random-feature trick.
3 · How does out-of-bag error work, and when should you distrust the number?
Each bootstrap leaves out "about one-third of the instances", so every customer has trees that never saw her - their votes are honest tests. Breiman: "using the out-of-bag error estimate removes the need for a set aside test set", and the estimates are "unbiased" - but only once enough trees exist; early on, tiny committees make OOB pessimistic. And OOB stays forest-internal: for time-based splits or cross-family comparisons you still want the true holdout.
What this session teaches, and where it came from
Every fact on this page, and its verification tier, is recorded in the course's source map.
Session 2 cheat sheet · pin this
Tonight's forest votes; it cannot add signal no tree found. Session 3 switches recipes: chain the trees, each one trained on what the last got wrong. The residual game - boosting as gradient descent in function space, the learning rate that tames it, and the live engine fitting real trees in your browser while you watch the train and holdout curves split apart.