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
Perfect multicollinearity among features makes X^T X:
- The identity matrix
- Singular (not invertible)
- A matrix with strictly positive entries
- Equal to the target vector y
Show the answer
B. Dependent columns make the matrix rank deficient.
The normal equation solution for the weight vector is:
- X^T divided by y
- (X^T X)^-1 X^T y
- X y^T, the outer product
- (X X^T) y, using the outer product
Show the answer
B. This closed form solves OLS.