MACHINE LEARNING

Multiple Linear Regression

With more than one predictor, OLS extends naturally via matrix algebra: β̂ = (XᵀX)⁻¹Xᵀy. The mechanics are the same, but interpretation and multicollinearity require more care.

1From Simple to Multiple Regression

Simple linear regression fits one line: y = β&sub0; + β&sub1;x. Multiple linear regression generalises this to d predictors: y = β&sub0; + β&sub1;x&sub1; + β&sub2;x&sub2; + … + βdxd + ε. The goal is identical — find the parameter vector β that minimises residuals — but the geometry shifts from fitting a line to fitting a hyperplane in a (d+1)-dimensional space.

Classic example: predicting sales from TV, radio, and newspaper advertising spend. TV alone explains 61% of sales variance. Adding radio increases it to 90%. Adding newspaper provides almost no additional explanatory power (R² barely changes) — because newspaper spend is effectively captured by the other two predictors.

2The Matrix Form: Design Matrix X

With n observations and d features, we stack the system into matrix form: y = Xβ + ε. The design matrix X is n × (d+1), with a first column of 1s (for the intercept β&sub0;). Each row is one observation.

The Normal Equation is the same as in simple regression: β̂ = (XᵀX)⁻¹Xᵀy. Crucially, (XᵀX) must be invertible — which requires n > d+1 and no perfect multicollinearity among the columns of X. If X has 200 rows and 3 feature columns (plus the intercept column), XᵀX is 4×4 — trivial to invert. With thousands of features, this becomes expensive: matrix inversion is O(d³).

y vector
n × 1 column of observed output values y&sub1;, y&sub2;, …, yn
Design matrix X
n × (d+1): first column all 1s, remaining columns are feature values. Each row is one sample.
β vector
(d+1) × 1: intercept β&sub0; first, then one coefficient per feature.

3Interpreting Coefficients

Each coefficient βj represents the expected change in y for a one-unit increase in xj while holding all other predictors constant. This “ceteris paribus” interpretation is why multiple regression is more useful than running separate simple regressions — it isolates each predictor's effect.

Advertising example coefficients

  • TV: β ≈ 0.05 — each extra $1k in TV spend → +50 units sold
  • Radio: β ≈ 0.19 — each extra $1k in radio spend → +190 units sold
  • Newspaper: β ≈ 0.00 — no independent effect

Interpretation pitfalls

  • Coefficients change when you add/remove predictors — each coefficient is conditional on the others
  • Comparing magnitude across features only makes sense after standardisation
  • High R² does not imply causation

4Multicollinearity and Feature Selection

When two predictors are highly correlated, their individual coefficients become unreliable — the model can't tell which is responsible for the variance. The estimate is technically correct but numerically unstable: small data changes cause large coefficient swings.

VIF diagnostic
Variance Inflation Factor > 5 signals problematic collinearity. VIF = 1/(1 - R²j), where R²j is R² from regressing feature j on all other features.
Fix: drop or merge
If area = length × breadth, drop one of the three. Alternatively, combine correlated features via PCA to get uncorrelated principal components.
Fix: regularisation
Ridge regression adds λI to XᵀX before inverting, making it numerically stable even under high multicollinearity. This trades a small amount of bias for much lower variance.

Related

Multiple Linear Regression — OLS with 3 predictors using numpy

Recall check

0 of …

Say the answer out loud before revealing — recalling is what makes it stick. ➜ Next: R² and Adjusted R²

  1. What does the design matrix X contain and why add a column of 1s?

  2. How do you interpret a coefficient β₁ = 0.05 in a model with TV and radio as predictors?

  3. Why does adding more predictors not always improve a model?

  4. What is the computational cost of OLS and when does it become prohibitive?