Cross-validation estimates test error by rotating which part of the data is held out: k-fold, leave-one-out (k = n), the number of fits each needs, their bias and variance, and how to use them for model selection without leakage.
The worked examples run LOO on nearest-neighbour and mean / least-squares predictors.
Concept notes
1. Why hold out data
Training error underestimates test error because the model has already seen the points. To estimate generalisation:
Hold-out (validation set) method: split once into training and validation parts (say 70/30), fit on one, measure error on the other. Simple, but the estimate depends on which points land where, and the model is trained on less data.
Train / validation / test: use the validation data to choose hyperparameters (, , depth, ) and the test data, touched only once at the end, to report final performance. Choosing anything using the test set makes the reported test error optimistic.
Cross-validation reuses the data more efficiently: every point is used for validation exactly once and for training in the other rounds.
Data leakage is the most common CV mistake: any step that learns from data (standardisation means and variances, feature selection, imputation, PCA) must be fitted inside each training fold only, then applied to that round's validation fold. Fitting it on the whole dataset first lets validation information leak into training.
For time-ordered data, folds must respect time (train on the past, validate on the future); random shuffling would leak the future.
2. k-fold cross-validation
Procedure:
Shuffle and split the points into roughly equal folds.
For : train on the other folds, compute the error on fold .
Report the CV error (or the size-weighted average if folds differ in size).
Each round trains on about points and validates on .
Cost: model fits per hyperparameter setting. A grid of settings costs fits, plus one final refit on all the data with the chosen setting.
Stratified k-fold keeps the class proportions of the whole dataset in every fold; use it for classification, especially with imbalanced classes.
Common choices are or : each model sees 80–90% of the data, so the estimate is only slightly pessimistic, and the cost stays moderate.
After choosing a hyperparameter by CV, refit on the full training data with that setting. The CV error of the winning setting is slightly optimistic because it was selected as the minimum; nested CV (an inner CV for tuning inside an outer CV for evaluation) gives an honest estimate.
5-fold cross-validation: each fold is the validation set once
3. Leave-one-out cross-validation (LOO)
LOO is k-fold with : each round leaves out a single point, trains on the remaining and tests on the one left out.
where is trained without point .
Deterministic: there is no random split, so the answer is unique.
Nearly unbiased: each model uses points, almost the full data.
Higher variance as an estimate: the training sets overlap almost completely, so the errors are highly correlated and their average does not settle as much as you might expect.
Expensive: fits in general.
Shortcut for least squares: for linear regression (and ridge, with its own hat matrix) the LOO residual is
where is the ordinary residual and the leverage, so LOO costs one fit. For the mean predictor () this gives LOO residuals .
LOO with kNN is cheap too: just find each point's nearest neighbours among the others.
4. Choosing k and using CV well
Hold-out
k-fold ()
LOO ()
Fits
1
Training size
e.g. 70%
Bias of estimate (pessimism)
highest
small
lowest
Variance of estimate
high (one split)
moderate
can be high
Randomness
yes
yes
none
So increasing reduces the bias of the error estimate (bigger training sets) but costs more and can increase its variance.
Using CV for model selection:
Compute the CV error for each candidate (each , , depth, kernel) and pick the lowest. A common rule is the one-standard-error rule: choose the simplest model whose CV error is within one standard error of the best.
Use the same folds for all candidates so that comparisons are fair.
CV estimates the error of the procedure (model family + tuning) on data of this size, not of one particular fitted model.
Bootstrap is a different resampling method: draw points with replacement; about of distinct points appear, and the rest (out-of-bag) can be used for validation.
Formulas to remember
k-fold CV error
LOO CV error
Training size per round
Fits for a grid search hyperparameter settings, folds
LOO shortcut for least squares
Bootstrap distinct fraction
Common mistakes
Fitting scaling, imputation or feature selection on the whole dataset before CV (data leakage).
Using the test set for model selection and then reporting its error as unbiased.
Counting fits as in total when there are several hyperparameter values; it is .
Saying LOO always has the lowest variance; it has the lowest bias, but its estimate can be quite variable.
Shuffling time-series data into random folds, which lets the model see the future.
Worked examples
Try each step yourself, then reveal the working.
Example 1: LOO error of the mean predictor
numerical
Targets . The model predicts the mean of its training targets. Find the LOO mean squared error.
Step 1: Leave out each point and predict.
Try it on paper first.
Example 2: LOO error of 1-NN
numerical
One-dimensional labelled points: 1 (A), 2 (A), 4 (B), 5 (B), 7 (A). Find the LOO error rate of the 1-nearest-neighbour classifier.
Step 1: Classify each point using the others.
Try it on paper first.
Example 3: Cost and fold sizes
numerical
points, 10-fold CV, and 8 candidate values of . How many points train each model, how many fits are needed, and how would LOO compare?
Step 1: Fold sizes.
Try it on paper first.
Example 4: Spot the leakage
conceptual
An analyst standardises all 1,000 rows, selects the 20 features most correlated with the label using all rows, and then runs 5-fold CV on a classifier. The CV accuracy is 95% but the model does poorly on new data. Why?
Step 1: Find the steps that used labels or statistics from all rows.
Try it on paper first.
Previous year questions
1 official GATE DA question on this topic, newest first.
9 questions: up to 1 official PYQs and original practice questions, with GATE marking (MCQ wrong answers lose marks). Score 60% or more to pass. A new set is drawn each time.
Mark as mastered
Loading your progress…
My revision notes
Notes written by the GATEiit team against the official GATE DA syllabus; being checked by a reviewer. Updated 2026-11-21. Spotted a mistake? Use Report an issue on any question, or contact us.