Mean Squared Error (MSE) is the standard regression evaluation metric — the average of every prediction's squared error, penalizing large mistakes disproportionately more than small ones.
Formula
Worked Example — Reusing the Linear Regression Model
From the Simple Linear Regression worked example: actual marks \(y=[52,58,62,68,75]\), predictions \(\hat{y}=[51.8,57.4,63.0,68.6,74.2]\), residuals \([0.2,0.6,-1.0,-0.6,0.8]\).
from sklearn.metrics import mean_squared_error
y_true = [52, 58, 62, 68, 75]
y_pred = [51.8, 57.4, 63.0, 68.6, 74.2]
print(mean_squared_error(y_true, y_pred)) # 0.48
Why Squaring Matters — And Its Real Cost
Squaring makes MSE differentiable everywhere (essential for gradient-based training, as covered in Cost Function) and heavily penalizes large errors: an error of 10 contributes 100, while an error of 2 contributes only 4. This is a double-edged property — it's exactly what you want if large errors are disproportionately bad in your business context, but it also means MSE is highly sensitive to a single outlier prediction.
The Units Problem
MSE is expressed in squared units of the target — "0.48 marks²" has no intuitive meaning. This is exactly why RMSE (its square root) is usually reported instead, when human-interpretable units matter.
Practical Use Cases
- The default training loss for linear regression and most regression neural networks
- Evaluation when large errors are genuinely much worse than small ones (e.g. inventory forecasting, where a huge miss causes real supply chain problems)
Common Mistakes
- Comparing MSE across datasets with different target scales — an MSE of 100 could be excellent for a target ranging in the millions, or terrible for one ranging 0-10.
- Using MSE as the primary reported metric to a non-technical audience — its squared units are unintuitive; RMSE communicates the same information more clearly.
Interview Relevance
Q: "Why might MSE be a poor metric if your data has a few extreme outliers?" Because squaring amplifies large errors disproportionately — a handful of outlier predictions can dominate the entire MSE score, making the metric mostly reflect how badly the model handles those few outliers rather than its typical, everyday performance; MAE is more robust to this.
Practice Question
Given actual values \([100, 200, 300]\) and predictions \([110, 190, 305]\), compute MSE by hand.