IAE Academy

GATE DA

Simple, multiple and ridge regression

Regression predicts a real-valued target from features. This topic covers fitting a line by least squares, writing the normal equations in matrix form, and how the ridge (L2) penalty shrinks weights and trades bias for variance. The calculations involved are typically a few sums, one small matrix solve, or one gradient step, so the formulas and the conditions under which they hold are worth knowing exactly.

4 previous-year questions · 4 solved · 5 practice questions

Regression versus classification, and the set-up

In regression the target is a real number (a price, a temperature); in classification it is a discrete label. The model for linear regression is a linear function of the features plus noise, and we choose the parameters that minimise the squared error on the training data.

Convention used in these notes. There are samples and features. Samples are the rows of the design matrix , the target is the column vector (), weights are and the bias (intercept) is . With feature columns only, is and the prediction is . To absorb the bias, append a column of ones to (it becomes ) and put in ; then . Unless a formula says otherwise, below includes this column of ones whenever the model has an intercept. In simple regression the intercept and slope are written (the bias ) and (the single weight). Vectors are column vectors written in bold, and is the Euclidean norm.

MEAN SQUARED ERROR (MSE)

Average squared residual; the sum of squared errors (SSE) is the same without the factor . Minimising either gives the same .

A residual is . The squared-error objective is convex in , so any stationary point is a global minimum, and it has a closed-form minimiser. If the noise is independent Gaussian with constant variance, the least-squares estimate is also the maximum-likelihood estimate of .

Linear in the parameters. 'Linear' regression means linear in , not necessarily in the inputs. A model such as is fitted by exactly the same formulas, with and as two columns of .

Simple linear regression

One feature , model . Define , and .

LEAST-SQUARES SLOPE AND INTERCEPT

Needs at least two distinct values (). The fitted line always passes through .

Properties of the fit (least squares with an intercept)

  1. The residuals sum to zero: .

  2. The residuals are orthogonal to : ; hence also to the fitted values: .

  3. The line passes through .

  4. , where is the sample correlation and the sample standard deviations; so the slope and have the same sign.

COEFFICIENT OF DETERMINATION

The two forms agree for least squares with an intercept on the training data, where SST = SSR + SSE; then (assuming SST ). For simple regression . On new (test) data, or for a model without an intercept, can be negative.

WORKED EXAMPLE

Data : . Fit , predict at and find .

Solution
  1. , .

  2. .

  3. .

  4. , .

  5. Prediction at : .

  6. . , so . (Check: fitted values ; SSE and .)

Answer: Fitted line ; prediction ; .

EXAM TIP

Extrapolating outside the range of the training values is unreliable, and a high does not by itself show that a linear model is appropriate. If a question fits a line through the origin (no intercept), the slope is , not , and the residuals need not sum to zero.

Multiple linear regression in matrix form

With features and a bias column included, the model is . The gradient of is ; setting it to zero gives the normal equations.

NORMAL EQUATIONS AND THE OLS SOLUTION

The inverse form requires to be invertible, i.e. the columns of (including the column of ones, if present) are linearly independent. This needs to be at least the number of columns. If one column is a linear combination of others (exact collinearity, or more columns than samples), is singular: minimisers still exist, but there are infinitely many.

HAT MATRIX AND RESIDUAL ORTHOGONALITY

is the orthogonal projection of onto the column space of ; the residual vector is orthogonal to every column of . With a column of ones, this is why the residuals sum to zero.

STATISTICAL PROPERTIES OF OLS

Assumes the model is correct, is fixed, and the noise has mean zero, variance and is uncorrelated across samples. = number of features excluding the bias, so is minus the number of columns of . For simple regression, .

ADJUSTED $R^2$

= number of features excluding the bias; requires . On the training data never decreases when a feature is added; adjusted can decrease.

Procedure for a small numerical problem

  1. Build with a column of ones (if there is an intercept) and the column vector .

  2. Compute and .

  3. Invert the small matrix (for : swap the diagonal entries, negate the off-diagonal entries, divide by the determinant) or solve the linear system directly.

  4. Compute predictions and, if asked, SSE or .

EXAM TIP

If every feature column is centred (mean zero) and the feature columns are pairwise uncorrelated, then , including the column of ones, is diagonal. Each weight is then just the simple-regression slope on that feature, and the bias is . Highly correlated (nearly collinear) features make the individual weights unstable (large variance) even when the predictions are fine.

Ridge regression

Ridge regression adds an L2 penalty on the weights to the squared error, with strength . By convention the bias term is not penalised (centre the data, or leave the bias out of the penalty). The first formulas below assume the penalty is applied to every column of as given; the intercept-free version follows them.

RIDGE OBJECTIVE

Sum of squared errors plus times the squared Euclidean norm of the weights. gives OLS. For the objective is strictly convex, so the minimiser is unique. Equivalent constrained form: minimise subject to , for a that depends on .

RIDGE CLOSED FORM

For the matrix is always invertible (positive definite), even when is singular. Here is the identity of size equal to the number of weights.

RIDGE WITH AN UNPENALISED INTERCEPT

is the matrix of feature columns (no column of ones) with each column's mean subtracted; is the vector of feature means, and is . Centring as well gives the same , because .

RIDGE WITH ORTHONORMAL COLUMNS

Every weight is shrunk by the same factor . This is the case of the next formula.

RIDGE SHRINKAGE IN GENERAL

Here is its eigendecomposition, and must be invertible for to exist. Directions with small eigenvalues (low-variance, near-collinear directions) are shrunk the most. For finite , ridge shrinks weights towards zero but does not in general make any of them exactly zero; an L1 (lasso) penalty can.

RIDGE AS A MAP ESTIMATE

A Gaussian prior on the weights gives ridge. A tighter prior (smaller ) means a larger and more shrinkage.

Effect of increasing

Result

Size of weights

Never increases (shrinkage); tends to as

Bias of the estimator

Never decreases; in general increases

Variance of the estimator

Never increases; in general decreases

Training error (SSE)

Never decreases; in general increases

Behaviour as

Approaches the OLS solution (the minimum-norm one if is singular)

WORKED EXAMPLE

Single feature, no intercept, , . Find the OLS weight and the ridge weight with (minimising ).

Solution
  1. and .

  2. OLS: .

  3. Ridge: setting the derivative to zero gives , so .

  4. The ridge weight is smaller in magnitude, as expected from shrinkage.

Answer: OLS ; ridge .

EXAM TIP

Check how the question scales the objective. With the mean, , the solution is . With , it is the same as the main formula .

EXAM TIP

Ridge is sensitive to feature scale because the penalty treats all weights alike. A feature whose values are numerically small needs a large weight to have the same effect, so it is penalised more. Standardise features (zero mean, unit variance) before applying ridge. OLS predictions, by contrast, do not change if a feature is multiplied by a non-zero constant.

Gradient descent for least squares, and feature scaling

When is too large to invert, minimise the loss iteratively. With MSE the gradient is and the Hessian is the constant matrix . Because the loss is a convex quadratic, gradient descent with a step size below the bound given with the update converges to a minimiser: the OLS solution when is invertible, otherwise one of the many minimisers.

GRADIENT DESCENT UPDATE FOR MSE

is the learning rate. The iterates converge from any starting point if , where is the largest eigenvalue of . If they generally diverge.

GRADIENT DESCENT UPDATE FOR RIDGE

For the objective (sum, not mean, of squared errors). The extra term pulls every weight towards zero at each step. The Hessian is , so the step-size bound is of that matrix.

When scaling matters. Gradient descent converges slowly when features have very different ranges, because the loss surface is a long, narrow valley (the eigenvalues of differ widely). Standardising the features makes the contours rounder and speeds convergence. Scaling also matters for ridge, as above. The predictions of the closed-form OLS solution are unaffected by scaling.

EXAM TIP

Check which loss the question uses before differentiating. For the gradient is ; for it is ; for the plain sum it is . A wrong constant is an easy slip to make in a one-step gradient-descent question.

PREVIOUS-YEAR QUESTIONS

4 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 DA 2025

GATE 2026 DA Q.29

GATE 2026 · DAQ.29 · 1 mark · NAT

Consider that for a supervised learning task, the objective function being minimized is , where is the input and is the parameter. Stochastic Gradient Descent with learning rate of 0.10 is used for parameter updates.

Suppose that at the end of iteration , the value of becomes 10.00.

Let be the input for iteration .

The value of at the end of iteration is __________. (Rounded off to two decimal places)

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

GATE 2026 DA Q.37

GATE 2026 · DAQ.37 · 2 marks · MCQ

Which of the following statements is true for Ridge Regression?

  1. (A)

    The regularizer in the objective function of Ridge Regression is used to guard against scenarios where the model works well for the test data, but poorly for the training data.

  2. (B)

    The regularizer of Ridge Regression uses L_1 norm.

  3. (C)

    Ridge Regression aims to reduce the number of parameters that have negative values.

  4. (D)

    The regularizer of Ridge Regression may increase the bias of the model, but it helps in reducing the variance in predictions.

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

GATE 2026 DA Q.55

GATE 2026 · DAQ.55 · 2 marks · NAT

Consider that Linear Ridge Regression is being used to learn a prediction function , where and Mean Absolute Error (MAE) is used to measure the prediction error. A weight of 0.20 is associated with the regularizer.

At an intermediate step of the training process, assume that the parameter . In the next step, for the input , the predicted value of is noted. Let the relation between and the true value of be .

The value of the overall regularized loss function for this instance is ______ . (Rounded off to two decimal places)

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

PRACTICE

5 questions to test yourself

PRACTICE 11 mark · NAT

A simple linear regression is fitted by least squares to the four points . What is the predicted value at ? (Give your answer to one decimal place.)

Answer and solution

Answer: (accepted range )

  1. , .

  2. .

  3. .

  4. ; .

  5. Prediction at : .

PRACTICE 21 mark · MCQ

In ridge regression with objective , the regularisation strength is increased from a small positive value to a large one. Which statement describes the change in the estimator?

  1. (A)

    Bias decreases and variance increases

  2. (B)

    Bias increases and variance decreases

  3. (C)

    Both bias and variance increase

  4. (D)

    Both bias and variance decrease

Answer and solution

Answer: (B)

  1. A larger shrinks the weights harder towards zero.

  2. A more constrained estimator fits the training data less flexibly, so its bias rises.

  3. The same shrinkage makes the estimate less sensitive to the particular training sample, so its variance falls.

  4. Hence option B.

PRACTICE 32 marks · NAT

For a single feature with no intercept, the training data are and . The ridge weight minimises with . Find .

Answer and solution

Answer: (accepted range )

  1. .

  2. .

  3. Setting the derivative to zero gives .

  4. .

PRACTICE 42 marks · MSQ

A simple linear regression with an intercept is fitted by ordinary least squares to points that do not all have the same and do not all have the same . Which of the following statements are always true?

  1. (A)

    The sum of the residuals is zero.

  2. (B)

    The fitted line passes through .

  3. (C)

    computed on the training data can be negative.

  4. (D)

    equals the square of the sample correlation between and .

Answer and solution

Answer: (A), (B), (D)

  1. With an intercept, the normal equation for gives , so A is true.

  2. Dividing by gives , so B is true.

  3. With an intercept, SST = SSR + SSE on the training data and SST , so ; C is false.

  4. For simple regression , so D is true.

PRACTICE 52 marks · NAT

A model (no intercept) is trained on , by minimising the mean squared error with . Starting from with learning rate , what is after one gradient-descent step?

Answer and solution

Answer: (accepted range )

  1. .

  2. At : .

  3. Gradient .

  4. Update: .

OFFICIAL GATE 2027 SYLLABUS WORDING

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

GATE DA

regression and classification problems, simple linear regression, multiple linear regression, ridge regression

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