Data Science & ML
Basic

Mean Squared Error (MSE)

Average of squared differences between predicted and actual values.

Formula

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

Variables

y_iActual value
\hat{y}_iPredicted value
nNumber of samples

Example

For errors 2, -1, 3: MSE = (4+1+9)/3 = 4.67

How it works

Mean Squared Error measures how far a model’s predictions are from the true values by taking each error, squaring it, and then averaging those squared errors. Squaring makes all errors positive and gives extra weight to larger mistakes, so a few big misses count more than many small ones. It is widely used because it is smooth, easy to optimize, and directly penalizes large prediction errors.

When to use it

Use MSE when you want to evaluate or train a regression model and care more about large errors than small ones. It is common in forecasting, pricing, sensor prediction, and other problems where predicted numbers should be close to actual numeric targets.

Worked example, step by step

Actual values: 5, 7, 6 Predicted values: 4, 9, 5 Errors: 5-4 = 1, 7-9 = -2, 6-5 = 1 Squared errors: 1^2 = 1, (-2)^2 = 4, 1^2 = 1 Sum of squared errors: 1 + 4 + 1 = 6 Number of samples: 3 MSE = 6 / 3 = 2

Common mistakes to avoid

  • Forgetting to square the errors before averaging
  • Using absolute errors instead of squared errors
  • Mixing up actual values and predicted values in the subtraction

Did You Know?

MSE penalizes large errors heavily because the differences are squared.

Share this formula

Reviewed & maintained by the FormulaWon editorial teamLast reviewed September 2026