Smoothing Spline
Study guide: Exam MAS-I
A smoothing spline is the function g that minimizes the Residual Sum of Squares plus a penalty on its roughness. A nonnegative tuning parameter \lambda sets the trade-off between fitting the data and being smooth.
\sum_{i=1}^{n}\big(y_i - g(x_i)\big)^2 + \lambda \int g''(t)^2\, dt
\hat{\mathbf{g}}_\lambda = \mathbf{S}_\lambda \mathbf{y}
df_\lambda = \sum_{i=1}^{n} \{\mathbf{S}_\lambda\}_{ii}
\mathrm{RSS}_{cv}(\lambda) = \sum_{i=1}^{n}\left[\frac{y_i - \hat g_\lambda(x_i)}{1 - \{\mathbf{S}_\lambda\}_{ii}}\right]^2
- Loss + Penalty. This is the same form as ridge regression and the lasso (see Regularization). The sum of squares rewards fitting the data. The second derivative
g''(t)measures how fast the slope is changing, so\int g''(t)^2\,dtmeasures the total change ing'(t)over its range. It is small for a smoothgand large for a jumpy one. A straight line hasg'' = 0. - The extremes of
\lambda. At\lambda = 0the penalty has no effect, andginterpolates the training observations exactly. As\lambda \to \infty,gbecomes the linear least squares line. In between,\lambdacontrols the Bias-Variance Tradeoff. - The solution. The minimizer is a natural cubic spline with a knot at every unique value of
x_1, \dots, x_n. It is not the natural cubic spline that the basis approach would fit with those knots (see Regression Spline). It is a shrunken version of it, and\lambdasets the amount of shrinkage. - Effective degrees of freedom.
\hat{\mathbf{g}}_\lambdais then-vector of fitted values atx_1, \dots, x_n, and\mathbf{S}_\lambdais ann \times nmatrix. The spline hasnnominal parameters, but they are heavily constrained, so flexibility is measured bydf_\lambda, the sum of the diagonal of\mathbf{S}_\lambda. As\lambdaincreases from0to\infty,df_\lambdafalls fromnto2. Higherdf_\lambdameans a more flexible fit, with lower bias and higher variance. - Choosing
\lambda. There are no knots to place. Instead\lambdais chosen by Cross-Validation, to minimize the cross-validated RSS. Leave-one-out CV costs essentially one fit, using the last formula above. There,\hat g_\lambda^{(-i)}(x_i)denotes the fit made without observationi, and the formula replaces it with quantities from the full fit\hat g_\lambda. Least squares has the same kind of shortcut, built on the leverages of the Hat Matrix. On ISLR's Wage data, choosing\lambdaby LOOCV gave6.8effective degrees of freedom. The fit was hard to tell apart from one with 16, so the simpler fit is preferred. - A smoothing spline can be the building block for one term of a Generalized Additive Model, fit by backfitting. Local Regression controls flexibility the same way, but with a span instead of
\lambda.
Choosing the Smoothing Parameter by LOOCV A smoothing spline relates claim frequency (per 100 vehicles) to vehicle age
x = 1, \dots, 6. At\lambda = 1, the fit to all six points gives:
x_i1 2 3 4 5 6 y_i8.1 7.2 7.5 6.1 6.4 5.2 \hat g_\lambda(x_i)8.011 7.519 7.063 6.537 6.002 5.367 \{\mathbf{S}_\lambda\}_{ii}0.757 0.379 0.379 0.379 0.379 0.757 At
\lambda = 0.2the same calculation givesdf_\lambda = 3.92and\mathrm{RSS}_{cv} = 3.78. Finddf_\lambdaand\mathrm{RSS}_{cv}(\lambda)at\lambda = 1, and say which\lambdaLOOCV prefers.Answer The effective degrees of freedom is the sum of the diagonal:
\begin{align*} df_\lambda &= 2(0.757) + 4(0.379) \\ &= 3.03 \end{align*}Each residual
y_i - \hat g_\lambda(x_i)is divided by1 - \{\mathbf{S}_\lambda\}_{ii}(that is,0.243or0.621) and squared:\begin{align*} \mathrm{RSS}_{cv} &= \left(\tfrac{0.089}{0.243}\right)^2 + \left(\tfrac{-0.319}{0.621}\right)^2 + \left(\tfrac{0.437}{0.621}\right)^2 \\ &\quad + \left(\tfrac{-0.437}{0.621}\right)^2 + \left(\tfrac{0.398}{0.621}\right)^2 + \left(\tfrac{-0.167}{0.243}\right)^2 \\ &= 0.134 + 0.264 + 0.495 + 0.495 + 0.411 + 0.472 \\ &= 2.27 \end{align*}
2.27 < 3.78, so LOOCV prefers\lambda = 1, the smoother fit with about 3 effective degrees of freedom. The ordinary RSS at\lambda = 1is only0.68. Dividing by1 - \{\mathbf{S}_\lambda\}_{ii}inflates each residual to what it would have been with that point left out. The end points have the largest\{\mathbf{S}_\lambda\}_{ii}, so they are inflated most.
What Happens as λ Changes A smoothing spline is fit to
n = 40points with distinctxvalues. Which of these statements are true?I. At
\lambda = 0the fit passes through every training point. II. As\lambdaincreases from0to\infty,df_\lambdadecreases from40to2. III. As\lambda \to \infty, the fit becomes the least squares line. IV. Increasing\lambdaremoves knots from the spline.Answer I, II and III are true; IV is false.
With no penalty, the RSS can be driven to zero, so
ginterpolates (I). The effective degrees of freedom run fromn = 40down to2(II), and the limit is the linear least squares fit, which has two coefficients (III).IV is false. The minimizer always has a knot at every unique
x_i, whatever\lambdais. Increasing\lambdashrinks the fit toward a line rather than removing knots. Choosing the number and location of knots is the Regression Spline approach.