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.
- Select observation i as the single held-out test case.
- Train the model on all other observations, repeating every preprocessing step inside this loop.
- Predict observation i and record the error or the predicted label.
- 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.
| Method | Model fits | Bias of estimate | Variance of estimate |
|---|---|---|---|
| Leave-one-out cross-validation | n | Very low | Often high |
| 10-fold cross-validation | 10 | Low | Moderate |
| 5-fold cross-validation | 5 | Moderate | Lower |
| Single holdout split | 1 | Higher | High, depends on the split |
| Bootstrap (.632) | Typically 100 or more | Low | Low |
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.
| Situation | Recommended method | Reason |
|---|---|---|
| Fewer than about 100 samples, cheap model | LOOCV | Maximizes training data per fit |
| Linear or ridge regression of any size | Closed-form LOOCV | Exact result from one fit |
| Thousands of samples | 5-fold or 10-fold | Similar accuracy, far lower cost |
| Imbalanced classes | Stratified k-fold cross-validation | Preserves class ratios in each fold |
| Hyperparameter tuning and evaluation together | Nested cross-validation | Avoids optimistic selection bias |
| Grouped or time-ordered data | Leave-one-group-out or forward chaining | Prevents leakage between related samples |
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.
| Mistake | Consequence | Correct practice |
|---|---|---|
| Scaling or feature selection on all data | Optimistic error estimate | Repeat preprocessing inside each fit |
| Duplicate or repeated measurements | Near-copies leak into training | Leave out whole subjects or groups |
| Per-fold AUC or F1 | Undefined or meaningless values | Compute metrics on pooled predictions |
| Reporting tuning score as final | Inflated performance | Use nested cross-validation |
- 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.