Local Regression
Study guides: Exam MAS-I, Exam ACIA-CAPSTONE
A Local Regression is a method that fits a non-linear function of a predictor x one target point at a time: the fit at a target point x_0 is a weighted least squares regression on only the training observations near x_0. Like polynomial regression, step functions and splines, it extends linear regression to a non-linear relationship between a predictor and the response. The fit at x_0 takes four steps:
- Gather the fraction
s = k/nof thentraining observations whosex_iare closest tox_0. - Give each observation in this neighbourhood a weight
K_{i0} = K(x_i, x_0), so that the observation furthest fromx_0has weight 0 and the closest has the highest weight. Every observation outside the neighbourhood has weight 0. - Fit a weighted least squares regression of
y_ionx_iwith these weights. - Take the fitted value of that regression at
x_0as\hat f(x_0).
The span s is the fraction of the training observations used in each local fit. The weighted least squares regression of step 3 finds the \hat\beta_0 and \hat\beta_1 that minimize
\sum_{i=1}^{n} K_{i0}\,(y_i - \beta_0 - \beta_1 x_i)^2
y_iis the response andx_iis the predictor of observationi.Kis the weighting function.
The fitted value at the target point is
\hat f(x_0) = \hat\beta_0 + \hat\beta_1 x_0
The weights change with x_0, so every target point needs its own weighted regression. Local regression is a memory-based method, like K-nearest neighbors: to find the neighbourhood of x_0, the distance from x_0 to every training observation is computed and the k smallest are kept, so all the training data are needed for each prediction. Local regression extends to two predictors with two-dimensional neighbourhoods, but it performs poorly when the number of predictors is much larger than 3 or 4, because few training observations are close to x_0.
A local linear regression of claim frequency on driver age uses
n = 50age groups and spans = 0.1. The neighbourhood ofx_0 = 40and its weights are below. What is\hat f(40)?
Age x_i36 38 41 43 45 Frequency y_i6.0 5.6 5.0 4.9 4.0 Weight K_{i0}0.1 0.7 0.9 0.4 0
- The neighbourhood holds
k = sn = 0.1(50) = 5observations. The closest age, 41, has the highest weight and the furthest, 45, has weight 0.- The weights add up to 2.1, so the weighted means are
\bar{x}_w = 84.3/2.1 = 40.1429and\bar{y}_w = 10.98/2.1 = 5.2286.- The weighted least squares slope is
\begin{aligned} \hat\beta_1 &= \frac{\sum K_{i0}(x_i - \bar{x}_w)(y_i - \bar{y}_w)}{\sum K_{i0}(x_i - \bar{x}_w)^2} \\ &= \frac{-1.4286}{8.8571} \\ &= -0.1613 \end{aligned}
- The fitted value at the target point is
\begin{aligned} \hat f(40) &= \bar{y}_w + \hat\beta_1(40 - \bar{x}_w) \\ &= 5.2286 - 0.1613(40 - 40.1429) \\ &= 5.25 \end{aligned}
The span and the smoothness of the fit
The span s controls the flexibility of the fit, as the tuning parameter \lambda does for a smoothing spline. A larger span averages over more observations and gives a smoother, less variable fit. A smaller span follows local fluctuations and gives a wiggly fit with higher variance. A span of 1 uses all the training observations. The span is chosen by cross-validation or set directly. Local regression also needs a weighting function K and a choice of whether step 3 fits a constant, a line or a quadratic, but the span is the most important choice. Knots and the degree of a piecewise polynomial tune a regression spline, not a local regression.
A local regression of loss ratio on policy tenure for
n = 400policies is fitted with spans 0.2 and 0.7. How many observations are in each neighbourhood, and which span gives the smoother curve?
- The neighbourhood holds
k = snobservations:0.2(400) = 80fors = 0.2and0.7(400) = 280fors = 0.7.- The span 0.7 averages over more observations, so it gives the smoother curve with lower variance.
- The span 0.2 gives the wigglier curve, which uses more degrees of freedom.