Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Mean Squared Error: Definition & Formula

· 7 min read · Home Tech

In this article
  1. Formula
  2. Worked Example
  3. Why Square the Errors?
  4. How to Interpret MSE
  5. Common Mistakes and Pitfalls
  6. MSE vs. MAE vs. RMSE
  7. Limitations of MSE
  8. Frequently Asked Questions

Mean squared error (MSE) measures the average squared difference between predicted values and actual values. You enter a list of observed values and a list of predicted values, and the calculator returns the MSE along with related error metrics. It is the most widely used loss function in regression analysis and machine learning because it penalizes large errors more heavily than small ones.

in obs | Observed values (comma-separated) | - | 3, 5, 2.5, 7, 4 | 0 | 1000000
in pred | Predicted values (comma-separated) | - | 2.5, 5.5, 2, 8, 3.5 | 0 | 1000000
out mse | Mean Squared Error | - | mean((obs - pred)^2) | 4
out rmse | Root Mean Squared Error | - | sqrt(mean((obs - pred)^2)) | 4
out mae | Mean Absolute Error | - | mean(abs(obs - pred)) | 4
out n | Number of pairs | - | count(obs) | 0

Formula

The mean squared error is defined as:

MSE = (1/n) * Σ(yᵢ - ŷᵢ)²

where:

  • n = number of data points (pairs of observed and predicted values)
  • yᵢ = the i-th observed (actual) value
  • ŷᵢ = the i-th predicted (estimated) value
  • Σ = summation over all n data points

The units of MSE are the square of the units of the original data. For example, if you are predicting house prices in dollars, MSE is in dollars squared. To get back to the original units, take the square root, which gives the root mean squared error (RMSE).

Worked Example

Using the default values from the calculator:

Observed: 3, 5, 2.5, 7, 4
Predicted: 2.5, 5.5, 2, 8, 3.5

Step 1: Compute the differences (observed - predicted):

  • 3 - 2.5 = 0.5
  • 5 - 5.5 = -0.5
  • 2.5 - 2 = 0.5
  • 7 - 8 = -1
  • 4 - 3.5 = 0.5

Step 2: Square each difference:

  • 0.5² = 0.25
  • (-0.5)² = 0.25
  • 0.5² = 0.25
  • (-1)² = 1
  • 0.5² = 0.25

Step 3: Sum the squared differences: 0.25 + 0.25 + 0.25 + 1 + 0.25 = 2.0

Step 4: Divide by n = 5: MSE = 2.0 / 5 = 0.4

The calculator shows MSE = 0.4, RMSE = √0.4 ≈ 0.6325, and MAE = (0.5 + 0.5 + 0.5 + 1 + 0.5)/5 = 3.0/5 = 0.6.

Why Square the Errors?

Squaring serves two purposes. First, it removes the sign: positive and negative errors do not cancel out. If you simply averaged the raw differences, a model that over-predicts half the time and under-predicts the other half could appear perfect even when every prediction is wrong. Squaring makes all errors positive.

Second, squaring gives more weight to large errors. A prediction off by 10 units contributes 100 to the MSE, while a prediction off by 1 unit contributes only 1. This is often desirable because large errors are usually more costly in real-world applications. However, it also means MSE is sensitive to outliers: a single extreme value can dominate the metric.

How to Interpret MSE

MSE has no absolute “good” or “bad” threshold—it depends entirely on the scale of your data. An MSE of 0.4 for values ranging from 2 to 7 (as in the example) is quite small. But an MSE of 0.4 for values ranging from 0 to 1 is relatively large.

A common approach is to compare MSE across different models on the same dataset. The model with the lower MSE is generally better. You can also use RMSE to express the average error in the same units as the data. In the example, the RMSE of 0.63 means the typical prediction error is about 0.63 units, even though individual errors range from 0.5 to 1.

Another useful comparison is against the variance of the observed values. If MSE is close to the variance, the model is barely better than just predicting the mean every time. If MSE is much smaller than the variance, the model captures a substantial portion of the variability.

Common Mistakes and Pitfalls

  • Mismatched lists: The observed and predicted lists must have the same length. The calculator checks this and returns “Cannot compute” if they differ.
  • Unit confusion: MSE is in squared units. If you report MSE for temperatures in Celsius, the result is in °C², which is hard to interpret. Always report RMSE alongside.
  • Outlier sensitivity: Because errors are squared, one bad prediction can inflate MSE dramatically. If your data has extreme outliers, consider mean absolute error (MAE) or median absolute deviation instead.
  • Using MSE for classification: MSE is designed for continuous numeric predictions. For classification (e.g., predicting categories), use cross-entropy or accuracy metrics.
  • Overfitting: Minimizing MSE on training data can lead to overfitting—a model that memorizes noise instead of learning patterns. Always evaluate MSE on a separate test set.

MSE vs. MAE vs. RMSE

Mean absolute error (MAE) is the average absolute difference between predictions and observations. It is less sensitive to outliers because it does not square the errors. RMSE is the square root of MSE and is in the same units as the data. RMSE is always greater than or equal to MAE; the difference grows as the error distribution becomes more spread out.

When to use which:

  • MSE: When you want to penalize large errors heavily, or when you are using gradient-based optimization (its derivative is simpler).
  • RMSE: When you want an interpretable error in the original units but still want to penalize large errors.
  • MAE: When you want a robust metric that treats all errors equally, especially if outliers are present.

In practice, many practitioners report both RMSE and MAE to get a fuller picture of model performance.

Limitations of MSE

MSE assumes that the errors are symmetrically distributed around zero. If your model consistently over-predicts or under-predicts, MSE will be high even if the pattern is systematic. It also assumes that all data points are equally important; if some observations are more critical than others, you may need a weighted version.

Another limitation is that MSE is not scale-invariant. Comparing MSE across datasets with different units or scales is meaningless. To compare models on different scales, use normalized metrics like R² or normalized RMSE (NRMSE), which divides RMSE by the range or mean of the observed values.

Finally, MSE only measures the magnitude of errors, not the direction. A model that always predicts 0.5 too high and one that always predicts 0.5 too low will have the same MSE, even though the bias is different. For bias detection, look at the mean signed error separately.

Frequently Asked Questions

What is a good MSE value?

There is no universal threshold. A good MSE is one that is low relative to the variance of the data you are predicting. A common benchmark is to compare your MSE to the MSE of a naive model that always predicts the mean of the observed values. If your model’s MSE is much lower, it is adding value.

Can MSE be negative?

No. Since errors are squared, every term is non-negative, and the sum of non-negative numbers divided by n is non-negative. An MSE of 0 means perfect predictions, which is rare in real-world data.

Why is MSE used in machine learning instead of MAE?

MSE is differentiable everywhere, which makes it easier to optimize with gradient descent. The derivative of the squared error is linear, leading to simpler updates. MAE has a non-differentiable point at zero, which can complicate optimization. Additionally, MSE’s emphasis on large errors can be beneficial when large errors are especially undesirable.

What is the difference between MSE and variance?

Variance measures the spread of observed values around their own mean. MSE measures the spread of predictions around the observed values. If your model always predicts the mean of the observed data, then MSE equals the variance of the observed data. A good model should have MSE significantly lower than the variance.

Should I use MSE or RMSE for reporting?

Report both. MSE is useful for model comparison and optimization, but RMSE is easier to interpret because it is in the same units as the data. If your audience is non-technical, RMSE is usually more meaningful.

Can I use MSE for time series forecasting?

Yes, MSE is commonly used for time series forecasts. However, be aware that errors in time series are often autocorrelated, which can make standard MSE misleading. Consider using metrics that account for the temporal structure, such as mean absolute scaled error (MASE) or the Diebold-Mariano test.