Smart Systems for Home

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

Mean Square Error: Definition & Formula

· 6 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. Other Error Metrics
  7. When to Use MSE
  8. Limitations of MSE
  9. Frequently Asked Questions

The mean square 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, root mean square error (RMSE), and mean absolute error (MAE). This gives you a single number that tells you how far off your predictions are, on average, with extra weight on large errors.

in obs | Observed values (comma-separated) | - | 3, 5, 2.5, 7, 4 | 0 | 100000
in pred | Predicted values (comma-separated) | - | 2.8, 5.1, 2.2, 6.9, 4.3 | 0 | 100000
out mse | Mean Square Error | - | mean((obs - pred)^2) | 4
out rmse | Root Mean Square Error | - | sqrt(mean((obs - pred)^2)) | 4
out mae | Mean Absolute Error | - | mean(abs(obs - pred)) | 4

Formula

MSE is defined as:

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

Where:

  • n = number of observations
  • yᵢ = actual (observed) value for the i-th observation
  • ŷᵢ = predicted value for the i-th observation

The sum of squared differences is divided by n to get the average. The squaring ensures that positive and negative errors do not cancel out, and it penalizes larger errors more heavily than smaller ones.

Worked Example

Using the default values from the calculator: observed = [3, 5, 2.5, 7, 4], predicted = [2.8, 5.1, 2.2, 6.9, 4.3].

  1. Compute differences (yᵢ - ŷᵢ): 0.2, -0.1, 0.3, 0.1, -0.3
  2. Square each difference: 0.04, 0.01, 0.09, 0.01, 0.09
  3. Sum the squares: 0.04 + 0.01 + 0.09 + 0.01 + 0.09 = 0.24
  4. Divide by n = 5: 0.24 / 5 = 0.048

The MSE is 0.048. The RMSE is sqrt(0.048) ≈ 0.2191. The MAE is (0.2 + 0.1 + 0.3 + 0.1 + 0.3)/5 = 0.2.

Why Square the Errors?

Squaring the errors serves two purposes. First, it makes all errors positive, so they don't cancel each other out. Second, it gives disproportionate weight to large errors. For example, an error of 2 contributes 4 to the MSE, while an error of 1 contributes 1. This means that a model with many small errors might have a lower MSE than one with a few large errors, which is often desirable if large errors are especially costly (e.g., in financial forecasting or safety-critical systems).

However, this sensitivity to outliers can be a drawback. If your data contains extreme values that aren't meaningful, MSE can be inflated. In such cases, you might prefer the mean absolute error (MAE), which treats all errors equally, or a robust metric like median absolute deviation.

How to Interpret MSE

MSE is in squared units of the variable you're predicting. For example, if you're predicting house prices in dollars, MSE is in dollars squared. This makes it hard to interpret intuitively. That's why the root mean square error (RMSE) is often reported: it's in the same units as the original data. An RMSE of 0.22 means your predictions are, on average, about 0.22 units away from the actual values (after accounting for the squaring).

There is no universal "good" MSE value—it depends entirely on the scale of your data. An MSE of 100 might be excellent if your values are in the thousands, but terrible if they are in the tens. Always compare MSE against a baseline model (like predicting the mean) or against other models on the same dataset.

Common Mistakes and Pitfalls

  • Mixing up units: If you enter some values in feet and others in meters, your MSE will be meaningless. Always use consistent units.
  • Using MSE when you care about relative error: MSE is absolute. If you're predicting values that range from 1 to 1000, a small error on a large value dominates. Consider using mean absolute percentage error (MAPE) or relative RMSE.
  • Confusing MSE with variance: Variance measures the spread of a single variable around its own mean. MSE measures the spread of predictions around actual values. They are the same only if your predictions are the mean of the data.
  • Ignoring the sample vs. population distinction: If you're estimating model error on a sample, some texts use n-1 in the denominator (like sample variance). In practice, for prediction error, n is standard.

MSE vs. Other Error Metrics

MSE is one of several metrics used to evaluate prediction accuracy. Here's how it compares:

  • MAE (Mean Absolute Error): Average absolute difference. Less sensitive to outliers. Easier to interpret.
  • RMSE (Root Mean Square Error): Square root of MSE. Same units as the data. Still penalizes large errors more.
  • MAPE (Mean Absolute Percentage Error): Expresses error as a percentage. Useful for comparing across different scales, but undefined when actual values are zero.
  • R-squared (Coefficient of Determination): Not an error metric per se, but indicates the proportion of variance explained by the model. R² = 1 - (SSE/SST), where SSE is sum of squared errors and SST is total sum of squares.

In practice, many data scientists report both RMSE and MAE. If RMSE is much larger than MAE, it suggests that a few predictions have very large errors, which might warrant investigation.

When to Use MSE

MSE is the default loss function for many regression problems, especially in machine learning. It's used in:

  • Linear regression (ordinary least squares minimizes MSE)
  • Neural network training (mean squared error loss)
  • Model evaluation in forecasting (stock prices, weather, demand)
  • Signal processing and image compression (peak signal-to-noise ratio is based on MSE)

However, if your data has heavy-tailed outliers, or if you need a more interpretable metric, consider alternatives. Also, MSE assumes that the cost of an error is proportional to the square of its magnitude. If that's not true for your application, another metric might align better with your goals.

Limitations of MSE

MSE has known limitations:

  • Scale-dependent: You can't compare MSE across datasets with different units or scales.
  • Sensitive to outliers: A single extreme value can dominate the MSE.
  • Not interpretable in original units: Squared units are awkward.
  • Assumes symmetric loss: Over-predicting and under-predicting by the same amount are treated equally. In some contexts (e.g., inventory), over-predicting might be cheaper than under-predicting.

For these reasons, always consider the context and possibly report multiple metrics.

Frequently Asked Questions

What is a good MSE value?

There's no absolute threshold. A good MSE is one that is low relative to the variance of the actual data. A common benchmark is to compare your model's MSE to the MSE of a naive model that always predicts the mean. If your model's MSE is significantly lower, it's doing well.

Can MSE be negative?

No. Since errors are squared, every term is non-negative, so the sum and the average are always non-negative. A negative MSE would indicate a calculation error.

What is the difference between MSE and RMSE?

RMSE is the square root of MSE. The key difference is that RMSE is in the same units as the original data, making it easier to interpret. RMSE also has the same property of penalizing large errors more, but its value is more intuitive.

How do I compute MSE in Excel?

You can use the formula =SUMSQ(obs_range - pred_range)/COUNT(obs_range) entered as an array formula (Ctrl+Shift+Enter in older Excel). Or use =AVERAGE((obs_range - pred_range)^2) as an array formula. Alternatively, you can compute the differences in a helper column, square them, and average.

Is MSE the same as variance?

No. Variance measures the spread of a single variable around its own mean. MSE measures the average squared difference between predictions and actual values. They coincide only if your predictions are exactly the mean of the actual values for every observation.

Why do we square errors instead of taking absolute values?

Squaring gives more weight to large errors, which is often desirable because large errors are disproportionately costly in many applications. It also makes the function differentiable everywhere, which is convenient for optimization algorithms like gradient descent. However, this also makes MSE sensitive to outliers.