Posts Mean Squared Error (MSE) - Evaluation Metrics
Post
Cancel

Mean Squared Error (MSE) - Evaluation Metrics

Brief

Mean squared error is one of the popular evaluation metrics used in measuring the accuracy of a model. It calculates the sum of squared differences and divides them by the number of records, squaring the number will remove the negative sign. Let’s see the formula and understand it.

Formula

\begin{equation} \mathrm{MSE}= \frac{1}{\mathrm{n}} \sum_{\mathrm{i}=1}^{\mathrm{n}} \left( \mathrm{y}_{\mathrm{i}}-\mathrm{\hat y} _ {\mathrm{i}}\right)^{2} \end{equation}

Explanation

Here, \( \sum \) = symbol for doing addition of values,
n = number of records,
i = record index starting from 1 (first record),
y = actual record from our testing data,
\( \mathrm{\hat y} \) = predicted value of y record from a model,

So, this formula will calculate the sum of squared differences between the actual value y and predicted value \( \mathrm{\hat y} \) (yhat) for all records and divide them by n the number of records. Remember that it is doing a square of differences between two values to remove negative sign unlike Mean Absolute Error (MAE).

Example

Let’s look at one example for better understanding:

Actual ValuePredicted ValueDifference
10.312.5-2.2
25.722.13.6
15.811.24.6

if we calculate the summation of squared differences, it would be like: \( (-2.2)^2+(3.6)^2+(4.6)^2\)
\( = 4.84 + 12.96 + 21.16 = 38.96\)
38.96 is our sum of differences. Now, we will divide 38.96 by 3 which is the number of records in this case:

\( 38.96 / 3 = 12.99\)

12.99 is our MSE (Mean Squared Error).
That’s it! You are done with the MSE (Mean Squared Error).

This post is licensed under CC BY 4.0 by the author.