Formula Bro

Math and physics formulas, explained like you are new.


Mean Squared Error (MSE)

In one sentence: Mean squared error measures how wrong a model’s guesses are by squaring each miss, so big misses count much more, and then averaging them.

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

Read it out loud: “M S E equals one over n, times the sum, for i from 1 to n, of the true value y i minus the predicted value y hat i, all squared.”

What each symbol means

SymbolMeaning

MSE\mathrm{MSE}

The mean squared error: one number that sums up how wrong the predictions are. It is in squared units, so if the values are in meters, the MSE is in square meters.

nn

How many predictions you are scoring.

ii

The position of one prediction in the list, counting from 1 up to nn.

∑i=1n\sum_{i=1}^{n}

“Add up for every ii from 1 to nn”: go through all the predictions and total the results.

yiy_i

The true value for case ii, the answer you know is correct.

ŷi\hat{y}_i

The predicted value for case ii, the model’s guess. The hat over the yy is the usual sign for a prediction.

What the formula is doing

A model makes a guess for each case, and for each case you know the true answer. The error for one case is the gap between them: true value minus prediction. The gap can be positive or negative, depending on which way the miss went.

Squaring each gap fixes two problems. It makes every error positive, so a miss of −2-2 and a miss of +2+2 do not cancel out. It also makes big misses count far more: a gap of 4 adds 16 to the total, while a gap of 2 adds only 4.

Next, the formula adds up all the squared gaps and divides by nn, the number of cases. Dividing turns the total into an average, so the score does not grow merely because you tested more cases.

A smaller MSE means the predictions sit closer to the truth. An MSE of 0 means every prediction was exactly right. Because of the squaring, the result is in squared units and is harder to read than the original values. The square root of the MSE, called RMSE, brings it back to the original units.

An everyday picture

Think of a darts coach scoring practice throws. Each throw’s distance from the bullseye is recorded, and a throw that lands far off costs much more than one that lands close. The coach averages those penalties across all the throws, so one wild throw shows up clearly in the score even when the rest are good.

Worked example: Three temperature predictions

A model predicts the temperature in three cities, in degrees Celsius. The true temperatures are y=(3,5,2)y = (3, 5, 2) and the predictions are ŷ=(2,6,4)\hat{y} = (2, 6, 4).

  1. Find each gap: 3−2=13 - 2 = 1, 5−6=−15 - 6 = -1 and 2−4=−22 - 4 = -2.
  2. Square each gap: 12=11^2 = 1, (−1)2=1(-1)^2 = 1 and (−2)2=4(-2)^2 = 4.
  3. Add the squares: 1+1+4=61 + 1 + 4 = 6.
  4. Divide by the number of predictions, n=3n = 3: MSE=63=2.0\mathrm{MSE} = \frac{6}{3} = 2.0.

Answer: The MSE is 2.0 square degrees Celsius. The biggest miss, the −2-2 for the third city, contributed 4 of the 6 squared points, so it dominates the score. A perfect model would score 0.

The numbers in this example are recomputed by script every time the site is built.

Common mistakes

Where you will meet it

Questions people ask

Why square the errors instead of taking absolute values?

Squaring gives a smooth curve with no sharp corner at zero, which makes it easier for gradient descent to follow. Squaring also punishes large misses more heavily. Some problems want that, and some do not.

What is the difference between MSE and RMSE?

RMSE is the square root of MSE. It comes back to the same units as the original values, so it is easier to read.

Is a small MSE always good?

Not always. A small MSE on the data used for training can hide a model that fails on new data. Check the score on data the model has not seen.

Can MSE be used for yes-or-no answers?

It can, but it is usually a poor choice. For classes, cross-entropy loss is the usual choice, because it punishes confident wrong answers much harder.

Sources

  1. Mean squared error, Wikipedia
  2. Loss function, Wikipedia

| All AI & ML formulas |

Published 2026-10-22. Plain-text copy for AI agents and readers: ai-ml/mean-squared-error.md.