Mean Squared Error: Formula, Worked Examples, and RMSE
Calculate mean squared error, compare MSE with RMSE and MAE, and identify the right denominator in regression with six worked examples.
TL;DR
Mean squared error (MSE) is the average squared difference between actual and predicted values. Compute one squared error per observation, then average. Zero means every prediction matches. Larger errors have more influence after squaring.
Key Points
- Pair each prediction with the matching observation before subtracting.
- Prediction MSE divides the sum of squared errors by the number of observations.
- MSE uses squared units. Root mean squared error (RMSE) returns to the original units.
- Squared error penalises large misses more strongly than absolute error.
- Compare models on equivalent data, using the same units, weights, and evaluation method.
What is mean squared error?
For each observed value and prediction , take the difference . Either subtraction order gives the same square. With equally weighted observations,
First calculate the errors, then square before averaging. An overprediction of 3 and an underprediction of 3 give signed errors that cancel in an ordinary mean. Their squared errors are both 9. The MSE is always at least zero, and all included errors have to be zero for an unweighted MSE of zero. scikit-learn, Mean Squared Error
How do MSE, RMSE, MAE, and SSE differ?
| Measure | Calculation | Output units | What to check |
|---|---|---|---|
| SSE | Sum the squared errors | Squared units | Larger sample sizes can increase a sum |
| MSE | Divide SSE by the observation count | Squared units | Large errors receive greater weight through squaring |
| RMSE | Take the square root of MSE | Same units as the target | Convenient when interpreting magnitude in original units |
| MAE | Average the absolute errors | Same units as the target | Each error contributes in proportion to its size |
RMSE and MSE rank the same models identically when computed from the same observations with the same weights because the square root is increasing. MAE can rank them differently. If the data are in metres, SSE and MSE are computed in square metres, and MAE and RMSE are in metres. None of these metrics by itself gives the direction of an error. Use the average signed error and examine individual residuals when direction matters. scikit-learn, Metrics and Scoring
Which denominator should you use in regression?
For evaluating predictions across observations, divide SSE by . Regression output may also label a separate quantity “MSE” or residual mean square. In a full-rank ordinary least-squares fit with estimated coefficients, including the intercept when present, the residual variance estimate is
A straight line with an estimated slope and intercept uses . Its residual mean square divides by . Its training mean squared prediction error on those same rows divides by . The two numbers serve different purposes. The least-squares guide shows how to compute the fitted predictions before either division. NIST, Linear Least Squares Regression Glossary
Why does minimising squared error favour the mean?
Among constant predictions on a fixed set of numbers, the arithmetic mean minimises MSE. Let the constant be and the observed mean be . Expand as the sum of and . The cross terms sum to zero, giving
The first term is fixed, and the second is smallest at . This provides a baseline for judging whether a model predicts better than a constant. Compare both on held-out data. For model training, least squares applies the same squared-error idea to predictions that vary with the inputs. Portland State University, Regression and Least Squares
When is MSE a good comparison?
Use it when a few large errors matter more than many small ones, such as when large staffing forecast misses carry a disproportionate cost. Report RMSE alongside it if readers need the error scale in workers or hours. Check MAE when typical misses matter and compare signed error when overprediction and underprediction have different consequences.
If there are specified nonnegative weights with positive total, compute the weighted error:
A zero-weight observation contributes nothing. Apply identical weights to all models in a comparison. Changes in units matter too. Expressing an error in centimetres instead of metres multiplies it by 100, so its square grows by a factor of 10,000.
Worked Mean Squared Error Examples
Example 1
Find MSE for actual values 12, 17, and 9 and predictions 10, 18, and 12.
- The signed errors are 2, , and .
- The squared errors are 4, 1, and 9. Their sum is 14.
- The MSE is . RMSE is in original units.
Example 2
Model A has errors . Model B has errors . Which looks better under each loss?
- A has MAE and MSE .
- B has MAE and MSE .
- By MAE, A has the lower average absolute error. By MSE, B performs better because A’s error of 5 has more influence.
Example 3
Three delivery errors are minutes. The first two observations have weight 1, and the third has weight 2.
- Square the errors to get 1, 4, and 16.
- Weight and sum the squares: .
- Divide by the total weight 4. The weighted MSE is square minutes.
Example 4
A fitted straight line has SSE 30 across 12 training observations and estimates a slope and intercept.
- Mean squared prediction error on the training rows is .
- Residual degrees of freedom are .
- The residual mean square is . Use the denominator that matches the question.
Example 5
Find the constant with lowest MSE for observations 4, 5, and 12.
- Their mean is .
- Predicting 7 gives squares 9, 4, and 25, so the MSE is .
- Predicting 6 instead gives squares 4, 1, and 36. Its MSE is , exactly 1 larger, the squared distance from 6 to 7.
Example 6
A model has MSE square metres. Express its RMSE in centimetres.
- The RMSE is metres.
- Multiply by 100 to get 20 centimetres.
- The equivalent MSE in the new units is square centimetres.
Mistakes That Change MSE
Mistake 1: Squaring the average signed error
For errors and 2, the signed mean is zero. Squaring each first gives MSE 4.
Mistake 2: Comparing models on different random test sets
The measured loss also depends on the examples included. Use the same held-out observations or cross-validation splits to make the scores comparable.
Mistake 3: Interpreting MSE as an error in the target unit
If the target is dollars, MSE is in dollars squared. Use RMSE or MAE to express error in dollars.
Try It Yourself
- Find MSE for errors and 2.
- An RMSE is 6 kilometres. What is the corresponding MSE?
- Three observations have errors 0, 4, and 1 and weights 1, 0, and 3. What is the weighted MSE?
Answers and Reasoning
- .
- square kilometres.
- . The observation with error 4 has zero weight.
Frequently Asked Questions
Can MSE be negative?
The ordinary error metric cannot. Some model-selection tools report a sign-flipped score so that higher is better. Read the metric’s name and documentation before interpreting it.
Is any particular MSE good?
No universal threshold applies. Judge a value against the units, a relevant baseline on the same data, and the size of error the task can tolerate.
Is MSE the same as variance?
Training or test MSE uses predictions as the reference for every observation. If the prediction for every row is the observed mean, dividing by produces the average squared deviation from that mean. A sample variance often uses instead. See the standard deviation guide.
Conclusion
- Pair predictions with actual values and average the squared errors.
- Check whether the label refers to prediction MSE or residual mean square.
- Compare equivalent data and use RMSE or MAE when original units are easier to interpret.
Read More
- Understand the role of covariance in related measurements
- Understand correlation and spread in scatter plots
Research Behind This Article
- Scikit-learn developers, Metrics and Scoring: Mean Squared Error. scikit-learn
- Scikit-learn developers, mean_squared_error API Reference. scikit-learn
- National Institute of Standards and Technology, Linear Least Squares Regression Glossary. NIST
- David Gerbing, Portland State University, Introduction to Machine Learning: Linear Regression. Portland State