Locally weighted linear regression predicts at a query xq by minimising ∑iwi (yi−θ0−θ1xi)2 with weights wi=exp⁡ ⁣(−(xi−xq)2/(2τ2)). For the data (0,1),(1,3),(2,2), bandwidth τ=1 and query xq=0, compute the prediction. How does it compare with the ordinary least-squares prediction at x=0?

Supervised learning, Locally weighted regression
Level L3 Intermediate. Length Medium. Nature Mat Mathematical.

What's being asked

Whether you can run weighted least squares by hand and explain that LWR fits a fresh local line for every query.

Key idea

Solve the weighted normal equations ∑wi(1xi)(1;xi)θ=∑wi(1xi)yi and predict θ0+θ1xq.

Steps

  1. Compute the weights for xq=0: w1=e0=1, w2=e−0.5=0.6065, w3=e−2=0.1353. Nearby points count more.
  2. Form the weighted sums: S=∑wi=1.7419, Sx=∑wixi=0.8772, Sxx=∑wixi2=1.1479, Sy=∑wiyi=3.0903, Sxy=∑wixiyi=2.3609.
  3. The weighted normal equations are (SSxSxSxx)θ=(SySxy). The determinant is SSxx−Sx2=1.9995−0.7695=1.2300.
  4. Solve: θ1=(SSxy−SxSy)/1.2300=(4.1124−2.7108)/1.2300=1.1396 and θ0=(Sy−θ1Sx)/S=(3.0903−0.9997)/1.7419=1.2002.
  5. The prediction at xq=0 is θ0≈1.20.
  6. Ordinary least squares uses equal weights. For these three points the slope is ∑(xi−1)(yi−2)/∑(xi−1)2=1/2 and the intercept is 2−0.5⋅1=1.5, so it predicts 1.5 at x=0. LWR gives 1.20 because it trusts the point (0,1) more and the distant (2,2) less.
  7. Because the weights change with xq, LWR is non-parametric: it needs the training data at prediction time and refits for every query.

Common mistakes

How long your answer should be

Half a page with a small table of weights; 5 minutes.

Read this

Previous in Supervised learning: Kernel ridge regression uses the kernel k(x,z)=(1+xz)2 on one-dimensional inputs, with penalty λ=1. The training data are (x1,y1)=(0,1) and (x2,y2)=(1,3). Find the dual coefficients α and predict at x=2. Why is the dual form useful?
Next in Supervised learning: The pinball (quantile) loss for level τ∈(0,1) is ρτ(r)=τr if r≥0 and (τ−1)r if r<0, with r=y−c. Show that the constant c minimising E ρτ(Y−c) is the τ-quantile of Y. How do you check it numerically for τ=0.7 on {1,2,3,4,10}?