Understand the reason for calculating the MSE Im following an introduction course into R-machine Learning. Im doing the following:


*

*Load the faithful dataset (standard in R)

*Creating a model that predicts waiting time -> eruptions of the first 136 items of the dataframe.
mymodel = glm(data=faithful[1:136,], waiting ~ eruptions)

*Calculate the mean standard error on the second half of the data.
mean((faithful$waiting - predict(mymodel, faithful[137:272, ])), ^2)
The way I see it you take the mean of all waitingtimes - the predicted values (using the glm model) and do exponent^2.
I do not understand however why exactly this is done? Could anybody explain this to me in plain English?
 A: Using mean squared error can be seen as a special case of the maximum likelihood parameter estimation. One wants to choose the model such that the likelihood of the observation is maximal for the selected model. The likelihood is:
$$
{\cal L} = p(z_1|y_1) \cdot \ldots \cdot p(z_N|y_N)
$$
where p(z|y) is the probability of the observed value z when the model predicts value y. 
So 'fitting' a model is done by maximizing L or equivalently minimizing 
$$
    - \log({\cal L})
$$
If you assume a Normal distribution centered at the y_i for the p's and you assume that all p's have the same width parameter sigma (set to one for convenience), you'll get:
$$
    - \log ({\cal L}) = constant - \log ( e^{-\frac{1}{2} \cdot (y_1-z_1)^2} ) - \ldots - \log ( e^{-\frac{1}{2} \cdot (y_N-z_N)^2} )
$$
Setting the width parameter of all Gaussians to the same value means that all your measurements have the same uncertainty (i.e. the same precision).
where the log and exp cancel each other and you'll end up with:
$$
    - \log ({\cal L}) = constant + \frac{1}{2} \cdot (y_1-z_1)^2 + ... + \frac{1}{2} \cdot (y_N-z_N)^2
$$
For the purposes of minimization, you can drop the constant and also the factors 0.5 and you'll end up with the mean (or summed) squared error.
