📘 Blog: Understanding Mean Absolute Error (MAE)

🔹 Question Recap

from sklearn.metrics import mean_absolute_error  

y_true = [2, 0, 3, 5]  
y_pred = [2.5, 0.0, 2, 8]  

mean_absolute_error(y_true, y_pred)

Options:

  • 1.25

  • 2.56

  • 4.25

  • ✅ 1.12

  • Error


✅ Step 1: What is MAE?

Mean Absolute Error (MAE) is a regression evaluation metric.

Formula:

MAE=1ni=1nytrue(i)ypred(i)MAE = \frac{1}{n} \sum_{i=1}^{n} |y_{true}^{(i)} - y_{pred}^{(i)}|
  • It calculates the absolute difference between actual and predicted values.

  • Then takes the average of these differences.

  • Smaller MAE → better performance.


✅ Step 2: Apply Formula

| Index | y_true | y_pred | Error = |y_true - y_pred| |
|-------|--------|--------|---------------------------------|
| 0 | 2 | 2.5 | 0.5 |
| 1 | 0 | 0.0 | 0.0 |
| 2 | 3 | 2 | 1.0 |
| 3 | 5 | 8 | 3.0 |

Now sum errors:

0.5+0.0+1.0+3.0=4.50.5 + 0.0 + 1.0 + 3.0 = 4.5

Divide by total samples (4):

MAE=4.54=1.125MAE = \frac{4.5}{4} = 1.125

Answer = 1.12 (approx)


✅ Step 3: Why Absolute Error?

  • If we used raw differences, positives and negatives would cancel out.

  • Example: if one prediction is too high by +5 and another too low by -5, average error would look zero, which is misleading.

  • Absolute ensures every error counts positively.


✅ Step 4: What Students Should Also Know

  1. Other Error Metrics (MCQ variations often test these):

    • MSE (Mean Squared Error):
      Squares errors → penalizes larger mistakes more.

    • RMSE (Root Mean Squared Error):
      Same as MSE but square root → interpretable in original scale.

    • R² (Coefficient of Determination):
      Measures goodness of fit (closer to 1 is better).

  2. When to Use MAE vs MSE:

    • MAE: Good when you want robustness to outliers.

    • MSE / RMSE: Good when large errors are very costly (e.g., predicting house prices).

  3. Scaling & Interpretation:

    • MAE is in same units as target variable → intuitive for real-world problems.

    • Example: If predicting delivery times in minutes, MAE = 3 means model is off by 3 minutes on average.

  4. Better Way to Teach Students:


✅ General Tip for Similar Questions

Whenever you see:

from sklearn.metrics import ...

👉 Immediately think:

  • Which metric is used? (MAE, MSE, RMSE, Accuracy, Precision, Recall, F1).

  • Formula for that metric.

  • Apply step-by-step manually before trusting options.


🎯 Key Takeaway


👉 Now, would you like me to prepare the next blog on MSE (Mean Squared Error) with a similar MCQ example, so your students can compare MAE vs MSE directly?

Comments

Popular posts from this blog

Understanding Data Leakage in Machine Learning: Causes, Examples, and Prevention

🌳 Understanding Maximum Leaf Nodes in Decision Trees (Scikit-Learn)

Linear Regression with and without Intercept: Explained Simply