1. University MCA (AI/ML) Semester 2
  2. CAB212
  3. Unit 2

CAB212 · Unit 2: Regression

Linear regression and the least-squares solution

8 practice questions

Key points

  • OLS minimises sum of squared errors
  • slope = Sxy / Sxx; intercept = y_mean - slope*x_mean
  • Normal equation: w = (X^T X)^-1 X^T y
  • Line passes through the mean point

Linear regression models y = w0 + w1*x1 + ... + wd*xd. Weights minimise the sum of squared errors (ordinary least squares, OLS).

For one feature:

  • slope w1 = sum((x - x_mean)(y - y_mean)) / sum((x - x_mean)^2)
  • intercept w0 = y_mean - w1 * x_mean

For many features the normal equation gives w = (X^T X)^-1 X^T y (needs X^T X invertible; costly for many features).

Worked example: points (1,2),(2,4),(3,5),(4,4),(5,5): x_mean=3, y_mean=4, Sxy=6, Sxx=10, so slope=0.6 and intercept=2.2.

Assumptions: linear relationship, independent errors, constant error variance (homoscedasticity), roughly normal residuals, little multicollinearity.

Exam pitfall: the fitted line always passes through (x_mean, y_mean).

Try two questions

Question 1 · Tier 4, Analyse

Perfect multicollinearity among features makes X^T X:

  1. The identity matrix
  2. Singular (not invertible)
  3. A matrix with strictly positive entries
  4. Equal to the target vector y
Show the answer

B. Dependent columns make the matrix rank deficient.

Question 2 · Tier 3, Apply

The normal equation solution for the weight vector is:

  1. X^T divided by y
  2. (X^T X)^-1 X^T y
  3. X y^T, the outer product
  4. (X X^T) y, using the outer product
Show the answer

B. This closed form solves OLS.