Mean squared error explained

In statistics, the mean squared error (MSE)[1] or mean squared deviation (MSD) of an estimator (of a procedure for estimating an unobserved quantity) measures the average of the squares of the errors—that is, the average squared difference between the estimated values and the actual value. MSE is a risk function, corresponding to the expected value of the squared error loss.[2] The fact that MSE is almost always strictly positive (and not zero) is because of randomness or because the estimator does not account for information that could produce a more accurate estimate.[3] In machine learning, specifically empirical risk minimization, MSE may refer to the empirical risk (the average loss on an observed data set), as an estimate of the true MSE (the true risk: the average loss on the actual population distribution).

The MSE is a measure of the quality of an estimator. As it is derived from the square of Euclidean distance, it is always a positive value that decreases as the error approaches zero.

The MSE is the second moment (about the origin) of the error, and thus incorporates both the variance of the estimator (how widely spread the estimates are from one data sample to another) and its bias (how far off the average estimated value is from the true value). For an unbiased estimator, the MSE is the variance of the estimator. Like the variance, MSE has the same units of measurement as the square of the quantity being estimated. In an analogy to standard deviation, taking the square root of MSE yields the root-mean-square error or root-mean-square deviation (RMSE or RMSD), which has the same units as the quantity being estimated; for an unbiased estimator, the RMSE is the square root of the variance, known as the standard error.

Definition and basic properties

The MSE either assesses the quality of a predictor (i.e., a function mapping arbitrary inputs to a sample of values of some random variable), or of an estimator (i.e., a mathematical function mapping a sample of data to an estimate of a parameter of the population from which the data is sampled). In the context of prediction, understanding the prediction interval can also be useful as it provides a range within which a future observation will fall, with a certain probability. The definition of an MSE differs according to whether one is describing a predictor or an estimator.

Predictor

If a vector of

n

predictions is generated from a sample of

n

data points on all variables, and

Y

is the vector of observed values of the variable being predicted, with

\hat{Y}

being the predicted values (e.g. as from a least-squares fit), then the within-sample MSE of the predictor is computed as
\operatorname{MSE}=1
n
n
\sum
i=1

\left(Yi-\hat{Y

2
i}\right)

In other words, the MSE is the mean \left(\frac \sum_^n \right) of the squares of the errors \left(Y_i-\hat\right)^2. This is an easily computable quantity for a particular sample (and hence is sample-dependent).

In matrix notation,

\operatorname{MSE}=1
n
2=1
n
\sum
i)

eTe

where

ei

is

(Yi-\hat{Yi})

and

e

is a

n x 1

column vector.

The MSE can also be computed on q data points that were not used in estimating the model, either because they were held back for this purpose, or because these data have been newly obtained. Within this process, known as cross-validation, the MSE is often called the test MSE,[4] and is computed as

\operatorname{MSE}=

1
q
n+q
\sum
i=n+1

\left(Yi-\hat{Y

2
i}\right)

Estimator

The MSE of an estimator

\hat{\theta}

with respect to an unknown parameter

\theta

is defined as

\operatorname{MSE}(\hat{\theta})=\operatorname{E}\theta\left[(\hat{\theta}-\theta)2\right].

This definition depends on the unknown parameter, but the MSE is a priori a property of an estimator. The MSE could be a function of unknown parameters, in which case any estimator of the MSE based on estimates of these parameters would be a function of the data (and thus a random variable). If the estimator

\hat{\theta}

is derived as a sample statistic and is used to estimate some population parameter, then the expectation is with respect to the sampling distribution of the sample statistic.

The MSE can be written as the sum of the variance of the estimator and the squared bias of the estimator, providing a useful way to calculate the MSE and implying that in the case of unbiased estimators, the MSE and variance are equivalent.[5]

\operatorname{MSE}(\hat{\theta})=\operatorname{Var}\theta(\hat{\theta})+\operatorname{Bias}(\hat{\theta},\theta)2.

Proof of variance and bias relationship

\begin{align} \operatorname{MSE}(\hat{\theta}) &=\operatorname{E}\theta\left[(\hat{\theta}-\theta)2\right]\\ &=\operatorname{E}\theta\left[\left(\hat{\theta}-\operatorname{E}\theta[\hat\theta]+\operatorname{E}\theta[\hat\theta]-\theta\right)2\right]\ &=\operatorname{E}\theta\left[\left(\hat{\theta}-\operatorname{E}\theta[\hat\theta]\right)2+2\left(\hat{\theta}-\operatorname{E}\theta[\hat\theta]\right)\left(\operatorname{E}\theta[\hat\theta]-\theta\right)+\left(\operatorname{E}\theta[\hat\theta]-\theta\right)2\right]\ &=\operatorname{E}\theta\left[\left(\hat{\theta}-\operatorname{E}\theta

2\right]+\operatorname{E}
[\hat\theta]\right)
\theta

\left[2\left(\hat{\theta}-\operatorname{E}\theta[\hat\theta]\right)\left(\operatorname{E}\theta[\hat\theta]-\theta\right)\right]+\operatorname{E}\theta\left[\left(\operatorname{E}\theta[\hat\theta]-\theta\right)2\right]\\ &=\operatorname{E}\theta\left[\left(\hat{\theta}-\operatorname{E}\theta[\hat\theta]\right)2\right]+2\left(\operatorname{E}\theta[\hat\theta]-\theta\right)\operatorname{E}\theta\left[\hat{\theta}-\operatorname{E}\theta[\hat\theta]\right]+\left(\operatorname{E}\theta[\hat\theta]-\theta\right)2&&\operatorname{E}\theta[\hat\theta]-\theta=const.\\ &=\operatorname{E}\theta\left[\left(\hat{\theta}-\operatorname{E}\theta[\hat\theta]\right)2\right]+2\left(\operatorname{E}\theta[\hat\theta]-\theta\right)\left(\operatorname{E}\theta[\hat{\theta}]-\operatorname{E}\theta[\hat\theta]\right)+\left(\operatorname{E}\theta[\hat\theta]-\theta\right)2&&\operatorname{E}\theta[\hat\theta]=const.\\ &=\operatorname{E}\theta\left[\left(\hat\theta-\operatorname{E}\theta

2\right]+\left(\operatorname{E}
[\hat\theta]\right)
\theta

[\hat\theta]-\theta\right)2\ &=\operatorname{Var}\theta(\hat\theta)+\operatorname{Bias}\theta(\hat\theta,\theta)2 \end{align}

An even shorter proof can be achieved using the well-known formula that for a random variable X, \mathbb(X^2) = \operatorname(X) + (\mathbb(X))^2. By substituting X with, \hat\theta-\theta, we have\begin\operatorname(\hat) &= \mathbb[(\hat\theta-\theta)^2] \\&= \operatorname(\hat - \theta) + (\mathbb[\hat\theta - \theta])^2 \\&= \operatorname(\hat\theta) + \operatorname^2(\hat\theta,\theta)\endBut in real modeling case, MSE could be described as the addition of model variance, model bias, and irreducible uncertainty (see Bias–variance tradeoff). According to the relationship, the MSE of the estimators could be simply used for the efficiency comparison, which includes the information of estimator variance and bias. This is called MSE criterion.

In regression

In regression analysis, plotting is a more natural way to view the overall trend of the whole data. The mean of the distance from each point to the predicted regression model can be calculated, and shown as the mean squared error. The squaring is critical to reduce the complexity with negative signs. To minimize MSE, the model could be more accurate, which would mean the model is closer to actual data. One example of a linear regression using this method is the least squares method—which evaluates appropriateness of linear regression model to model bivariate dataset,[6] but whose limitation is related to known distribution of the data.

The term mean squared error is sometimes used to refer to the unbiased estimate of error variance: the residual sum of squares divided by the number of degrees of freedom. This definition for a known, computed quantity differs from the above definition for the computed MSE of a predictor, in that a different denominator is used. The denominator is the sample size reduced by the number of model parameters estimated from the same data, (np) for p regressors or (np−1) if an intercept is used (see errors and residuals in statistics for more details).[7] Although the MSE (as defined in this article) is not an unbiased estimator of the error variance, it is consistent, given the consistency of the predictor.

In regression analysis, "mean squared error", often referred to as mean squared prediction error or "out-of-sample mean squared error", can also refer to the mean value of the squared deviations of the predictions from the true values, over an out-of-sample test space, generated by a model estimated over a particular sample space. This also is a known, computed quantity, and it varies by sample and by out-of-sample test space.

In the context of gradient descent algorithms, it is common to introduce a factor of

1/2

to the MSE for ease of computation after taking the derivative. So a value which is technically half the mean of squared errors may be called the MSE.

Examples

Mean

Suppose we have a random sample of size

n

from a population,

X1,...,Xn

. Suppose the sample units were chosen with replacement. That is, the

n

units are selected one at a time, and previously selected units are still eligible for selection for all

n

draws. The usual estimator for the

\mu

is the sample average
\overline{X}=1
n
n
\sum
i=1

Xi

which has an expected value equal to the true mean

\mu

(so it is unbiased) and a mean squared error of
2\right]=\left(\sigma
\sqrt{n
\operatorname{MSE}\left(\overline{X}\right)=\operatorname{E}\left[\left(\overline{X}-\mu\right)
}\right)^2= \frac

where

\sigma2

is the population variance.

For a Gaussian distribution, this is the best unbiased estimator (i.e., one with the lowest MSE among all unbiased estimators), but not, say, for a uniform distribution.

Variance

The usual estimator for the variance is the corrected sample variance:

2
S
n-1

=

1
n-1
n\left(X
\sum
i-\overline{X}

\right)2=

1
n-1
n
\left(\sum
i=1
2-n\overline{X}
X
i

2\right).

This is unbiased (its expected value is

\sigma2

), hence also called the unbiased sample variance, and its MSE is[8]
2
\operatorname{MSE}(S
n-1

)=

1
n
\left(\mu
4-n-3
n-1

\sigma4\right)=

1
n
\left(\gamma
2+2n
n-1

\right)\sigma4,

where

\mu4

is the fourth central moment of the distribution or population, and

\gamma2=\mu

4-3
4/\sigma
is the excess kurtosis.

However, one can use other estimators for

\sigma2

which are proportional to
2
S
n-1
, and an appropriate choice can always give a lower mean squared error. If we define
2
S
a

=

n-1
a
2
S
n-1

=

1
a
2
\sum
i-\overline{X}\right)

then we calculate:

2
\begin{align} \operatorname{MSE}(S
a) &=\operatorname{E}\left[\left(n-1
a
2
S
n-1

-\sigma2\right)2\right]\\ &=\operatorname{E}\left[

(n-1)2
a2
4
S
n-1

-2\left(

n-1
a
2
S
n-1

\right)\sigma2+\sigma4\right]\\ &=

(n-1)2
a2

\operatorname{E}\left[

4
S
n-1

\right]-2\left(

n-1
a

\right)\operatorname{E}\left[

2
S
n-1

\right]\sigma2+\sigma4\\ &=

(n-1)2
a2

\operatorname{E}\left[

4
S
n-1

\right]-2\left(

n-1
a

\right)\sigma4+\sigma4&&\operatorname{E}\left[

2
S
n-1

\right]=\sigma2\\ &=

(n-1)2
a2

\left(

\gamma2
n

+

n+1
n-1

\right)\sigma4-2\left(

n-1
a

\right)\sigma4+\sigma4&&\operatorname{E}\left[

4
S
n-1

\right]=

2
\operatorname{MSE}(S
n-1

)+\sigma4\\ &=

n-1
na2

\left

2+n
((n-1)\gamma
2+n

\right)\sigma4-2\left(

n-1
a

\right)\sigma4+\sigma4\end{align}

This is minimized when

a=
2+n
(n-1)\gamma
2+n
n

=n+1+

n-1
n

\gamma2.

For a Gaussian distribution, where

\gamma2=0

, this means that the MSE is minimized when dividing the sum by

a=n+1

. The minimum excess kurtosis is

\gamma2=-2

, which is achieved by a Bernoulli distribution with p = 1/2 (a coin flip), and the MSE is minimized for

a=n-1+\tfrac{2}{n}.

Hence regardless of the kurtosis, we get a "better" estimate (in the sense of having a lower MSE) by scaling down the unbiased estimator a little bit; this is a simple example of a shrinkage estimator: one "shrinks" the estimator towards zero (scales down the unbiased estimator).

Further, while the corrected sample variance is the best unbiased estimator (minimum mean squared error among unbiased estimators) of variance for Gaussian distributions, if the distribution is not Gaussian, then even among unbiased estimators, the best unbiased estimator of the variance may not be

2
S
n-1

.

Gaussian distribution

The following table gives several estimators of the true parameters of the population, μ and σ2, for the Gaussian case.[9]

True value Estimator Mean squared error

\theta=\mu

\hat{\theta}

= the unbiased estimator of the population mean,
\overline{X}=1
n
n(X
\sum
i)
2)=\left(\sigma
\sqrt{n
\operatorname{MSE}(\overline{X})=\operatorname{E}((\overline{X}-\mu)
}\right)^2

\theta=\sigma2

\hat{\theta}

= the unbiased estimator of the population variance,
2
S
n-1

=

1
n-1
2
\sum
i-\overline{X}\right)
2
\operatorname{MSE}(S
n-1
2
)=\operatorname{E}((S
n-1

-\sigma2)

2)=2
n-1

\sigma4

\theta=\sigma2

\hat{\theta}

= the biased estimator of the population variance,
2
S
n

=

1
n
2
\sum
i-\overline{X}\right)
2
\operatorname{MSE}(S
n
2
)=\operatorname{E}((S
n

-\sigma2)

2)=2n-1
n2

\sigma4

\theta=\sigma2

\hat{\theta}

= the biased estimator of the population variance,
2
S
n+1

=

1
n+1
2
\sum
i-\overline{X}\right)
2
\operatorname{MSE}(S
n+1
2
)=\operatorname{E}((S
n+1

-\sigma2)

2)=2
n+1

\sigma4

Interpretation

An MSE of zero, meaning that the estimator

\hat{\theta}

predicts observations of the parameter

\theta

with perfect accuracy, is ideal (but typically not possible).

Values of MSE may be used for comparative purposes. Two or more statistical models may be compared using their MSEs—as a measure of how well they explain a given set of observations: An unbiased estimator (estimated from a statistical model) with the smallest variance among all unbiased estimators is the best unbiased estimator or MVUE (Minimum-Variance Unbiased Estimator).

Both analysis of variance and linear regression techniques estimate the MSE as part of the analysis and use the estimated MSE to determine the statistical significance of the factors or predictors under study. The goal of experimental design is to construct experiments in such a way that when the observations are analyzed, the MSE is close to zero relative to the magnitude of at least one of the estimated treatment effects.

In one-way analysis of variance, MSE can be calculated by the division of the sum of squared errors and the degree of freedom. Also, the f-value is the ratio of the mean squared treatment and the MSE.

MSE is also used in several stepwise regression techniques as part of the determination as to how many predictors from a candidate set to include in a model for a given set of observations.

Applications

Loss function

Squared error loss is one of the most widely used loss functions in statistics, though its widespread use stems more from mathematical convenience than considerations of actual loss in applications. Carl Friedrich Gauss, who introduced the use of mean squared error, was aware of its arbitrariness and was in agreement with objections to it on these grounds. The mathematical benefits of mean squared error are particularly evident in its use at analyzing the performance of linear regression, as it allows one to partition the variation in a dataset into variation explained by the model and variation explained by randomness.

Criticism

The use of mean squared error without question has been criticized by the decision theorist James Berger. Mean squared error is the negative of the expected value of one specific utility function, the quadratic utility function, which may not be the appropriate utility function to use under a given set of circumstances. There are, however, some scenarios where mean squared error can serve as a good approximation to a loss function occurring naturally in an application.[10]

Like variance, mean squared error has the disadvantage of heavily weighting outliers.[11] This is a result of the squaring of each term, which effectively weights large errors more heavily than small ones. This property, undesirable in many applications, has led researchers to use alternatives such as the mean absolute error, or those based on the median.

See also

Notes and References

  1. Web site: Mean Squared Error (MSE). 2020-09-12. www.probabilitycourse.com.
  2. Book: Mathematical Statistics: Basic Ideas and Selected Topics . I . Second . Bickel . Peter J. . Peter J. Bickel . Doksum . Kjell A. . 2015 . 20 . "If we use quadratic loss, our risk function is called the mean squared error (MSE) ...".
  3. Book: E. L. . Lehmann . George . Casella . Theory of Point Estimation . Springer . New York . 1998 . 2nd . 978-0-387-98502-2 . 1639875.
  4. Book: James. Gareth. Daniela. Witten. Trevor. Hastie. Rob. Tibshirani. 2021. An Introduction to Statistical Learning: with Applications in R. Springer. 978-1071614174.
  5. Book: Dennis . Wackerly . William. Mendenhall . Richard L.. Scheaffer . Mathematical Statistics with Applications . Thomson Higher Education. Belmont, CA, USA . 2008 . 7 . 978-0-495-38508-0.
  6. Book: A modern introduction to probability and statistics : understanding why and how. 2005. Springer. Dekking, Michel, 1946-. 978-1-85233-896-1. London. 262680588.
  7. Steel, R.G.D, and Torrie, J. H., Principles and Procedures of Statistics with Special Reference to the Biological Sciences., McGraw Hill, 1960, page 288.
  8. Book: Mood, A. . Graybill . F. . Boes . D. . Introduction to the Theory of Statistics . limited . 229 . 3rd . McGraw-Hill . 1974.
  9. Book: DeGroot, Morris H. . Morris H. DeGroot . Probability and Statistics . 2nd . Addison-Wesley . 1980 . degroot .
  10. Book: Berger, James O. . Statistical Decision Theory and Bayesian Analysis . limited . James Berger (statistician) . 1985 . 2nd . Springer-Verlag . New York . 978-0-387-96098-2 . 0804611 . 2.4.2 Certain Standard Loss Functions . 60.
  11. Bermejo . Sergio . Cabestany . Joan . 2001 . Oriented principal component analysis for large margin classifiers . Neural Networks . 14 . 10. 1447–1461 . 10.1016/S0893-6080(01)00106-X. 11771723 .