Đại học Kinh tế Quốc dân – National Economics UniversityMICRO4ASIA
🏆 Arena
Sign inSign up
MICRO4ASIAThe six micro-credentials

Courses are delivered on the Limio learning platform. Limio

← Fundamental of Machine Learning

You are viewing a public preview

Sign in to save your progress, do assignments, join discussions and get feedback.

Sign in
Module 3: Model Evaluation and Optimization

3.4 Mean Absolute Error (MAE)

Print / Save as PDF

3.4 Mean Absolute Error (MAE)

After this unit you will be able to: compute and interpret Mean Absolute Error for a regression problem.

Key points

  • Regression predicts a continuous value (for example a house price), so the confusion matrix cannot be used; instead we measure the deviation between the true value and the predicted value.
  • MAE = (|error 1| + |error 2| + … ) / number of samples. For the three-house example: MAE = (|e₁| + |e₂| + |e₃|) / 3.
  • Taking the absolute value keeps positive and negative errors from cancelling each other out.
  • MAE has the same unit as the value being predicted (billion VND in the example), so it is easy to interpret: “on average the prediction is off by this much”.

Study notes

By the end of this lesson you can:

  • Explain why regression needs different metrics from classification
  • Compute Mean Absolute Error by hand for a few house-price predictions
  • Explain why the absolute value is needed
  • Interpret an MAE value in the units of the target (billion VND)
  • Compute MAE with scikit-learn

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.

From classification to regression metrics

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.

How MAE is computed

  1. For each prediction, compute the error: actual minus predicted (or the other way round, the sign does not matter later).
  2. Take the absolute value of each error, keeping only its size.
  3. Add up all the absolute errors.
  4. Divide by the number of predictions.

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.

Why the absolute value?

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.

Interpreting MAE

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.

Worked example

Three houses, prices in billion VND:

HouseActualPredictedError (actual - predicted)Absolute error
13.02.5+0.50.5
22.02.4-0.40.4
34.54.0+0.50.5

Step by step:

  1. Sum of absolute errors = 0.5 + 0.4 + 0.5 = 1.4.
  2. MAE = 1.4 / 3, about 0.467 billion VND.
  3. Without the absolute value, the errors would sum to 0.6 and suggest an average error of only 0.2, which understates the real error.
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.

Common mistakes

  • Dropping the absolute value. Positive and negative errors cancel and the model looks better than it is.
  • Using a confusion matrix for a regression model. Continuous predictions need error-based metrics such as MAE.
  • Comparing MAE values across different units. An MAE of 0.4 (billion) and 400 (million) are the same error.
  • Reporting MAE without its unit. "MAE = 0.47" means little until you add "billion VND".

Summary

  • Regression predicts continuous values, so we measure the distance between prediction and truth.
  • MAE = sum of absolute errors / number of predictions.
  • The absolute value stops positive and negative errors from cancelling.
  • MAE has the same unit as the target, so it reads as "the average error is this much".
  • In scikit-learn: mean_absolute_error(y_true, y_pred).

Flashcards · 3.4 Mean Absolute Error (MAE)

7 words
WordMeaningExample
  • Regression metric

    A measure of how far continuous predictions are from the true values.

    MAE, MSE, RMSE, R-squared.

  • Error (residual)

    The difference between the actual value and the predicted value for one sample.

    Actual 3.0, predicted 2.5 -> error 0.5.

  • Absolute error

    The size of an error with its sign removed.

    |-0.4| = 0.4

  • Mean Absolute Error (MAE)

    The average of the absolute errors across all predictions.

    (0.5 + 0.4 + 0.5) / 3 = 0.467

  • Error cancellation

    Positive and negative errors offsetting each other when summed without absolute values.

    +1 and -1 sum to 0.

  • Unit of MAE

    MAE uses the same unit as the target variable, which makes it easy to explain.

    MAE = 0.3 billion VND.

  • mean_absolute_error()

    scikit-learn function that computes MAE from true and predicted values.

    mean_absolute_error(y_true, y_pred)