Mean Squared Error (MSE)

Machine Learning
Introduced by
Carl Friedrich Gauss
Year
1809
Type
Squared-error loss function
Family
Error metric

What does it do?

Mean Squared Error (MSE) is a loss and error metric for regression.

It averages the squared differences between observed values and model predictions. The least-squares principle, which minimizes the same sum of squared residuals, was published by Legendre in 1805 and by Gauss in 1809, with their priority disputed in the historical literature. MSE remains a common training objective for regression models.

The intuition behind the method

MSE squares each prediction error before averaging, so the penalty grows quadratically with error size: an error of 2 contributes 4 and an error of 4 contributes 16, so a few large misses can dominate the average. Because the result is in the squared units of the target, it is harder to read than RMSE, but the smooth quadratic form is convenient for optimization.

History

The least-squares method, which minimizes the sum of squared residuals, was published by Legendre (1805) and by Gauss (1809); these works concern least-squares fitting rather than a named MSE metric. The priority between Legendre and Gauss is disputed in the historical literature and remains unresolved. Gauss linked least squares to maximum-likelihood estimation under Gaussian errors. MSE, the mean of these squared residuals, is now a standard loss in statistics and a common objective in machine-learning regression. As a named metric, it has no single credited originator.

When to use it

Use MSE when the target is continuous, a squared-error criterion is a reasonable match for the cost of mistakes, and large errors should count disproportionately. It suits fitting linear models in closed form and gradient-based training, because the quadratic loss is differentiable everywhere. Avoid it, or pair it with a more robust measure, when the residuals contain outliers or heavy tails, when over- and under-predictions have unequal costs, or when the target is categorical; in the last case a likelihood-based loss such as cross-entropy is more appropriate. If results must be read in the original units, report RMSE or MAE alongside MSE.

Limitations and considerations

  • Highly sensitive to outliers: a single extreme residual contributes its square directly to the sum and can dominate the metric
  • Expressed in squared units of the target, so the value is hard to interpret against the original scale; taking the square root (RMSE) restores the units
  • Symmetric penalty: an over-prediction and an under-prediction of the same size contribute equally, so MSE cannot express cases where the two kinds of error have different costs
  • Scale-dependent: the value changes with the units of the target, so MSE values are not comparable across targets measured on different scales

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • The quadratic loss is smooth and differentiable everywhere, with a gradient that is simple to compute, which helps gradient-based optimization
  • For linear models, minimizing MSE has a closed-form solution, and residual-based variance estimates are straightforward to compute
  • The heavy penalty on large errors suits problems where a few big misses are costlier than many small ones
  • Under Gaussian errors, least-squares estimates coincide with maximum-likelihood estimates, which supports standard inference such as confidence intervals and hypothesis tests

Applications

  • Regression model training: minimizing MSE over linear or neural-network predictors for a continuous target
  • Forecast evaluation: comparing predicted and observed values of a continuous quantity, where large misses should weigh more than small ones
  • Control and estimation: quadratic cost functions in which deviations from a target state are penalized by their square
  • Image reconstruction: pixel-wise squared-error losses comparing a reconstructed image with a reference image

How it works

How it works

1

Calculate the residual for each observation: the observed value minus the predicted value.

Formula
e_i = y_i - \hat{y}_i
2

Square each residual. Squaring makes the contribution of a large deviation grow quadratically relative to a small one.

Formula
e_i^2 = (y_i - \hat{y}_i)^2
3

Sum the squared residuals and divide by the number of observations n to obtain the mean squared error.

Formula
MSE = \frac{1}{n} \sum_{i=1}^{n} (y_i - \hat{y}_i)^2

Common pitfalls

  • Comparing MSE across different targets or units; because the value depends on scale, normalize by the target variance (for example via R²) before comparing
  • Treating low training MSE as evidence of good generalization; the value must be checked on held-out data
  • Optimizing MSE but reporting RMSE to stakeholders without explaining that the two rank models identically but are in different units

Frequently asked questions

What is the difference between MSE and RMSE?

MSE is the mean of squared errors (in squared units). RMSE is the square root of MSE, returning the metric to original units. They rank models identically, but RMSE is more interpretable while MSE is easier to optimize.

Why is MSE preferred for optimization over MAE?

MSE is smooth and differentiable everywhere, allowing efficient gradient descent. MAE has a non-smooth kink at zero, complicating gradient-based optimization. However, specialized solvers can handle MAE.

Can I use MSE as a loss function for classification?

Technically yes, but it is not recommended. MSE treats classification as regression and can lead to poor probability estimates. Use cross-entropy loss (logistic loss) for binary classification or categorical cross-entropy for multiclass.

How does MSE relate to variance?

MSE can be decomposed as Bias² + Variance + Irreducible Error. This decomposition applies to the expected squared error of a predictor over repeated samples and new data, not to a single in-sample MSE computed on training residuals as in the mechanics. For an estimator, MSE equals its variance plus its squared bias, the general relation shown in Principles of Econometrics (5th ed.), Appendix 4C. The decomposition underpins the bias-variance tradeoff in model selection.

Is high MSE always bad?

Not necessarily. If your target variable has high variance, even perfect predictions will have nonzero MSE due to irreducible error. Always compare MSE to baseline models and normalize by target variance (via R²) for context.

Related methods

Sources

  1. Gauss, C. F. (1809). Theoria Motus Corporum Coelestium in Sectionibus Conicis Solem Ambientium. Hamburg: Perthes and Besser.

    Open publication reference
  2. Legendre, A. M. (1805). Nouvelles méthodes pour la détermination des orbites des comètes. Paris: F. Didot.

    Open publication reference
  3. Goodman, L. A. (1960). On the exact variance of products. Journal of the American Statistical Association, 55(292), 708-713.

    Open DOI reference
  4. Principles of Econometrics, 5th Edition, Appendix 4C: Mean Squared Error: Estimation and Prediction, p. 195