2.6.5 · D1Model Evaluation & Selection

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

2,086 words9 min readBack to topic

Before you can read the parent note, you need a toolbox. Below, every symbol and idea it uses is built from nothing — plain words first, then a picture, then why the topic needs it. Read top to bottom; each rung of the ladder stands on the one below.


1. A sample, and the pair

The picture: think of a spreadsheet. Each row is one sample. The left columns are , the last column is .

Why the topic needs it: cross-validation is entirely about which rows go into training and which go into testing. If you can't picture one row as , none of the splitting makes sense.

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

2. The dataset size

The picture: the height of the spreadsheet. 100 rows means .

Why the topic needs it: LOOCV literally sets the number of folds equal to . So is the number of times you retrain the model — the whole cost of LOOCV rides on this one letter.


3. Classes, and the counts

So if is either "cat" or "dog", then . If rows are cats and are dogs, then (cats) and (dogs).

Why appears: the parent writes . The symbol (capital Greek "sigma") means "add these up". The little underneath and on top mean "let run from 1 up to , and add every ." In words: the counts of all classes add up to the total number of samples. Of course they do — every row belongs to exactly one class.

Why the topic needs it: stratification is all about keeping each class's share fixed. You cannot talk about "keeping the mix" without a symbol for "how many of each kind."


4. Class proportion

The picture: a pie chart. If of rows are class 0, that slice is , i.e. of the pie.

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

Why the topic needs it: the whole promise of stratified CV is "every fold has the same as the full dataset." is the quantity we protect. Every proportion is between and , and all of them add to (the full pie).


5. Folds: cutting the deck into piles

The picture: shuffle a deck of cards, deal them into piles. Each round, one pile is the test set (hidden) and the other piles glued together are the training set.

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

Why the topic needs it: k-fold, stratified, and LOOCV are all the same recipe with different . LOOCV is just : as many piles as cards, so each pile is a single card. Understanding "fold = one pile you take turns hiding" unlocks the entire family. See 2.6.03-K-fold-cross-validation for the base recipe this builds on.


6. Set language: , , , and

The parent note groups samples with set notation. A "set" is just a collection of things — think of a labelled box.

The picture: two overlapping circles (a Venn diagram). Union = the whole shaded blob; intersection = only the lens where they overlap.

Why the topic needs it: stratification builds a fold by taking one small sub-box from each class and pouring them together — that is exactly . And to check "how many class- samples are in fold " the parent writes : the count of the overlap between fold and class .


7. Floor and ceiling: and

When doesn't divide evenly by , you can't put a whole number of samples in each sub-fold. The parent handles this with floor and ceiling.

The picture: a number line. sits between two integers; floor slides left to the integer below, ceiling slides right to the integer above.

Why the topic needs it: if and , then . Some sub-folds get , others get . That is what the parent's "" means — you can't split people into fractions.


8. The model and the "leave-one-out" superscript

Why the topic needs it: this is the heart of LOOCV. The whole point is honesty — you test the model on a sample it was never trained on. The superscript is the notation that guarantees this honesty.


9. Error, loss , and the average

Worked mini-check (from the parent's example): sample 1 has , prediction . Then

The picture: dots on a number line (the errors); is their balance point.

Why the topic needs it: one error tells you almost nothing (bad luck on one sample). Averaging over all samples turns luck into a reliable estimate of real-world error.


10. Bias, variance, expectation , and covariance

The parent's cost/accuracy discussion needs three probability words.

The picture: a dartboard. Bias = distance of the cluster's centre from the bullseye. Variance = spread of the darts. See 2.6.04-Bias-variance-tradeoff-in-cross-validation.

Why the topic needs it: LOOCV's training sets overlap in samples, so their errors are highly correlated (large covariance). That correlation is exactly why LOOCV has near-zero bias but high variance — the parent's punchline.


Prerequisite map

Sample x and y

Dataset size n

Classes and counts n_i

Proportion p_i

Folds and k

Stratified CV

LOOCV k equals n

Set language union and count

Floor and ceiling

Model f-hat and leave-one-out

Loss and average

Bias variance covariance

Stratified and LOOCV topic


Equipment checklist

Cover the right side and answer aloud. If any stumps you, reread its section above.

What does the pair stand for in one sample?
= the inputs/features, = the label/answer to predict.
What does count?
The total number of samples (rows) in the dataset.
Read in plain words.
Add up the counts of all classes; they total the whole dataset .
What is and what shape pictures it?
The fraction of data that is class , — a slice of a pie chart.
In k-fold, how big is one fold and how much is left for training?
One fold has samples; the other folds ( of the data) train the model.
What does mean versus ?
Union = everything in or ; intersection = only what and share.
Compute and .
Floor = 6 (round down), ceiling = 7 (round up).
What does the superscript in promise?
The model was trained on every sample except sample , so testing on is honest.
With squared-error loss, what is when , ?
.
Bias vs variance on a dartboard?
Bias = how far the dart cluster's centre sits from the bullseye; variance = how scattered the darts are.