Statistics
Mean squared error
stats.mseAlso called mean squared error, mse, l2 loss, squared error
Average of the squared differences between observed and predicted values.
Notation
observed values
y ∈ ℝn
predicted values
ŷ ∈ ℝn
number of observations
Size, at least 1
Result: the mean squared error
scalar
Worked examples
Each result is solved exactly and confirmed by two independent computations.
Given
Result
≈ 1.66666666667
Given
Result
≈ 2.125
Given
Result
Common mistakes
Sums instead of averaging
The squared errors are summed, giving n times the mean.
Fix: Divide by n (reduction='mean').
Includes a factor of 1/2
The 1/2 used to simplify gradients is folded into the reported value.
Fix: Drop the 1/2 when the quantity is reported as the MSE.
Returns the root mean squared error
A square root is applied to the mean.
Fix: Remove the square root.
Source
Murphy 2022
Murphy, Kevin P. Probabilistic Machine Learning: An Introduction. MIT Press, 2022.