Mean Squared Error

Mean squared error, or MSE, is a common regression loss.

For each example:

squared_error = (prediction - target)^2

For a batch:

MSE = average squared error
errorsquared error1^22^2
Squaring makes larger errors count more than smaller errors.

Squaring does two things:

  • it removes the sign;
  • it makes larger errors count more.

Small batch

Suppose predictions and targets are:

predictions = [3, 5]
targets     = [1, 6]

Errors:

[3 - 1, 5 - 6] = [2, -1]

Squared errors:

[4, 1]

Mean squared error:

(4 + 1) / 2 = 2.5
Exercise: One squared error

A prediction is 7, and the target is 4. What is the squared error?

Compute it first, then check your number.

HintError first

Compute the signed error, then square it.

SolutionWork it out

The error is 7 - 4 = 3. The squared error is 3^2 = 9.

Exercise: Mean squared error

Squared errors are [1, 9, 2]. What is their mean?

Compute it first, then check your number.

HintAverage them

Add the three values and divide by 3.

SolutionWork it out

(1 + 9 + 2) / 3 = 12 / 3 = 4.