2.6.5 · D5Model Evaluation & Selection

Question bank — Stratified and leave-one-out cross-validation

2,140 words10 min readBack to topic

This page is a question bank for the ideas in the parent note. Each line is a trap. Read the left side, answer out loud, then reveal the right side. The answers are reasoning, not "yes/no" — that reasoning is the whole point.

First, a shared vocabulary so no term is used before it is anchored:

Two pictures ground everything below. The first shows why random splitting is dangerous and stratified splitting is safe; the second shows why LOOCV has high variance.

Figure — Stratified and leave-one-out cross-validation

Look at the top row (random split): one fold caught zero red (minority) rows — that fold's metric is worthless. The bottom row (stratified split): every fold carries the same red-to-black ratio as the full bar on the left.

Figure — Stratified and leave-one-out cross-validation

The red overlap band shows that any two LOOCV training sets share rows. Nearly-identical training sets make nearly-identical mistakes → correlated errors → the averaged estimate stays jittery (high variance).


True or false — justify

Stratified CV changes the model's training algorithm.
False. It only changes which rows land in which fold. The learner, its loss, and its hyperparameters are untouched — stratification is a splitting rule, not a training rule.
Stratified CV can be applied to regression targets exactly as to classification labels.
False as stated. "Class" needs discrete labels. For regression you must first bin the continuous target into buckets (e.g. quantile bins), then stratify on the buckets — otherwise "same class distribution" is undefined.
If every fold has the same class proportion as the whole dataset, then every fold's training set also has that proportion.
True. The training set is the union of the other folds; a union of pieces that each carry proportion also carries . Both test and train mirror the original (see the parent's medical example: 95% healthy in each).
LOOCV always gives lower test-error variance than 5-fold CV.
False. LOOCV has low bias but often high variance, because its training sets overlap in samples (figure s02), making the error terms highly correlated. Correlated errors don't average away.
LOOCV is guaranteed to be more accurate than 10-fold CV.
False. "More data per fit" lowers bias, but the high variance can make a single LOOCV number noisier as an estimate. Accuracy of the estimate is bias and variance together.
Stratified 5-fold CV and plain 5-fold CV cost the same in compute.
True. Both train exactly models on rows each. Stratification only reorders which rows go where — no extra fits.
For a perfectly balanced dataset (50/50), stratified and random splitting give each fold the same class proportions.
False in general. In expectation each fold is 50/50, but a single random split can still drift (e.g. 55/45 in one fold). Stratification pins every fold to 50/50 exactly; balance only shrinks how big the random drift typically is. (This is about fold proportions, not about a particular model's metric.)
LOOCV with samples performs training runs.
True. Each of the rows is held out exactly once, so there are folds and fits — this is why LOOCV is expensive for large .
Increasing toward always reduces the bias of the CV error estimate.
True (as a trend). Larger means each training set is a larger fraction of the data, so each fitted model is closer to the final full-data model, shrinking bias.
Stratified CV removes class imbalance from the dataset.
False. It preserves imbalance faithfully in every fold. Fixing imbalance is a different job — see 3.2.05-Handling-imbalanced-classes. Stratification just stops random splits from worsening it.

Spot the error

"We have 950 healthy and 50 diseased. In random 10-fold CV each fold will contain about 5 diseased patients, so stratification is unnecessary."
Error: "about 5" is only the average. Random draws fluctuate; some folds can get 0 or 1 diseased (top row of figure s01). The whole point (parent's disaster case) is that the minority count is small enough for a fold to miss the class.
"To stratify, I shuffle all rows, then cut into equal blocks."
Error: That is plain k-fold. Stratifying requires splitting within each class first (all classes), then combining one sub-group per class into each fold. Blind shuffling doesn't lock the proportions.
"LOOCV has zero bias, therefore its error estimate equals the true test error."
Error: Bias means the expected estimate is near the truth. Any single LOOCV run can still be far off due to high variance. Low bias low error on one run.
"Since LOOCV trains on samples, the model it validates is a different model from my final one, so the estimate is biased."
Error: is almost identical to , so the validated model is essentially the final model — this is precisely why LOOCV bias is near zero, not why it's biased.
"I stratified on the target, so my time-series CV is now valid."
Error: Stratification ignores order. For time series you must not let future rows train a model tested on the past — that needs 5.4.02-Time-series-cross-validation, not stratification.
"Each fold in stratified CV has exactly samples of class ."
Error: Only when is divisible by . Otherwise folds carry or — a rounding wobble the parent notes explicitly. Here is the count of class (see vocabulary).

Why questions

Why can a random fold end up with zero minority samples?
Because each minority row independently "misses" a fold with probability ; for a small count the chance all of them miss, , is non-trivial (e.g. for ).
Why does stratification make validation metrics more reliable, not just prettier?
Because a fold that reflects the true 5% positive rate produces a metric measured under realistic conditions; a fold with 0% positives measures nothing about the model's ability on positives, so its "accuracy" is meaningless.
Why do LOOCV's error terms end up correlated?
Any two of its training sets share of the same rows (figure s02), so they fit almost the same model and make almost the same mistakes — their errors move together instead of independently.
Why does correlation between fold-errors raise the variance of the averaged estimate?
Averaging kills variance only when terms are independent. Correlated terms don't cancel each other's fluctuations, so the mean stays jittery — high variance survives the averaging.
Why is stratified CV especially tied to 3.2.05-Handling-imbalanced-classes?
Imbalance is exactly when random splits break: the rare class is fragile. Stratification is the first line of defence that guarantees the rare class appears in train and test of every fold.
Why does the parent frame LOOCV as the "limit" of k-fold rather than a separate method?
Because it is k-fold with — same averaging formula , just the extreme setting. Seeing it as a limit explains its low-bias/high-variance profile via the 2.6.04-Bias-variance-tradeoff-in-cross-validation.

Edge cases

What happens to stratified CV if a class has fewer than samples?
You cannot place one member in every fold — some folds get zero of that class no matter what (our class C with dies at ). The stratification guarantee breaks; you must lower or merge/handle that rare class first.
With many classes of varying rarity (say , some with 3 rows, some with 500), how do you assign folds?
Stratify class by class: split each into near-equal sub-groups and take one per fold. The binding constraint is the rarest class — must satisfy , or the rare classes can't spread across all folds.
How would you stratify a continuous (regression) target?
There are no classes to copy, so you manufacture them: cut the target into quantile bins (each bin holds an equal count), then stratify on the bin labels. This "quantile-based folding" keeps each fold's target distribution — not just its mean — close to the whole.
Can you stratify a multi-label target (each row carries several labels at once)?
Not with the simple per-class recipe, because label combinations overlap. Specialized iterative stratification algorithms greedily place rows to balance every label's proportion simultaneously; plain single-label stratification would break some labels while fixing others.
What does LOOCV cost when ?
One million model fits, each on rows — usually infeasible. This is why LOOCV is reserved for small (or models with closed-form leave-one-out shortcuts).
For a 50/50 balanced, huge dataset, is stratification worth it?
The benefit is tiny (random drift is small when both and balance are large), but the cost is also ~zero, so it's harmless and still the safe default.
If every sample is identical in features but labels split 70/30, does stratification help the model learn?
No — the model can't separate identical inputs. Stratification still balances the folds, but it fixes split fairness, never the underlying learnability of the data.
With only 2 classes and (LOOCV), can each single-row test fold be "stratified"?
No. A one-row fold holds one label, so it can never mirror a 70/30 ratio. Stratification is meaningful only when folds are large enough to hold a mix — it and LOOCV pull in opposite directions.
Does stratified CV protect you if your data was collected with a sampling bias?
No. It preserves whatever distribution the data has, bias included. Fixing collection bias is upstream work — see 2.3.08-Sampling-methods; CV cannot repair a skewed sample.
Recall Quick self-test

One-fold-missing-a-class probability formula ::: — the chance all minority rows avoid a given fold. LOOCV bias vs variance in one phrase ::: near-zero bias, often high variance from overlapping training sets. The one thing stratification never changes ::: the actual class imbalance — it copies it, it doesn't cure it. Constraint on for stratified CV with rarest class count ::: , else some folds miss the rarest class.