IAE Academy

GATE DA

Bias–variance trade-off and cross-validation

Every model is judged by how well it does on data it has not seen, not on the data it was fitted to. This topic explains why training error misleads, how expected test error splits into bias, variance and noise, how cross-validation (k-fold and leave-one-out) estimates generalisation error and picks hyperparameters, and the common measures used to score a classifier.

2 previous-year questions · 2 solved · 7 practice questions

Training, validation and test error

A model is fitted on a training set. Its error there is the training error. What we actually care about is the generalisation error: the expected error on new data from the same distribution. We estimate it on data the model never saw during fitting.

Set

Used for

Can it be reused to tune the model?

Training

Fitting the parameters (weights, splits, centroids)

Yes, this is its purpose

Validation

Choosing hyperparameters and comparing models

Yes, but the more choices made on it, the more optimistic its error becomes

Test

One final, honest estimate of generalisation error

No. Using it for any choice spoils the estimate

Training error is usually lower than test error, because the parameters were chosen to make it small. Training error alone therefore cannot tell you whether a model is good. A very flexible model can reach zero training error and still predict badly.

EXAM TIP

A hyperparameter (the in -NN, the penalty , the tree depth, the polynomial degree) is not learned by minimising training error. Choosing it that way tends to pick the most flexible setting. It must be chosen on validation data or by cross-validation.

Underfitting and overfitting

Underfitting: the model is too simple to capture the true pattern. Training error is high, and test error is high and close to the training error. Overfitting: the model is so flexible that it fits the noise in the training set. Training error is very low, test error is much higher, and the gap between them is large.

Symptom

Training error

Validation/test error

Gap

Diagnosis

Both high

High

High

Small

Underfitting (high bias)

Low train, high test

Low

High

Large

Overfitting (high variance)

Both low

Low

Low

Small

Good fit

Typical remedies

  1. Underfitting: use a more flexible model, add useful features, reduce regularisation. More data of the same kind does not cure underfitting.

  2. Overfitting: get more training data, use a simpler model, increase regularisation, remove irrelevant features, stop training earlier.

EXAM TIP

As model complexity increases, training error generally falls. For nested models fitted by least squares it can never rise. Validation error is typically U-shaped: it falls, reaches a minimum, then rises. The best model sits near the bottom of the U.

The bias-variance decomposition

Suppose , where is noise with and . Let be the model learned from a random training set. At a fixed point , let be a new observation whose noise is independent of the training set. The expectation is over the random training set and the noise in this new . Squared-error loss is assumed throughout.

BIAS OF AN ESTIMATOR AT $X_0$

Systematic error: how far the average prediction over training sets is from the truth.

VARIANCE OF AN ESTIMATOR AT $X_0$

Sensitivity: how much the prediction changes from one training set to another.

BIAS-VARIANCE DECOMPOSITION OF EXPECTED SQUARED ERROR

Valid for squared-error loss, with zero-mean noise in the test response that is independent of the training data. The term is irreducible: no model can remove it.

For an estimator of a fixed parameter , the same idea gives the mean squared error: .

EXAM TIP

The decomposition has bias squared, not bias. A bias of contributes . All three terms are non-negative, so under these assumptions the expected test error at can never be below .

What moves bias and variance

The trade-off: making a model more flexible usually lowers bias and raises variance. Making it simpler does the opposite. Test error is smallest where the two balance. The table shows the usual direction of each change, not a guarantee for every dataset.

Change

Bias

Variance

Increase model complexity (higher polynomial degree, deeper tree, more hidden units)

Decreases

Increases

Increase regularisation strength (ridge, lasso, weight decay)

Increases

Decreases

Increase in -NN

Increases

Decreases

More training data (same model class)

Roughly unchanged

Decreases

More irrelevant features

Little change

Increases

Averaging many models trained on resamples (bagging)

Roughly unchanged

Decreases

Two points to remember. First, more data helps against variance, not against bias: a straight line fitted to curved data stays wrong however many points you give it. Second, regularisation deliberately accepts a small bias to buy a larger drop in variance.

RIDGE REGRESSION ESTIMATE

Convention: is with samples in its rows, holds the responses, and the weights. The bias (intercept) is not penalised: and each column of are centred first, so drops out and is recovered afterwards. For , is always invertible. gives ordinary least squares (when is invertible), the lowest-bias and highest-variance member of the ridge family. drives (high bias, low variance). The penalty depends on the scale of each feature, so features are usually standardised first.

EXPECTED SQUARED ERROR OF $K$-NN REGRESSION AT $X_0$

Holds when the training inputs are fixed and with independent zero-mean noise of variance . Here are the training inputs nearest to , and is the average of their values. The middle term is bias squared, which usually grows with as farther neighbours are averaged in. The variance falls as grows.

EXAM TIP

-NN with has zero training error when all training inputs are distinct (each point is its own nearest neighbour), and it has high variance. Do not confuse a small with a simple model: small is the flexible end.

Cross-validation: k-fold and leave-one-out

The simplest estimate is the hold-out (validation-set) method: split the data once, train on one part and measure the error on the other. It has two weaknesses. The estimate depends on which samples happen to land in the validation part, and the model trains on fewer samples, so its error tends to be pessimistic. Cross-validation (CV) reuses every sample for both training and validation, in turn, so that each sample is validated exactly once by a model that did not train on it.

$k$-fold cross-validation, in order

  1. Shuffle the samples and split them into folds of (nearly) equal size.

  2. For : train a model on the other folds and compute its error on fold .

  3. Report the average of as the CV estimate.

ERROR ON ONE FOLD (REGRESSION, SQUARED ERROR)

is the number of samples in fold , and is the prediction of the model trained without fold . For classification, is the misclassification rate on fold .

$K$-FOLD CV ESTIMATE

Assumes equal-sized folds. With unequal folds, use . Number of models trained: , each on about samples.

LEAVE-ONE-OUT (LOO) CV ESTIMATE

LOO is -fold with . is the loss, and is trained on every sample except the -th, so models are trained, each on samples.

LOO SHORTCUT FOR ORDINARY LEAST SQUARES

Valid only for linear least squares with squared error, fitted once on all the data. is the full-data fit. is the -th diagonal entry of the hat matrix , with samples in the rows of . It requires to be invertible and . If an intercept is fitted, includes a column of ones. No refitting is needed.

Property

-fold ( = 5 or 10)

Leave-one-out ()

Models trained

Training size per model

Cost

Lower

Highest (unless a shortcut exists)

Bias of the error estimate

Slightly pessimistic (models see less data)

Smallest (models see almost all data)

Variance of the estimate

Usually lower

Can be higher, since the training sets overlap almost completely

Randomness

Depends on how folds are drawn

None: the splits are fixed

EXAM TIP

Cross-validation estimates how well the procedure generalises. The final model is normally refit on all the data afterwards, and the models inside CV are not the model you deploy. Any preprocessing learned from data (scaling constants, feature selection) must be fitted inside each training fold only. Fitting it on all the data first leaks information and makes the CV error optimistic. For classification, stratified folds keep the class proportions in each fold.

Choosing a hyperparameter by cross-validation

Procedure

  1. List candidate values of the hyperparameter (for example ).

  2. For each candidate, run -fold CV and record the CV error.

  3. Pick the candidate with the smallest CV error.

  4. Refit the model with that value on the whole training set.

  5. Evaluate once on a separate test set, if one was held out.

MODELS TRAINED IN A GRID SEARCH

With several hyperparameters, the number of candidate settings is the product of the grid sizes. The is the refit on all the data. Leave it out if the question asks only about the search.

WORKED EXAMPLE

A dataset has samples. 5-fold CV is used and the fold errors (misclassification rates) are . Find the CV estimate and the size of each training set.

Solution
  1. Each fold has samples, so the folds are equal in size.

  2. Each model trains on the other four folds: samples.

  3. CV estimate .

Answer: CV estimate ; each of the 5 models is trained on 96 samples.

EXAM TIP

If the hyperparameter is chosen by CV and the same CV error is then quoted as the model's performance, the figure is optimistic, because the winner was picked for having the lowest error. An untouched test set gives the honest number. Without one, nested cross-validation can be used: an inner CV picks the hyperparameter inside each outer training fold, and the outer folds measure the error.

Evaluation measures for classification

For a binary problem with a positive class, the confusion matrix counts: TP (positive predicted positive), FP (negative predicted positive), FN (positive predicted negative), TN (negative predicted negative). Here .

ACCURACY

Misleading when the classes are very unbalanced.

PRECISION

Of everything predicted positive, the fraction that is truly positive. Undefined if nothing is predicted positive.

RECALL (SENSITIVITY, TRUE POSITIVE RATE)

Of everything truly positive, the fraction found.

SPECIFICITY AND FALSE POSITIVE RATE

Specificity is the fraction of true negatives correctly identified.

F1 SCORE

The harmonic mean of precision and recall . TN does not appear in it.

WORKED EXAMPLE

A classifier is tested on 200 samples and gives , , , . Find the accuracy, precision, recall and .

Solution
  1. Accuracy .

  2. Precision .

  3. Recall .

  4. .

Answer: Accuracy 0.85, precision 0.80, recall 0.667, .

EXAM TIP

A model that always predicts the majority class can have high accuracy and zero recall for the minority class. When the positive class is rare, quote precision, recall or , not accuracy alone.

PREVIOUS-YEAR QUESTIONS

2 questions from the DA papers

Try each question first, then open the answer. We placed each question under a topic ourselves; the exam paper does not label topics.

See these papers in full: GATE DA 2026

GATE 2026 DA Q.12

GATE 2026 · DAQ.12 · 1 mark · MCQ

Consider that you are training a classifier for a 10-class classification problem. Each input is represented as a 512-dimensional vector. There are 1000 samples, out of which first 100 will be used for testing. Let Leave-One-Out-Cross-Validation (LOOCV) be used for selection of the classifier model before testing.

Which of the following options is the correct number of validation splits that will be generated?

  1. (A)

    10

  2. (B)

    512

  3. (C)

    900

  4. (D)

    1000

Answer and solution
See the question in the paper
GATE 2026 DA Q.12: answer and solution

GATE 2026 DA Q.47

GATE 2026 · DAQ.47 · 2 marks · MSQ

Consider that 20 stories of Author X and 10 stories of Author Y were kept together without mentioning the names of the authors. A classifier was then asked to predict the author (X or Y) of each of these stories. Let, out of X's stories, 6 were classified as that of Y. On the other hand, out of Y's stories, 2 were classified as that of X.

Considering X and Y as two classes, which of the following statements is/are true?

  1. (A)

    Accuracy of the classifier is 11/15.

  2. (B)

    Precision of Class X is higher than the Precision of Class Y.

  3. (C)

    Recall of Class X is higher than the Recall of Class Y.

  4. (D)

    Accuracy of the classifier is 14/15.

Answer and solution
See the question in the paper
GATE 2026 DA Q.47: answer and solution

PRACTICE

7 questions to test yourself

PRACTICE 11 mark · NAT

At a test point the true value is . Over many training sets, a model's prediction at has mean and variance . The noise in has zero mean and variance , and is independent of the training set. Using squared-error loss, find the expected squared prediction error at (answer to two decimal places).

Answer and solution

Answer: (accepted range )

  1. Bias , so .

  2. Variance and irreducible noise .

  3. Expected error .

PRACTICE 21 mark · MCQ

In ridge regression, the penalty strength is increased from a small positive value to a much larger one, with the training set fixed. Which statement describes the typical effect on the fitted model?

  1. (A)

    Bias decreases and variance increases

  2. (B)

    Bias increases and variance decreases

  3. (C)

    Both bias and variance decrease

  4. (D)

    Both bias and variance increase

Answer and solution

Answer: (B)

  1. A larger shrinks the weights towards zero, which makes the model less flexible.

  2. A less flexible model is less sensitive to the particular training set, so variance typically falls.

  3. It also cannot fit the true pattern as closely, so bias typically rises. The answer is B.

PRACTICE 32 marks · MSQ

A dataset has samples. Which of the following statements about leave-one-out (LOO) cross-validation and 5-fold cross-validation on this dataset are correct?

  1. (A)

    LOO trains 100 models.

  2. (B)

    Each LOO model is trained on 99 samples.

  3. (C)

    5-fold CV trains 5 models, each on 80 samples.

  4. (D)

    LOO always needs less computation than 5-fold CV.

Answer and solution

Answer: (A), (B), (C)

  1. LOO leaves out one sample each time, so it trains models, each on samples. A and B are true.

  2. 5-fold CV has 5 folds of 20 samples. Each model trains on the other 4 folds, which is samples. C is true.

  3. LOO trains 100 models against 5, so it normally costs more, not less. D is false: a shortcut such as the least-squares formula is a special case, not 'always'.

PRACTICE 42 marks · MCQ

A decision tree reaches a training error of 1% but a validation error of 22%. Which diagnosis and remedy fit best?

  1. (A)

    High bias; use a more complex model

  2. (B)

    High variance (overfitting); more training data or stronger regularisation, such as limiting tree depth, is likely to help

  3. (C)

    High bias; reduce regularisation

  4. (D)

    Neither; a gap this size is expected for any model with noise

Answer and solution

Answer: (B)

  1. Training error is very low but validation error is much higher, so the gap is large.

  2. A large gap means overfitting, which is high variance.

  3. The standard remedies are more data, a simpler model or more regularisation. A and C treat it as underfitting, which would show high training error. The answer is B.

PRACTICE 51 mark · NAT

A model has two hyperparameters: the first has 4 candidate values and the second has 3. Every combination is evaluated by 5-fold cross-validation, and the best combination is then refit once on the full training set. How many times is a model trained in total?

Answer and solution

Answer:

  1. Number of candidate settings .

  2. Each setting needs 5 models (one per fold): .

  3. Add the single final refit: .

PRACTICE 62 marks · NAT

A -NN regressor with is used at a point . The training inputs are fixed, and each response is with independent zero-mean noise of variance . The true function values at the 4 nearest training inputs are , and . Using squared-error loss, find the expected squared prediction error at for a new observation at (answer to two decimal places).

Answer and solution

Answer: (accepted range )

  1. Average of the neighbours' true values .

  2. Bias , so .

  3. Variance of the prediction .

  4. Expected error .

PRACTICE 72 marks · NAT

A binary classifier is evaluated on 100 samples, giving , , and . Find the score of the positive class, rounded to two decimal places.

Answer and solution

Answer: (accepted range )

  1. Precision .

  2. Recall .

  3. .

OFFICIAL GATE 2027 SYLLABUS WORDING

Copied from the GATE 2027 syllabus; see all 2027 syllabi.

GATE DA

bias-variance trade-off, cross-validation methods such as leave-one-out (LOO) cross-validation, k-folds cross-validation

Preparing in Kolkata? IAE Academy's course for GATE DA.