Coding Now – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 9667708830
Back to Machine Learning Notes
Topic #1715

Mean Absolute Error

Mean Absolute Error (MAE) averages the absolute value of every prediction error — treating every unit of error equally, regardless of size, unlike MSE's disproportionate penalty on large mistakes.

Formula

\[ MAE = \frac{1}{n}\sum_{i=1}^{n}|y_i-\hat{y}_i| \]

Worked Example

Same residuals as MSE's example: \([0.2, 0.6, -1.0, -0.6, 0.8]\).

\[ MAE = \frac{|0.2|+|0.6|+|{-1.0}|+|{-0.6}|+|0.8|}{5} = \frac{3.2}{5} = 0.64 \]
from sklearn.metrics import mean_absolute_error

y_true = [52, 58, 62, 68, 75]
y_pred = [51.8, 57.4, 63.0, 68.6, 74.2]

print(mean_absolute_error(y_true, y_pred))   # 0.64

MAE (0.64) directly answers "on average, how many marks off is a typical prediction?" — a more intuitive, directly interpretable number than MSE's squared-units 0.48.

MAE vs MSE — When Each Wins

MAEMSE
Outlier sensitivityLower — errors scale linearlyHigher — errors scale quadratically
UnitsSame as the target — directly interpretableSquared units — less intuitive
Differentiable at zero error?No — a sharp corner in the loss curveYes, smoothly
Best forData with outliers you don't want to dominate the scoreWhen large errors are genuinely much worse than small ones

A Concrete Illustration of the Difference

from sklearn.metrics import mean_absolute_error, mean_squared_error

y_true = [10, 20, 30, 40, 50]
y_pred_normal = [12, 18, 32, 38, 52]      # small, consistent errors
y_pred_outlier = [11, 19, 31, 39, 100]     # one huge error, rest are tiny

print("Normal errors  -- MAE:", mean_absolute_error(y_true, y_pred_normal),
      " MSE:", mean_squared_error(y_true, y_pred_normal))
print("Outlier errors -- MAE:", mean_absolute_error(y_true, y_pred_outlier),
      " MSE:", mean_squared_error(y_true, y_pred_outlier))
# MSE jumps dramatically for the outlier case; MAE rises much more modestly --
# MSE's squaring makes it far more sensitive to that single large miss

Practical Use Cases

  • Reporting model error to a non-technical audience — "on average, off by ₹0.64 lakh" is immediately understandable
  • Data with known, expected outliers you don't want to disproportionately dominate the evaluation

Common Mistakes

  • Using MAE as a training loss with gradient-based methods without accounting for its non-differentiability at zero error — some optimizers handle this fine, others need adjustment.
  • Assuming MAE and MSE will always rank two models the same way — a model with many small errors vs one with fewer but larger errors can rank differently under each metric.

Interview Relevance

Q: "You have a regression dataset with a few extreme, known-legitimate outliers. Would you report MAE or MSE as your primary metric?" MAE — its linear error scaling keeps the outliers from dominating the reported score, giving a more representative sense of the model's typical performance, whereas MSE's squaring would make the metric mostly reflect how the model handles those few extreme cases.

Practice Question

Given actual values \([100, 200, 300]\) and predictions \([110, 190, 305]\), compute MAE by hand and compare it to the MSE you computed in the MSE note's practice question.

Related ML Notes

Want to go beyond the notes?

Join CodingNow's Machine Learning course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →