Mean Squared Error (MSE)

Description

In order to measure the average squared differences between some predicted and actual values, the MSE can be used. By squaring the errors before averaging them, larger errors will be penalized. The MSE is defined as follows:

\[\text{MSE} = \frac{1}{n} \sum_{i=1}^{n} (y_i - \hat{y}_i)^2 ,\]

where:

  • ( n ) is the number of observations.

  • ( y_i ) is the actual value.

  • ( hat{y}_i ) is the predicted value.

Tools and Libraries

Python

To measure the MSE between the actual values and predicted values, the following example can be used.

Install scikit-learn via this command:

pip install -U scikit-learn
from sklearn.metrics import mean_squared_error

y_true = [5, 0.2, 8, -0.3]
y_pred = [6, 0.0, 7, 0.0]

MSE = mean_squared_error(y_true, y_pred)

print(f"The MSE is: {MSE}")

MATLAB

C++

Literature