The procedure for k-fold cross-validation
Every sample is used for testing exactly once and for training k−1 times. The score you report is the average over the k held-out folds.
The rotation
Each row is one round of training. Click a row, or press Play, to follow one round.
Shuffle once, cut the shuffled samples into k equal slices, then rotate which slice is held out. Scores shown are simulated AUCs for illustration.
What happens inside one round
Nested cross-validation, for tuning and evaluating
When you also choose a hyperparameter (for PRS, the p-value threshold PT), the choice must happen inside the outer training set. The inner loop picks PT; the outer fold only grades that choice.
Leakage: the same steps in the wrong order
Leaky
Correct
In genetic data, also keep relatives in the same fold (grouped k-fold), and stratify by case/control status so each fold has a similar ratio.
Created with the assistance of Claude and reviewed by the author. The AUC values shown are simulated and for illustration only.