liveBook · Manning

Cross-validation

As explained in Deep Learning with Python, Third Edition

A validation procedure that partitions data into K folds, trains on K−1 folds, and evaluates on the remaining fold in rotation.

A single validation split can give an unstable score when data is scarce: changing which examples enter validation may change the result substantially. K-fold cross-validation reduces that dependence by rotating validation across several partitions and averaging the scores. section 4.3.4 section 5.2.1

A four-fold regression check

Set k = 4 and divide the training data into four partitions. Train a fresh, identical model three times per fold, evaluate it on the held-out partition, and record the validation score. Scores of 0.298, 0.349, 0.232, and 0.305 average to 0.296, which is more reliable than choosing any one split. Repeating the process for 200 epochs produces a mean validation-MAE history; the curve stops improving significantly around epochs 120–140, so a final model is trained for 130 epochs before test evaluation. section 4.3.4

Use the procedure as a short practical checklist:

  • Choose K, commonly 4 or 5, and divide the available data into equal-sized folds. section 4.3.4
  • For each fold, hold it out for validation and concatenate the remaining folds into the training data. section 5.2.1
  • Instantiate a new model for every fold, train it, evaluate it, and average the resulting validation scores. section 4.3.4

How Deep Learning with Python, Third Edition covers it

How deep it goes
Implements fold construction, repeated training, score averaging, per-epoch histories, plotting, and practical epoch selection.
Examples
Uses four-fold scalar regression, validation MAE histories, epoch plots, and a final 130-epoch model.
What it assumes
Assumes model fitting and evaluation while emphasizing separate validation and never-before-seen test data.
What you can do after
Apply it via a model-training loop to obtain a more reliable validation estimate and guide training duration.
How it connects
Connects validation sets with hold-out validation, test sets, generalization, overfitting, and model training.

Also explained in

Compare how 12 books explain cross-validation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with Python, Third Edition. The section links point to the parts of the book it draws on.