S149 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

S14 · Lesson 9 · Linear regression and the bias–variance trade-off

Linear models in basis functions, the normal equations and their regularized form, the effective number of parameters, how regularization trades bias for variance, the best regularization strength for a simple case, and how many features a polynomial basis needs

"Linear" regression can fit curves: the model only has to be linear in its weights, and the inputs can pass first through any fixed set of basis functions, polynomials, sinusoids or Gaussians. That makes the fit a matrix problem with a closed-form answer, and it lets the effect of regularization be worked out exactly. The result is the bias–variance trade-off: a penalty that pulls weights toward zero makes every fit a little wrong in the same direction, but much less sensitive to noise, and the right amount minimizes the total error.

  • For a single weight (true value 1) estimated from data with Σx² = S and noise variance σ², the squared bias and the variance of the ridge estimate w^=∑xt/(S+λ) against λ (log scale), and their sum, the mean squared error.
  • With no regularization the estimate is unbiased but noisy. As λ grows, variance falls and bias rises. The total is smallest at λ=σ2/w2.
  • More data (larger S) needs less regularization.

Predict

A single weight, truly 1, is estimated with Σx² = 10 and noise variance 4. Can ridge regularization lower its mean squared error below the unregularized 0.4?

Name it

Linear models

y(𝐱,𝐰)=∑j=0M−1wjϕj(𝐱)=𝐰T𝝓(𝐱)

with fixed basis functions ϕj (and ϕ0=1 for the bias). A polynomial basis of degree M in D inputs has (M+DD) terms, which grows quickly with dimension.

The normal equations

Stacking 𝝓(𝐱n)T into the design matrix Φ, least squares gives 𝐰=(ΦTΦ)−1ΦT𝐭, and with a penalty λ2‖𝐰‖2 (ridge regression)

𝐰=(ΦTΦ+λI)−1ΦT𝐭

Effective parameters

If ΦTΦ has eigenvalues di, ridge shrinks each direction by di/(di+λ), and the effective number of parameters is ∑idi/(di+λ): well-determined directions keep their weight, poorly determined ones are suppressed.

Bias and variance

The expected squared error of an estimate splits into squared bias plus variance (plus the irreducible noise, for predictions). For one weight with Σx² = S, ridge gives bias² (λw/(S+λ))2 and variance σ2S/(S+λ)2, minimized in sum at λ=σ2/w2, where the error is σ2/(S+λ).

Worked example

Tabulate the sim's case (S = 10, w = 1, σ² = 4).

Show the solution
  1. Add squared bias and variance at each λ. With S = 10, w = 1 and σ² = 4:
λbias²variancetotal
000.4000.400
10.0080.3310.339
40.0820.2040.286
100.2500.1000.350
400.6400.0160.656
  1. Find the minimum. The total is smallest at λ = 4.

Answer the total error is 0.400, 0.339, 0.286, 0.350 and 0.656 at λ = 0, 1, 4, 10 and 40, with the minimum, 0.286, at λ = 4.

Worked example

A design's ΦTΦ has eigenvalues 10, 1 and 0.1, and λ = 1. How many effective parameters does ridge leave?

Show the solution
  1. Effective parameters. 1011+12+0.11.1=0.909+0.500+0.091=1.5
  2. Which directions survive. The strongly determined direction survives almost whole, the weakest is nearly removed.
  3. Counting basis terms. A cubic polynomial in two inputs would have (52) = 10 terms, a quadratic in three inputs (53) = 10, which is why basis expansions struggle in high dimensions.

Answer ridge leaves 1.5 effective parameters.

Worked example

A two-feature fit has ΦTΦ=[4222] and ΦT𝐭=(6,4). Find the least-squares weights, and the ridge weights with λ = 1.

Show the solution
  1. Least squares. The determinant is 4 × 2 − 2² = 4, so 𝐰=14[2−2−24](6,4)=(1,1)
  2. Ridge. Adding λ = 1 to the diagonal gives [5223], with determinant 11, so w1=3×6−2×411=0.909w2=−2×6+5×411=0.727
  3. Which weight shrinks more. The second shrinks more (27% against 9%) because it lies more along the matrix's weak direction, where ridge acts hardest.

Answer least squares gives w = (1, 1), and ridge with λ = 1 gives (0.909, 0.727).

Check

A weight w = 0.5 is estimated by ridge with Σx² = 5 and λ = 20. What's the squared bias?

Check

For the same estimate (Σx² = 5, λ = 20) with noise variance 1, what's the variance?

Check

For a single weight w = 0.5 with noise variance 4, what ridge λ minimizes the mean squared error?

Check

ΦTΦ has eigenvalues 5, 0.5 and 0.2. With λ = 5, how many effective parameters remain?

Check

How many terms does a polynomial basis of degree 3 in 2 inputs have (including the constant)?

Check

With Σx² = 5, noise variance 1 and a true weight 2, what mean squared error does the best ridge λ achieve?

Check

A two-weight least-squares problem has ΦTΦ=[accb] with a = 5, b = 2, c = 1.5, and ΦT𝐭 = (6, −1).

(a)

What is w1?

(b)

What is w2?

Check

A single weight w is estimated by ridge regression with Σx² = S, penalty λ, and noise variance v.

Step 1

What is the estimate's expected value?

Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.

Explain why

How can a deliberately biased estimate beat an unbiased one?

Practice

Keep practicing

10 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.