When doing regression, for example, two hyper parameters to choose are often the capacity of the function (eg. the largest exponent of a polynomial), and the amount of regularisation. What I'm confused about, is why not just choose a low capacity function, and then ignore any regularisation? In that way, it will not overfit. If I have a high capacity function together with regularisation, isn't that just the same as having a low capacity function and no regularisation?
I recently made a little in browser app that you can use to play with these ideas: Scatterplot Smoothers (*).
Here's some data I made up, with a low degree polynomial fit
It's clear that the quadratic polynomial is just not flexible enough to give a good fit to the data. We have regions of very high bias, between $0.6$ and $0.85$ all the data is below the fit, and after $0.85$ all the data is above the curve.
To rid ourselves of bias, we can increase the degree of the curve to three, but the problem remains, the cubic curve is still too rigid
So we continue to increase the degree, but now we incur the opposite problem
This curve tracks the data too closely, and has a tendency to fly off in directions not so well borne out by general patterns in the data. This is where regularization comes in. With the same degree curve (ten) and some well chosen regularization
We get a really nice fit!
It's worth a little focus on one aspect of well chosen above. When you are fitting polynomials to data you have a discrete set of choices for degree. If a degree three curve is underfit and a degree four curve is overfit, you have nowhere to go in the middle. Regularization solves this problem, as it gives you a continuous range of complexity parameters to play with.
how do you claim "We get a really nice fit!". For me they all look the same, namely, inconclusive. Which rational are you using to decide what is a nice and a bad fit?
The assumption I'm making here is that a well fit model should have no discernable pattern in the residuals. Now, I'm not plotting the residuals, so you have to do a little bit of work when looking at the pictures, but you should be able to use your imagination.
In the first picture, with the quadratic curve fit to the data, I can see the following pattern in the residuals
- From 0.0 to 0.3 they are about evenly placed above and below the curve.
- From 0.3 to about 0.55 all the data points are above the curve.
- From 0.55 to about 0.85 all the data points are below the curve.
- From 0.85 on, they are all above the curve again.
I'd refer to these behaviours as local bias, there are regions where the curve is not well approximating the conditional mean of the data.
Compare this to the last fit, with the cubic spline. I can't pick out any regions by eye where the fit does not look like it's running precisely through the center of mass of the data points. This is generally (though imprecisely) what I mean by a good fit.
Final Note: Take all this as illustration. In practice, I do not recommend using polynomial basis expansions for any degree higher than $2$. Thier problems are well discussed elsewhere, but, for example:
- Their behaviour at the boundaries of your data can be very chaotic, even with regularization.
- They are not local in any sense. Changing your data in one place can significantly affect the fit in a very different place.
I instead, in a situation like you describe, reccomend using natural cubic splines along with regularization, which give the best compromise between flexibility and stability. You can see for yourself by fitting some splines in the app.
No, it isn't the same. Compare, for example, a second-order polynomial without regularization to a fourth-order polynomial with it. The latter can posit big coefficients for the third and fourth powers so long as this seems to increase predictive accuracy, according to whatever procedure is used to choose the penalty size for the regularization procedure (probably cross-validation). This shows that one of the benefits of regularization is that it allows you to automatically adjust model complexity to strike a balance between overfitting and underfitting.
All the answers are great and I have similar simulations with Matt to give you another example to show why complex model with regularization is usually better than simple model.
I made a analogy to have intuitive explanation.
- Case 1 you only have a high school student with limited knowledge (a simple model without regularization)
- Case 2 you have a graduate student but restrict him/her to only use high school knowledge to solve problems. (complex model with regularization)
If two persons are solving the same problem, usually the graduate students would work better solution, because the experience and insights about the knowledge.
Figure 1 is showing 4 fittings to the same data. 4 fittings are line, parabola, 3rd order model and 5th order model. You can observe the 5th order model may have overfitting problem.
On the other hand, in the second experiment, we will use 5th order model with different level of regularization. Compare last one with the second order model. (two models are highlighted) you will find the last one is similar (roughly have the same model complexity) to parabola, but slightly more flexible to the data well.
Model Complexity (model flexibility) is about representing the structures hidden in the data. To take an example of polynomial curve fitting, a higher-order polynomial (say, parabola/quadratic) provides more flexibility to represent the hidden structures compared to a lower-order one (say, line/linear) if there is indeed a hidden parabolic structure (that we found using EDA).
So, where does Regularization come in?
The observations/outcomes of a random experiment are noisy (we assume gaussian noise as a good approximation). When we use a higher-order polynomial, the higher the polynomial, the more the training points that lie exactly on the fitted curve. But, this results in poor generalization and the test set results are disappointing.
When we examine the coefficients of the higher order polynomials, they carry very high values. What has happened is that even though the model is flexible, it has tuned itself to the gaussian noise, so much so that the fitted curve oscillates rapidly near the ends of intervals between data points. So, during testing, a slight off-x results in a big off-y.
Regularization helps in keeping these coefficients at lower values, hence, the curve is smooth. We now have less training points on the curve, more training error, but less test error, means, better generalization (less Overfitting).
The choice between higher order polynomial and regularization is not that of excluding one for the other, but that of striking a balance between how higher the polynomial can be without losing too much on generalization.
When we talk about order of polynomial and regularization in the context of generalization/less-overfitting, there is a third lever that can reduce the overfitting caused by a higher-order polynomial. This lever is 'size of data'. More data helps in accommodating a higher-order polynomial.
References: 1 Pattern Recognition and Machine Learning - Christopher Bishop