Before we start, let us make sure every symbol on this page is earned.
Look at the figure: the horizontal strip is your whole dataset D. One coloured box is the test fold (Fi); the rest are the training folds (Ti). As i moves from 1 to K, the coloured box slides along — that is the entire algorithm in one picture.
WHAT: Each fold is an equal pile, so it holds N/K samples.
KN=4200=50 samples per fold.WHY that many models: In K-fold we train one model per fold (each fold takes a turn as the test set). So the number of models trained equals K=4.
Answer:50 samples per fold, 4 models trained.
Recall Solution 1.2
False. In any single iteration i, the folds are disjoint: the test fold Fi is completely removed from training (Ti=D∖Fi, i.e. "all of D except box i"). A point is either being tested or being trained on in that iteration — never both at once. (Across different iterations a point is used for both, just not simultaneously.)
Recall Solution 1.3
K=N means each fold has exactly one sample (N/K=N/N=1). Testing on one point at a time, using all N−1 others to train, is called Leave-One-Out Cross-Validation (LOOCV). Note this is the largest legal K, since K≤N.
Sum =0.0050. Divide by K=4: 0.0050/4=0.00125. Take the square root:
SDfolds=0.00125≈0.0354.Answer:SDfolds≈0.035, so the model is 85.0%±3.5%.
Recall Solution 2.3
Each fold = N/K=1000/10=100 test samples. Training uses the other K−1=9 folds:
train size=N−KN=1000−100=900.
Fraction =KK−1=109=0.90=90%.
Answer:900 training samples, 90% of the data.
Compute the spread. Model A's scores hug 0.85 tightly; Model B swings from 0.60 to 0.99.
Model A SDfolds: deviations −0.01,0,0.01,0,0 → sum of squares =0.0002 → 0.0002/5=0.00004 → SDA=0.00004≈0.0063.
Model B SDfolds: deviations −0.15,0.14,−0.25,0.13,0.13 → squares 0.0225,0.0196,0.0625,0.0169,0.0169 → sum =0.1384 → /5=0.02768 → SDB=0.02768≈0.166.
Interpretation: same average, but SDB≈26×SDA. Model B is wildly sensitive to which data it trains on — a red flag (unstable model or non-representative folds). Trust Model A: consistent scores mean the 0.85 estimate is reliable.
Recall Solution 3.2
The core idea: more training data usually → better model.
K=3: each CV model trains on KK−1N=32⋅1000≈667 samples. That is far short of the final 1000, so those models are weaker than the deployed one → the reported score underestimates true performance. That downward gap is the bias.
K=10: each CV model trains on 900 samples — much closer to 1000 → its performance closely mirrors the final model → less bias.
Trade-off summary: larger K shrinks bias but averages over noisier, more-overlapping training sets (higher variance) and costs K trainings.
Recall Solution 3.3
The failure: random splitting could dump many/all of the 10 class-B points into just one or two folds. A validation fold with zero class-B points can only measure class-A accuracy — the minority class is invisible, so the score is misleading (a model that ignores class B could still look "good").
The fix — stratified K-fold: keep each fold at the same 90:10 ratio as the whole set. For K=5: each fold gets 90/5=18 class-A and 10/5=2 class-B samples. Now every validation fold contains both classes and truly represents the data distribution.
ShuffleD once, then split it into 5 folds and fix that split.
For each setting (say H1 and H2):
a. For each fold i: train the model with that setting on the other 4 folds.
b. Do all preprocessing (scaling, imputing) fitted on the training folds only, then apply to Fi.
c. Record scorei.
d. Compute CV5 for that setting.
Pick the setting with the higher CV5.
Retrain that chosen setting on all data for deployment.
The classic leak: fitting the scaler / choosing the hyperparameter using information from the validation fold (e.g. normalizing the whole dataset before splitting). Preprocessing statistics must be learned inside each training fold only.
Recall Solution 4.2
Split each class into 5 equal parts:
Class A: 100/5=20 per fold.
Class B: 20/5=4 per fold.
One fold Fi:20 A +4 B =24 samples, preserving the 100:20=5:1 ratio.
Training size per model:N−∣Fi∣=120−24=96 samples (which is 20×4 A +4×4 B =80 A +16 B — still 5:1).
Answer: each fold =24 samples (20A/4B); each model trains on 96 samples.
LOOCV means K=N=5 folds, one point each. The per-fold "score" here is the squared error.
CV5=54+1+9+0+1=515=3.0.Fold spread: deviations from 3.0: 1,−2,6,−3,−2. Squares: 1,4,36,9,4, sum =54. Divide by K=5: 10.8. Square root:
SDfolds=10.8≈3.286.Answer: LOOCV MSE =3.0, SDfolds≈3.29. The large spread relative to the mean warns that with only 5 points the estimate is very shaky — exactly the "maximum variance" LOOCV is known for.
Recall Solution 5.2
When the scaler's mean/standard-deviation are computed on the full dataset, each validation fold's statistics have already influenced the numbers the model trains on — the model gets a subtle hint about the test data. This inflates performance, so 91% is optimistically biased. The corrected pipeline (fit scaler on training folds only, apply to the held-out fold) removes that hint and gives an honest 86%. Publish 86% — it estimates true generalization. Reporting 91% would over-promise and the model will underperform in production.
Recall Solution 5.3
Each strategy trains K models, so total time =K×2 minutes.
(a) K=5: 5×2=10 minutes.
(b) K=10: 10×2=20 minutes.
(c) LOOCV, K=N=500: 500×2=1000 minutes ≈16.7 hours.
Rule: cost grows linearly in K. LOOCV's tiny bias rarely justifies a 50×–100× cost jump, so K=5 or K=10 is the default; reserve LOOCV for very small datasets where every sample is precious.
Recall Quick self-check (cloze)
The two aggregation formulas are CVK= ::: K1∑i=1Kscorei (the mean of fold scores).
Each K-fold model trains on a fraction ::: KK−1 of the data.
LOOCV corresponds to K= ::: N (one sample per fold; the largest legal K).
Before splitting into folds you should always ::: shuffle the data once (so sorted data does not bias the folds).
A large fold spread with a good mean means ::: the model is unstable across folds — do not trust the single number.
Fitting a scaler on the whole dataset before splitting causes ::: data leakage (optimistically biased scores).