Cross-validation
Cross-validation evaluates each development fold with a model fitted on the other folds.
On this page 8 sections
01Cross-validation estimates how a training procedure performs on data it did not fit#
Cross-validation estimates how a training procedure performs on data it did not fit. Split the training data into folds, fit on the other folds, and evaluate on the held-out fold. Rotating this role lets each record receive an out-of-fold evaluation.
Cross-validation rotates which development observations are held out. For each fold, fit a new model on the other folds and evaluate on that fold. The held-out predictions come from models that did not fit those observations.
For validation fold B, fit on A and C. Repeat with A and C held out in turn. Keep final test T outside this procedure.
With five folds, one run trains on four and evaluates on the remaining one. Repeat until each fold has been held out once. If fold sizes differ, an overall per-record loss weights each fold mean by its evaluation count; a simple average of fold means answers a different weighting question.
Development folds X={a,b}, Y={c,d}, Z={e,f}. Final test T. Validate X. Fit / validate blocks?
Show answer and explanation
Fit excludes X and T.
02This lesson reports pooled loss per validated observation#
This lesson reports pooled loss per validated observation. Add the validation loss totals, then divide by the number of validated observations. With fold counts 2 and 4 and loss totals 6 and 6, the pooled mean is .
Unequal fold sizes need their observation counts. The fold means above are 3 and 1.5; their unweighted mean 2.25 differs from the pooled mean 2. With equal fold sizes, the two averaging rules coincide.
Validation folds (n, loss total): (1,2), (3,6). Each fold excluded from its fit. Pooled mean per observation?
Show answer and explanation
Total 8 / count 4 = 2.
03A closer look#
Do not replace the aggregate with a favorable fold or use the final test to select settings. For time-dependent data, validation should reflect future observations; group-dependent data need suitable group separation. Random folds are not universal.
Validation folds (n, loss total): (2,4), (2,8). “CV=2: best fold.” Repair pooled mean per observation.
Show answer and explanation
Pool: 12/4=3.
04Any learned preprocessing belongs inside each training fold#
Any learned preprocessing belongs inside each training fold. Reusing a transformation fitted on every row gives the held-out fold influence over training. After selecting a procedure, a separate untouched test set can assess the full selection process.
Follow the supplied split roles, pool the requested validation losses using their counts, and preserve an untouched final test.
- Aggregate held-out validation losses under the stated fold scheme.
Sources & further reading
- [1]Scikit-learn User Guide, Cross-validation: Evaluating Estimator Performance ↗Scikit-learn developers · Article