Linear Regression

1 min read

Linear regression models the relationship y=wx+by = \mathbf{w}^\top\mathbf{x} + b (or y=Xwy = X\mathbf{w} with bias absorbed).

Two ways to solve:

Closed-form (Normal Equations):

w^=(XX)1Xy\hat{\mathbf{w}} = (X^\top X)^{-1}X^\top \mathbf{y}
  • Direct solution, no iteration
  • Equivalent to MLE assuming Gaussian noise
  • O(d3)O(d^3) — impractical for very high dimensions

Gradient descent:

wt+1=wtηw1ni(yiwxi)2\mathbf{w}_{t+1} = \mathbf{w}_t - \eta \nabla_\mathbf{w} \frac{1}{n}\sum_i (y_i - \mathbf{w}^\top\mathbf{x}_i)^2

Loss function: MSE = 1n(yiy^i)2\frac{1}{n}\sum(y_i - \hat{y}_i)^2 — assumes Gaussian noise, equivalent to MLE.

Adding Regularization:

  • Ridge (L2): (XX+λI)1Xy(X^\top X + \lambda I)^{-1}X^\top yMAP with Gaussian prior
  • Lasso (L1): no closed form, promotes sparsity

See also: Logistic Regression, Bias-Variance Tradeoff

Linked from