You are viewing a public preview
Sign in to save your progress, do assignments, join discussions and get feedback.
After this unit you will be able to: compute and interpret Mean Absolute Error for a regression problem.
By the end of this lesson you can:
Key idea: MAE is the average size of the prediction errors, ignoring their sign; it is in the same unit as the target, so "MAE = 0.3 billion VND" simply means predictions are off by about 0.3 billion on average.
So far we evaluated classifiers, where a prediction is either right or wrong. A regression problem predicts continuous numbers, such as house prices, so a prediction is rarely exactly right. A confusion matrix no longer makes sense; instead we measure how far each prediction is from the true value.
The lecture's figure shows three houses on the horizontal axis and price on the vertical axis. For each house there is an actual value and a predicted value. The formula on the slide is:
MAE = (|e1| + |e2| + |e3|) / 3
where each e is the difference between the actual and the predicted price.
Example from the lecture: a house actually costs 3 billion VND and the model predicts 2.5 billion. The absolute error for that house is 0.5 billion VND. Repeat for every house, sum and divide.
Without it, positive and negative errors would cancel each other. If the model overestimates one house by 1 billion and underestimates another by 1 billion, the plain errors sum to 0, as if the model were perfect. The absolute value turns both into 1, so the average reflects how wrong the model really is.
The great strength of MAE is that it is easy to interpret. It is expressed in exactly the same unit as the target. If the MAE is 0.3 billion VND, the model's price predictions are off by about 0.3 billion VND on average, in either direction.
This makes it easy to explain to non-technical stakeholders: "on average, our estimates are 300 million VND away from the real price".
Because MAE uses the target's unit, it changes with the unit. Converting prices from billion VND to million VND multiplies every error, and therefore the MAE, by 1,000.
Three houses, prices in billion VND:
| House | Actual | Predicted | Error (actual - predicted) | Absolute error |
|---|---|---|---|---|
| 1 | 3.0 | 2.5 | +0.5 | 0.5 |
| 2 | 2.0 | 2.4 | -0.4 | 0.4 |
| 3 | 4.5 | 4.0 | +0.5 | 0.5 |
Step by step:
import numpy as np
from sklearn.metrics import mean_absolute_error
actual = np.array([3.0, 2.0, 4.5])
predicted = np.array([2.5, 2.4, 4.0])
print(round(np.mean(np.abs(actual - predicted)), 3))
print(round(mean_absolute_error(actual, predicted), 3))
print(round(mean_absolute_error(actual * 1000, predicted * 1000), 1))
Expected output:
0.467
0.467
466.7
The last line shows the same predictions measured in million VND: the MAE becomes about 466.7 million VND, the same error expressed in a different unit.
mean_absolute_error(y_true, y_pred).Flashcards · 3.4 Mean Absolute Error (MAE)
7 wordsA measure of how far continuous predictions are from the true values.
The difference between the actual value and the predicted value for one sample.
The size of an error with its sign removed.
The average of the absolute errors across all predictions.
Positive and negative errors offsetting each other when summed without absolute values.
MAE uses the same unit as the target variable, which makes it easy to explain.
scikit-learn function that computes MAE from true and predicted values.