Consider a synthetic data based on the sinusoidal function which is generated from the function $\sin(2\pi x)$ with random noise included in the target values. Suppose that we are given a training set $X\equiv(x_1,\cdots,x_N)^{\text T}$, together with corresponding observations of the values $T\equiv(t_1,\cdots,t_N)^{\text T}$.
The goal is to achieve good generalization by making accurate predictions for new data. In particular, we shall fit the data using a polynomial function of the form
$$ y(x,\bold w)=\sum_{j=0}^Mw_jx^j $$
with $\bold w=(w_0,\cdots,w_M)$.
We fit the polynomial to the training data by minimizing an error function that measures the misfit between the function $y(x,\bold w)$, for any given value of $\bold w$, and the training set data points, then the resulting polynomial is given by the function $y(x,\bold w^*)$. Here we use the following function as error function
$$ E(\bold w)=\frac{1}{2}\sum_{n=1}^N\{y(x_n,\bold w)-t_n\}^2 $$
We can obtain some quantitative insight into the dependence of the generalization performance on $M$ by considering a separate test set comprising 100 data points generated using exactly the same procedure used to generate the training set pings but with new choices for the random noise values included in the target values. For each choice of $M$, we can then evaluate the residual value of $E(\bold w^*)$ for the training data and test data set. In this case, we use the root-mean-square(RMS) defined by
$$ E_{\text {RMS}}=\sqrt{2E(\bold w^*)/N} $$
as the residual value of $E(\bold w^*)$. The test set error is a measure of how well we are doing in predicting the values of $t$ for new data observations of $x$.
The more flexible polynomials with larger values of $M$ are becoming increasing tuned to the random noise on the target values. This behavior is known as over-fitting.
For a given model complexity, the over-fitting problem become less severe as the size of the data set increases.
One rough heuristic that is sometimes advocated is that the number of data points should be no less than some multiple (say 5 or 10) of the number of adaptive parameters in the model.
In data sets of limited size where we may wish to use relatively flexible models, to control the over-fitting phenomenon we use regularization which involves adding a penalty term to the error function in order to discourage the coefficients from reaching large values.
The simplest such penalty term takes the form of a sum of squares of all of the coefficients, leading to a modified error function of the from
$$ \tilde E(\bold w)=\frac{1}{2}\sum_{n=1}^N\{y(x_n,\bold w)-t_n\}^2+\frac{\lambda}{2}\|\bold w\|^2 $$
$\lambda$ controls the effective complexity of the model and hence determines the degree of over-fitting.
A simple way to determine a suitable value for the model complexity is to take the available data and partitioning it into a training set, used to determine the coefficients $\bold w$, and a separate validation set, used to optimize the model complexity (either $M$ or $\lambda)$. In many cases, however, this will prove to be too wasteful of valuable training data.