Mean Squared Error (MSE) in Machine Learning

CSPeach
2 min readJan 21, 2024

--

Mean Squared Error (MSE) is a common measure used to evaluate the performance of a regression model. It quantifies the difference between the observed actual outcomes and the predicted outcomes by the model.

Mean Squared Error Formula

where n is the number of data points, yi is the actual value for the i-th data point, and yi_hat is the predicted value for the i-th data point

Interpretation

  • MSE measures the average of the squares of the errors, for example, the average squared difference between the estimated values and the actual value.
  • A smaller MSE indicates a closer fit to the data, while a larger MSE indicates a poorer fit.
  • MSE gives more weight to larger differences due the squaring part of the formula. This means that models are heavily penalized for larger errors

Let’s look at an example where you want to predict the house price given a house size. Assume you have the house size input x in 1000 sqft :[1, 2, 3]. You have the actual data y in 1000s of dollars: [200, 300, 400], and the predicted data from the model y_hat : [210, 310, 380], to compute the MSE:

  1. Calculate the squared difference:
(200 - 210)^2 = 100
(300 - 310)^2 = 100
(400 - 380)^2 = 400

2. Sum the squared difference:

100 + 100 + 400 = 600

3. Divide by the number of data points (n=3):

MSE = 600/3 = 200

Therefore, the MSE for this model is 200.

To visualize the difference

Conclusion

Due to the squaring of each error, MSE is particularly sensitive to large errors. This can be both a strength and a weakness. It’s good for emphasizing significant errors, but it can also overemphasize outliers. Also, MSE is in the squared units of the output variable. It can sometimes be more difficult to interpret than other metrics, like Mean Absolute Error (MAE).

--

--