Skip to main content
Crowdfunding
Python + AI for Geeks
Practice

Mean Absolute Error (MAE)

In the previous lesson, we discussed mean squared error, which calculates the average of the squares of the errors between predicted and actual values.

MSE is sensitive to large errors, making it potentially unsuitable for model evaluation when data contains outliers.

To address this issue, we use MAE (Mean Absolute Error).

MAE calculates the absolute differences between predicted and actual values and averages them.


How to Calculate Mean Absolute Error

MAE is calculated using the following formula:

MAE=1ni=1nyiy^i\text{MAE} = \frac{1}{n} \sum_{i=1}^{n} |y_i - \hat{y}_i|

Where each term represents:

  • nn : Number of data samples

  • yiy_i : Actual value (ground truth)

  • y^i\hat{y}_i : Predicted value by the model

MAE takes the absolute difference between predicted and actual values for each sample and computes the average for all samples.

MAE Example
Actual values: [10, 20, 30]
Predicted values: [15, 25, 35]

MAE = (|10-15| + |20-25| + |30-35|) / 3
= (5 + 5 + 5) / 3
= 15 / 3
= 5

How Should We Interpret MAE?

MAE indicates how much the model's predictions deviate from actual values on average.

A smaller MAE means predictions are closer to actual values and the model's performance is better.

Unlike MSE, MAE does not square errors, making it less sensitive to outliers.

Thus, it serves as a stable evaluation metric for data with many outliers.


What Are the Limitations of MAE?

1. Non-differentiable Points Exist

The absolute value operation in MAE creates points where differentiation is not possible, complicating use with optimization algorithms like Gradient Descent.
To overcome this, some models replace MAE with Huber Loss.

2. Does Not Account for Error Direction

MAE only measures the magnitude of errors, ignoring whether predictions are higher or lower than actual values.
Therefore, when analyzing model bias, MAE should be used alongside metrics like MSE or others.


MAE allows for more intuitive interpretation and is less sensitive to outliers, making it a useful evaluation metric for various regression problems.

In the next lesson, we will explore another frequently used metric for evaluating regression models: the R² Coefficient of Determination.

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.