In Introduction to Statistical Learning, there's this line under the section describing Smoothing Spline's tuning parameter $\lambda$:

In fitting a smoothing spline, we do not need to select the number or location of knots - there will be a knot at each training observation, $x_1,...,x_n$.

But, in my opinion wouldn't that be overfitting?

Reason for such a claim:
If there are more points which act as knots in the Spline fit, then the range for each slot for fitting is very small. Thus each change in the data, is recognized and imititated in the fit. Thus fitting the changes, which are random, and do not mean anything. Thus overfitting.

We know that cubic splines and Smoothing splines are different. The basic differences are:

  1. Smoothing splines try to minimize the function $$\sum_{i=1}^n(y_i-g(x_i))^2+\lambda\int g''(t)^2dt$$
  2. Smoothing splines shrink the parameters.

Moreover, Smoothing Splines are basically natural cubic splines, and thus they're smooth too.

So, how can these differences( and properties) save the Smoothing Spline from overfitting? Is there anything else that I'm missing here?

  • 5
    $\begingroup$ Regularization my friend, regularization. $\endgroup$ Aug 30, 2017 at 18:08
  • 4
    $\begingroup$ "wouldn't that be overfitting?" --- maybe if the coefficients were free parameters, but they aren't. $\endgroup$
    – Glen_b
    Aug 31, 2017 at 0:22

2 Answers 2


But, in my opinion wouldn't that be overfitting?


Your equation explains it all. $$\underbrace{\sum_{i=1}^n(y_i-g(x_i))^2}_\text{residual squares}+\underbrace{\lambda\int g''(t)^2dt}_\text{roughness penalty}$$

The second part $\lambda\int g''(t)^2dt$ is often called a roughness penalty, and $\lambda$ - roughness coefficient. The idea here is that first and second parts are competing. Think of this, if you make your function $g(x_i)=y_i$, i.e. go through each point exactly, then $\sum_{i=1}^n(y_i-g(x_i))^2=0$, but it usually leads to the function being very bumpy, it goes up and down trying to pass through each observation, which have noise in them. This would increase the contribution of the right part because generally $g''(x)$ will be higher, and depending on $\lambda$ the second part may become very large. Note, that $g''(x)$ is an approximation of the curvature of the spline.

So, you may find a curve that doesn't go exactly through each point $g(x_i)\ne y_i$ and $\sum_{i=1}^n(y_i-g(x_i))^2>0$, but your function becomes less bumpy, more smooth so that $g''(x)$ becomes smaller, and the increase in the first part is compensated by the decrease of the second part. Therefore, the roughness penalty does what shrinkage does, it actually cures overfitting.

Note, that the equation you gave is not the only possible way to build the smoothing spline. It's probably the simplest and most intuitive one. You could replace the second part with something different, e.g. $\lambda\int g'(t)^2dt$ would lead to the Laplacian kernel. It minimizes the length of the smooth curve.

The example actually has a simple physical representation. So let's start with an ordinary spline. Imagine that we nail a ring to the board at coordinates $x_i,y_i$, then we pass a flat spline through each ring. Now the shape of the flat spline is what you get from an ordinary (cubic) spline. Here how it looks (pic is from Wiki):

enter image description here

Now, instead of the ring, we nail springs into the same point. Then we attach the spline to the spring. Since the springs can extend the spline no longer will go through each observation! It'll relax a bit. What defines the shape of the new spline? The competition between the potential energy of the springs and the energy of tension in the flat spline. The more you bend the flat spline the more energy is in its tension, just like with a spring extension.

So, if you recall what is potential energy of a spring, it's just a square of its extension, which is given by the error (residual) $e_i=y_y-g(x_i)$, i.e. the sum of squares in the first part of your smoothing spline equation: enter image description here

Now the second part of your equation gives the potential energy of the tension in the spline. In my example $\lambda\int g'(t)^2dt$ represents an approximation of the length of the spline. So, the shape of the spline will be the one that minimizes the total potential energy (in your case) or sum of the potential energy of spring extensions and the length of the spline (in my example).


Having read the book myself, this statement refers to a regularized model (edit: I guess all smoothing splines are like that), where every point is a knot, but you are regularizing by adding $\lambda \int g''(x)^2$ to the loss function, so you are punishing a "wiggly function", as expressed in a large absolute second derivative. I believe they also point out that the $\lambda$ effectively maps to the degrees of freedom of the model (the higher the $\lambda$, the less variance in the estimated model, which means less overfitting)

Edit (also, I'm pretty sure I'm citing ISLR here more or less, so credits to them):

The way an algorithm finds a smoothing spline, is by minimizing the equation you outline in 1). This equation has two parts, the RHS and the LHS. The LHS is minimal, when all the $g(x_i) = y_i$. The RHS is minimal, if the second derivative of a $g()$ is 0 everywhere. That means, the function is at most linear. Clearly, these objectives for RHS and LHS are a trade off, because the LHS wants $g$ to be flexible, but the RHS wants $g$ to be linear. This trade-off is regulated through the $\lambda$.

If, e.g., $\lambda = \infty$, the second derivative HAS to be 0 to minimize the loss, which means that $g$ needs to be linear, corresponding to 0 knots (and the model has two degrees of freedom, intercept and slope).

If $\lambda = 0$, the RHS becomes irrelevant, and the objective is to minimize the LHS without constraints, which is achieved by setting one knot at each data point (and hence the model has n degrees of freedom)

  • $\begingroup$ By regularization, do you mean the shrinkage of parameters? If I'm wrong then please point me towards the right resources. $\endgroup$
    – Mooncrater
    Aug 31, 2017 at 12:22
  • $\begingroup$ updated my answer $\endgroup$
    – Sam
    Aug 31, 2017 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.