Mean Squared Error

Mean squared error (MSE) is a metric used to evaluate regression models. The MSE of a model is the average squared difference between actual values and predicted values over all examples.

MSE = 1 m βˆ‘ i = 1 m ( y i βˆ’ y ^ i ) 2

where:

  • m is the number of examples
  • yi is the actual value of the label of the ith example
  • Ε·i is the predicted value of the label of the ith example

The lower the MSE, the better the model’s performance. The best possible MSE is 0.

Computing mean squared error in scikit-learn

import numpy as np
from sklearn.metrics import mean_squared_error

y_true = np.array([32, 38, 47, 58, 66, 73, 85, 91, 106, 116])
y_pred = np.array([32, 41, 50, 59, 68, 77, 86, 95, 104, 113])
mse = mean_squared_error(y_true, y_pred)

print(f"MSE: {mse:.2f}")
MSE: 6.90

This page references the following sources:

Here are all the notes in this garden, along with their links, visualized as a graph.