Leave-one-out cross-validation

Also known as: LOOCV

On this page 6

Leave-one-out cross-validation (LOOCV) is a resampling method that estimates how well a model generalizes by training it n times on n minus one observations and testing it each time on the single observation left out. In model evaluation, it is the extreme case of k-fold cross-validation in which the number of folds equals the number of samples.

Because every observation serves once as a test case and the training sets are almost the full dataset, LOOCV gives an almost unbiased estimate of generalization error. That property makes it attractive for small datasets in fields such as medicine, chemistry and genomics, where every sample is expensive. The price is computational cost and, for some models and metrics, a high-variance estimate.

How leave-one-out cross-validation works

LOOCV follows a simple and fully deterministic procedure. Given a dataset of n observations, the model is fitted n separate times. In iteration i, observation i is removed, the model is trained on the remaining n minus one observations, and its prediction for observation i is recorded. After all iterations, the n individual errors are averaged into one performance estimate.

  1. Select observation i as the single held-out test case.
  2. Train the model on all other observations, repeating every preprocessing step inside this loop.
  3. Predict observation i and record the error or the predicted label.
  4. Repeat for every observation and average the n errors.

Unlike k-fold cross-validation with random splits, LOOCV has no randomness in the partitioning: every run on the same data produces the same result. This reproducibility is useful in regulated settings and in published comparisons, where reviewers expect identical numbers when an analysis is repeated.

Bias, variance and computational cost

The central trade-off of LOOCV is low bias against high variance and high cost. Each training set contains n minus one observations, so the fitted models are nearly as good as a model trained on all data, and the estimate is only slightly pessimistic. However, the n training sets overlap almost completely, so the n errors are strongly correlated, and their average can vary considerably from one dataset to another.

The table below compares LOOCV with common alternatives on these properties.

MethodModel fitsBias of estimateVariance of estimate
Leave-one-out cross-validationnVery lowOften high
10-fold cross-validation10LowModerate
5-fold cross-validation5ModerateLower
Single holdout split1HigherHigh, depends on the split
Bootstrap (.632)Typically 100 or moreLowLow
LOOCV compared with other validation methods

Computational cost grows linearly with n, which becomes prohibitive for large datasets or expensive models such as deep neural networks. For certain models, however, LOOCV is almost free. In ordinary least squares and ridge regression, the leave-one-out residual can be computed from a single fit using the diagonal of the hat matrix, and the same idea underlies generalized cross-validation and fast LOOCV for Gaussian processes and kernel methods.

When to use LOOCV

LOOCV is the right choice when data are scarce and model fitting is cheap. With 30 or 60 samples, removing a fifth of the data for each fold of 5-fold cross-validation noticeably weakens every fitted model, while LOOCV keeps the training sets as large as possible. For thousands of samples, 5-fold or 10-fold cross-validation gives similar conclusions at a fraction of the cost.

SituationRecommended methodReason
Fewer than about 100 samples, cheap modelLOOCVMaximizes training data per fit
Linear or ridge regression of any sizeClosed-form LOOCVExact result from one fit
Thousands of samples5-fold or 10-foldSimilar accuracy, far lower cost
Imbalanced classesStratified k-fold cross-validationPreserves class ratios in each fold
Hyperparameter tuning and evaluation togetherNested cross-validationAvoids optimistic selection bias
Grouped or time-ordered dataLeave-one-group-out or forward chainingPrevents leakage between related samples
Choosing a validation strategy

LOOCV also fits naturally into model selection for small studies, for example choosing the number of neighbors in k-nearest neighbors or the regularization strength in a ridge model. When it serves both selection and final reporting, the reported score is optimistic, and nested cross-validation is the correct remedy.

Pitfalls and common misconceptions

Most LOOCV errors come from data leakage and from metrics that do not work on single samples. Because each test set contains one observation, metrics such as AUC, precision or F1 cannot be computed per fold; they must be computed once on the pooled out-of-fold predictions. Averaging per-fold accuracy is valid, but it hides the correlation between folds.

MistakeConsequenceCorrect practice
Scaling or feature selection on all dataOptimistic error estimateRepeat preprocessing inside each fit
Duplicate or repeated measurementsNear-copies leak into trainingLeave out whole subjects or groups
Per-fold AUC or F1Undefined or meaningless valuesCompute metrics on pooled predictions
Reporting tuning score as finalInflated performanceUse nested cross-validation
LOOCV mistakes and their consequences
  • LOOCV is not always the most accurate estimator: its variance can exceed that of 10-fold cross-validation, especially for unstable learners such as decision trees.
  • Classification with a majority-class rule can behave paradoxically, because removing one sample shifts the class balance against that sample.
  • LOOCV does not create new information: on a tiny dataset, a precise-looking estimate still carries wide uncertainty.

Understanding it simply

Imagine a teacher with only twenty practice questions. She wants to know how well a student really understands the topic. So she hides one question and lets the student study the other nineteen. Then she asks the hidden one. She repeats this twenty times, hiding a different question each time.

The final score is the share of hidden questions answered correctly. Leave-one-out cross-validation tests a model the same way. It is thorough and fair for small datasets, but it takes as many rounds as there are examples.

Applied in practice

A hospital research group builds a model that predicts whether a rare tumor type responds to a specific therapy, using 48 patients and twelve biomarker measurements. Splitting off a 20 percent test set would leave only about ten patients for testing and weaken the training set, so the team evaluates a regularized logistic regression with LOOCV.

For each of the 48 iterations, the team standardizes the biomarkers using only the 47 training patients, fits the model and predicts the held-out patient. The 48 out-of-fold predictions are pooled to compute an AUC of about 0.81 and a calibration plot. Because the regularization strength was also chosen by cross-validation, the group repeats the analysis with nested cross-validation, obtains a slightly lower AUC, and reports that more conservative figure together with its confidence interval before planning a larger validation study.