Supervised Learning
Supervised Ensembles: Random Forests & Boosting
An ensemble combines actual learner predictions; bootstrap sampling, feature restrictions and sequential weighting create different voting rules.
One direct depth-two fit: move the query cross
computing. Completed work units 0. No completed model readouts are shown.
24×20 cell-centre samples; constant opacity encodes classes, not confidence. A plain/circle; B hatched/square. All training observations are shown. Axes include both draws; pixel lengths need not equal feature distances.
Query (5, 5): Predict first, or wait for fitting.
- Class A circle / plain field
- Class B square / hatched field
- Unlabelled query
Query and random stream
Completed readouts wait for this experiment’s fitting and field.
Where does one shallow tree make mistakes?
This depth-two tree fits the displayed training observations directly, without a bootstrap. Move the unlabelled query and inspect its actual prediction.
- Training observations
- Direct or replacement-sample fits
- Actual learner predictions
- Declared aggregation
- Exploratory validation
Base learner
One fitted predictor that can contribute to an ensemble.
Check this stage
Check your understanding
Move a query through real tree predictions. Inspect which original rows each bootstrap repeats, how hard votes combine, and how AdaBoost changes the next round’s fitting weights.
Follow one prediction
An ensemble combines fitted predictors. Bagging gives independently fitted trees equal votes; AdaBoost builds a sequence whose later fits depend on earlier reweighting. Neither guarantees that every extra learner improves validation accuracy.
Start with Single tree. Drag the neutral query cross, use its arrow keys, or open Query and random stream for native coordinates. The cross has no class label and never enters training. Training A observations are circles, B observations squares; the selected training row has extra emphasis. The baseline is a directly fitted depth-two tree, which can make several splits, not just one.
The synthetic observations come from four Gaussian clusters with alternating cluster labels. There are sixty training observations and an independent validation draw of eight hundred. Labels follow cluster membership; overlapping Gaussian tails mean this is not an exact deterministic XOR rule at every coordinate. Spread is coordinate variation, not injected label corruption. New data changes the training draw; validation stays fixed. No manual observation or label edits are offered. The fixed validation seed 987654 is reserved. A shared URL requesting it for training resolves visibly to 987655; New data skips the reserved seed. This prevents a training request from reusing the validation random stream. The displayed and shared training seed is always the resolved seed actually used.
A bootstrap repeats identities
Open Bootstrap samples. Inspect a learner, then choose a training observation. Its multiplicity counts how many times it entered that learner’s fit. Dimmed rows were omitted. Resample bootstrap changes replacement draws on the same observations; it does not acquire sixty new measurements. The drawer lists the exact draw order.
For four observations, draws [0, 0, 2, 3] mean multiplicities [2, 0, 1, 1]:
four fitting rows, three unique observations, and row one out of bag for this tree.
The omission probability for a named row is , approaching about 0.368 for
large . It is not a guaranteed omitted fraction in each realised sample.
At Features per split = 2, each candidate node considers both coordinates: this is bagging. At one, the forest randomly considers x or y at each node. That can change learner dependence and strength; it need not improve this small two-feature task. The original implementation uses one random stream for draws and feature choices, so changing feature count can also change later bootstrap samples. Same seeds and settings reproduce the same complete experiment. Do not interpret that comparison as a perfectly paired identical-bootstrap experiment.
Count the actual votes
Open Combine votes, make a class prediction, and reveal it. Every forest tree
casts one hard class vote. Votes [A, B, B] select B; [A, B, B, A] tie and select A
under this lab’s lowest-label rule. The drawer gives every learner’s query vote.
The winning fraction is a vote share, not a calibrated probability. This differs
from library forests that average leaf class probabilities.
The full ensemble field and selected-learner field sample a 24 by 20 grid at cell centres using those same predictors. A is plain and B hatched. Opacity is constant; it does not encode uncertainty. Finite samples can miss behaviour between centres, and the shared primitive rounds cell edges to pixels. Axes cover both generated populations with padding and can change after resampling. Raw cell coordinates and predictions remain in the drawer. Pixel distances need not preserve aspect ratio.
The learner selector and Step learner inspect all accepted fitted members. They change neither the full ensemble nor its prediction. Two legible plots replace the old first-five miniature strip; every learner remains accessible at native text size. This is inspection of completed work, not animated training or autoplay.
What does AdaBoost actually update?
Open First AdaBoost round. The model starts with score and equal weights . Encode A as and B as . A shallow classification tree grows by greedy weighted Gini reduction on these same training rows. Its weighted error is then measured; weighted Gini search is not a global oracle for minimum classification error over every possible tree.
For an accepted learner , define error , applied coefficient , learning rate and positive normaliser :
The learning rate multiplies the coefficient before both score addition and reweighting. The full score is a sum, not a regression mean. Nonnegative score selects B, including an exact zero tie. No accepted learner gives an unavailable prediction. This is signed binary AdaBoost, not gradient boosting fitted to regression residuals.
Hand example: four equal weights, one mistake, rate one. Error is , so . Correct weights multiply by and the wrong weight by . The normaliser is . Next weights are . A smaller rate changes that allocation too; at rate one half, the wrong row’s share is , not one half.
Select a training row to compare its incoming/outgoing weight. Bars use the actual zero-to-one fraction; exact values stay beside them and in the complete training ledger. Observation weights control fitting; learner coefficients control voting. They are different quantities. The original point-size promise is replaced with this explicit measurement, without clipped or invented radii.
Read a real history, including its stops
In AdaBoost history, inspect every accepted round’s weighted error, raw/applied coefficient, normaliser, prefix accuracy and mean training exponential loss:
In the four-row hand example, loss goes from one to . Classification accuracy and exponential loss measure different things; neither is the validation accuracy. The model uses the requested number of learners unless a stated fitting stop occurs. A finite budget is not convergence.
Error at least one half, within an absolute comparison tolerance, rejects that proposed learner and stops, leaving accepted history unchanged. Zero error has an infinite ideal coefficient; this implementation uses an explicit error floor of in the half-log coefficient, retains the learner, applies the same normalised update and stops. A perfect constant learner on one-class input is valid. Log normalisation avoids overflow, preserving exact zero input weights; it does not repair contradictory labels or missing information. The same coefficient floor applies to tiny positive errors; only exact zero triggers the perfect-learner stop. The chance tolerance prevents floating-point summation from turning a theoretical half into a spurious positive advantage.
All trees retain the shared weighted-tree conventions: distinct-value midpoint candidates, x before y, ascending thresholds, strict improvement retaining the first tie, equality routed left, lowest-label leaf ties, parent split size two and child size one. Pure nodes, depth limits and absent admissible thresholds stop growth. Zero-gain growth remains enabled here; the separate decision-tree experience opts into positive-gain stopping. No validation label enters any of these decisions.
Break the interaction limit, then recover
Choose Load stump limit. It restores the original population and seeds, rate one, twenty requested AdaBoost rounds and depth one. Read the actual training and validation scores. A stump is a function of x alone or y alone; a signed sum is . That score cannot classify all four ideal XOR corners correctly: the required diagonal sign inequalities contradict after addition. A finite noisy cluster sample can still show improved training accuracy. A gap alone does not prove memorisation or supply a bias–variance decomposition.
Use Load challenge, keep its seeds, rate and round budget fixed, then change depth alone to meet the stated training/validation targets. A deeper path can test both coordinates. That is a measured repair for this task, not a claim that deeper trees always generalise better. Opposite labels at exactly identical coordinates remain inseparable by any deterministic rule on these features.
The banner identifies the loaded preset and separately reports the current recomputed experiment after edits. Back to working restores every preceding setting, seed, query, inspection selection, guided/free mode, prediction and saved fitted history. Recovery stays accessible in free exploration. A snapshot of unfinished work returns cancelled with Retry rather than pretending to have a complete fit.
Keep evaluation and state honest
Training and independent validation scores use the same active predictor. Every prefix is scored on the same observations; counts, per-class validation recall and the balanced training-majority baseline accompany accuracy. Requested learner count is an explicit budget, not equal wall-clock work: tree depth, feature count and sequential updates differ. No universal method ranking follows.
The validation draw is reused while you explore, so it is exploratory validation, not an untouched final test. OOB membership names training rows omitted by a particular bootstrap; this lab does not compute an OOB score. A proper OOB prediction would use only voters that omitted that row. Bagging does not eliminate bias, extra trees do not force monotone validation, and disagreement is not automatically uncertainty. Boosting can focus on repeatedly misclassified labels; it need not always overfit. No label-noise control or universal noise-chasing preset is simulated here.
Model/data changes start bounded recomputation, one learner or one field row per unit, with real progress, Cancel and Retry. Partial/stale work never supplies completed readouts. Inspection and query edits reuse fits. Reset keeps stage/training seed, restores defaults, returns guided and clears recovery/guesses. Share reproduces the guided display stage, seeds, settings, query and inspection by deterministic refitting; it excludes guesses, sandbox identity, local progress, recovery and pending work.
Sources: Breiman’s bagging paper, random forests paper, Cornell’s boosting derivation, and the scikit-learn ensemble guide.
Stage recap
Single tree
This depth-two tree fits the displayed training observations directly, without a bootstrap. Move the unlabelled query and inspect its actual prediction.
Bootstrap samples
Each tree draws sixty training indices with replacement. Repeated indices count more than once; omitted rows are out of bag for that tree. Feature count also changes the original shared random stream.
Combine votes
Each forest tree contributes one hard class vote. Equal totals select A. More trees can change either validation direction; a vote fraction is not a calibrated probability.
First AdaBoost round
Weighted Gini fits a tree to the same rows. Its weighted error sets a signed vote coefficient; normalised exponential updates shift the next round’s fitting weights.
AdaBoost history
Inspect every accepted round’s error, coefficient, weights and prefix scores. The full model uses all accepted learners. A finite round budget is not convergence, and validation never decides when fitting stops.
Reference
- Bootstrap
- n replacement draws from n training indices. A named row is omitted with probability (1−1/n)^n.
- Tree rule
- Weighted Gini, midpoint candidates, ≤ goes left, minimum parent two/child one, lowest-label majority ties; legacy zero-gain growth retained.
- Forest vote
- Each tree supplies one hard label. Ties choose A. These are not averaged leaf probabilities.
- Binary AdaBoost
- F₀=0; y,h ∈ {−1,+1}; ε=Σwᵢ1[hᵢ≠yᵢ]; a=ν·½log((1−ε)/ε); F←F+a·h.
- Weight update
- wᵢ←wᵢexp(−a yᵢhᵢ)/Z. Mean training exponential loss is mean exp(−yᵢFᵢ).
- Numerical stops
- Reject error ≥½ within 10⁻¹² tolerance. Errors below 10⁻¹² use that coefficient floor; exact zero retains the learner, updates and stops. Round budget is not convergence.
- Evaluation
- Independent generated validation draw reused for exploration; no validation fitting, OOB score or untouched final test.
Break it on purpose
Load twenty depth-one AdaBoost rounds on the original four-cluster draw. Compare its training and exploratory validation accuracy, then change depth alone. A signed sum of stumps is additive in x and y; it cannot classify all four ideal XOR corners correctly. A validation gap alone does not prove memorisation or mathematical variance.
Explore next
- Decision TreesEach question divides the training observations reaching one node; leaf votes turn those questions into predictions.
- Bias–variance trade-offA more flexible curve can follow the signal better while becoming more sensitive to the particular training sample.
- Learning CurvesA learning curve measures what changes when the same fitting rule receives more observations; its shape is evidence about this experiment.
- Train/Test Split & CVA held-out score is only as honest as the split and fitting procedure behind it.