Skip to main content icon/video/no-internet

Cross-validation is a data-dependent method for estimating the prediction error of a fitted model or a trained algorithm. The basic idea is to divide the available data into two parts, called training data and testing data, respectively. The training data are used for fitting the model or training the algorithm, while the testing data are used for validating the performance of the fitted model or the trained algorithm on predication purpose.

A typical proportion of the training data might be roughly 1/2 or 1/3 when the data size is large enough. The division of the data into training part and testing part can be done naturally or randomly. In some applications, a large enough subgroup of the available data is collected independently of the other parts of the data by different people or institutes or through different procedures but for similar purposes. Naturally, that part of the data can be extracted and used for testing purpose only. If such a subgroup does not exist, one can randomly draw a predetermined proportion of data for training purposes and leave the rest for testing.

K-Fold Cross-Validation

In many applications, the amount of available data is not large enough for a simple cross-validation. Instead, K-fold cross-validation is commonly used to extract more information from the data. Unlike the simple training-and-testing division, the available data are randomly divided into K roughly equal parts. Each part is chosen in turn for testing purposes, and each time the remaining (K1) parts are used for training purposes. The prediction errors from all the K validations are collected, and the sum is used for cross-validation purposes.

In order to formulate the K-fold cross-validation using common notations, suppose the available data set consists of N observations or data points. The ith observation includes predictor(s) xi in scalar (or vector) form and response yi, also known as input and output, respectively. Suppose a random partition of the data divides the original index set {1,2,,N} into K subsets I(1),I(2),,I(K) with roughly equal sizes. For the kth subset, let f^k() be the fitted prediction function based on the rest of the data after removing the kth subset. Then the K-fold cross-validation targets the average prediction error defined as

CV=1Nk=1KiI(k)L(yi,f^k(xi)).

In the aforementioned expression, CV is average prediction error, L(·,·) is a predetermined function, known as the loss function, which measures the difference between the observed response yi and the predicted value f^k(xi). Commonly used loss functions L(y,f^) include the squared loss function (yf^)2; the absolute loss function |yf^|; the 0−1 loss function, which is 0 if y=f^ and 1 otherwise; and the cross-entropy loss function 2logP^(Y=yi|xi), when a predicted probability is available.

The result CV of K-fold cross-validation depends on the value of K used. Theoretically, K can be any integer between 2 and the data size N. Commonly used values of K include 5 and 10. Generally speaking, when K is small, CV tends to overestimate the prediction error because each training part is only a fraction of the full data set. As K gets closer to N, the expected bias tends to be smaller, while the variance of CV tends to be larger because the training sets become more and more similar to each other. In the meantime, the cross-validation procedure involves more computation because the target model needs to be fitted for K times. As a compromise, 5-fold or 10-fold cross-validation would be suggested.

...

  • Loading...
locked icon

Sign in to access this content

Get a 30 day FREE TRIAL

  • Watch videos from a variety of sources bringing classroom topics to life
  • Read modern, diverse business cases
  • Explore hundreds of books and reference titles

Sage Recommends

We found other relevant content for you on other Sage platforms.

Loading