the idea is to make multiple identical copies of the data setand to partition each copy into different training and test setsas illustrated in figure herethere are four copies of the data set (consisting of response and explanatory variableseach copy is divided into test set (colored blueand training set (colored pinkfor each of these setswe estimate the model parameters using only training data and then predict the responses for the test set the average loss between the predicted and observed responses is then measure for the predictive power of the model figure an illustration of four-fold cross-validationrepresenting four copies of the same data set the data in each copy is partitioned into training set (pinkand test set (bluethe darker columns represent the response variable and the lighter ones the explanatory variables folds -fold cross-validation in particularsuppose we partition data set of size into folds ck of sizes nk (hencen nk ntypically nk /kk let `ck be the test loss when using ck as test data and all remaining datadenoted - as training data each `ck is an unbiased estimator of the generalization risk for training set - that isfor `(gt- the -fold cross-validation loss is the weighted average of these risk estimatorscvk nk = `ck (gt- xx loss(gt- (xi )yi = ic = loss(gt- ( (xi )yi )where the function { { kindicates to which of the folds each of the observations belongs as the average is taken over varying training sets { - }it estimates the expected generalization risk `(gt )rather than the generalization risk `(gt for the particular training set example (polynomial regression (cont )for the polynomial regression examplewe can calculate -fold cross-validation loss with nonrandom partitioning of the training set using the following codewhich imports the previous code for the polynomial regression example we omit the full plotting code