Intermediate: machine learning · Evaluating models · topic 30 of 62 · 30 min
Regression metrics: MAE, MSE, RMSE and R²
Explanation
Why several metrics?
A delivery-time model that is usually 2 minutes off but sometimes 40 minutes off is very different from one that is always 6 minutes off, yet both may have similar averages. Each regression metric looks at errors in a different way, and choosing one is a statement about which mistakes hurt your business most.
The four metrics
| Metric | Formula in words | Units | Best for |
|---|---|---|---|
| MAE (mean absolute error) | Average of |actual − predicted| | Same as the target (₹, minutes) | Easy to explain; treats every minute of error the same |
| MSE (mean squared error) | Average of (actual − predicted)² | Squared units (minutes²) | Training loss; punishes big errors strongly |
| RMSE (root mean squared error) | √MSE | Same as the target | Reporting when big misses are especially bad |
| R² (coefficient of determination) | 1 − SS_res ÷ SS_tot | No units; usually 0 to 1 | Comparing to the "always predict the mean" baseline |
actual = [30, 25, 40, 20]
pred = [28, 27, 30, 21]
errors = [a - p for a, p in zip(actual, pred)]
mae = sum(abs(e) for e in errors) / len(errors)
mse = sum(e * e for e in errors) / len(errors)
print(mae, mse, round(mse ** 0.5, 2))MAE versus RMSE
If RMSE is much bigger than MAE, a few large errors are present. Pick MAE when all errors cost roughly the same per unit (each minute late is equally annoying). Pick RMSE when big misses are disproportionately costly (being an hour late loses the customer). Report both when unsure.
R² explained
SS_tot is the total squared distance of the actual values from their mean: the error of the simplest baseline. SS_res is the squared error of your model. R² = 1 − SS_res ÷ SS_tot. An R² of 0.8 means the model removes 80% of the baseline's squared error. R² = 0 means no better than the mean, and R² can even be negative on test data if the model is worse than the mean.
Percentage errors
MAPE (mean absolute percentage error) averages |error| ÷ actual. Business teams like it ("we are 8% off on average"), but it breaks when actual values are zero or tiny, and it treats over- and under-prediction unequally. Use it with care, for example for sales of products that always sell some units.
Common mistakes
- Comparing RMSE across different targets or units. Fix: compare models on the same test set and target.
- Reporting R² alone. Fix: add MAE or RMSE in real units.
- Forgetting that MSE is in squared units, so "MSE = 25" means a typical error of about 5, not 25.
Need help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
Regression metrics: MAE, MSE, RMSE and R² · 1/6
Regression models are judged by how far predictions are from the real numbers.
Prefer a video by a teacher? Find free videos on “MAE MSE RMSE R squared regression metrics explained” on YouTube ↗
In real life: Crop yield forecasts for a district
An agriculture department forecasts wheat yield per hectare for each district before harvest, to plan procurement and storage. Officials want to know "how many quintals off are we, usually?", so the analysts report MAE in quintals per hectare. They also report RMSE, because a big miss in one large district can leave warehouses empty, and R² to show how much better the model is than using last year's average.
Practice (0/2 done)
Write mae(actual, predicted) and rmse(actual, predicted), each rounded to 4 decimal places.
Write r2(actual, predicted) = 1 − SS_res / SS_tot, where SS_res = Σ(actual − predicted)² and SS_tot = Σ(actual − mean(actual))². Round to 4 decimal places. If SS_tot is 0 (all actual values equal), return 0.0.
Quick quiz
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- Overfitting, underfitting and regularisationEvaluating models · same module
- Confusion matrix, accuracy, precision, recall and F1Evaluating models · same module
- Spread: range, variance and standard deviationStatistics made simple
- Choosing and explaining a modelk-NN, decision trees and ensembles
- k-nearest neighboursk-NN, decision trees and ensembles
- Logistic regression and classificationThe ML workflow, regression and classification
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
A delivery model has MAE = 4 minutes. What does that mean?
Answer: On average, predictions are 4 minutes away from the actual time
MAE is the average absolute error in the target's units.
RMSE is 15 minutes while MAE is 5 minutes. What does this suggest?
Answer: A few predictions have very large errors
Squaring makes rare big misses inflate RMSE.
On the test set, R² = −0.2. What does that mean?
Answer: The model is worse than always predicting the mean
Negative R² means SS_res is larger than the baseline's SS_tot.
Why is MAPE risky for daily sales of a product that sometimes sells 0 units?
Answer: Dividing by an actual value of 0 breaks it
Percentage error divides by the actual value, which cannot be 0.
A model trained on flats of 400–1,500 sq ft predicts a 9,000 sq ft villa. What is the risk?Related
Answer: Extrapolation: the line may not hold far outside the training range
Patterns learned in one range may not continue outside it.
What is a baseline model?Related
Answer: A deliberately simple prediction that sets the bar to beat
Baselines like "predict the mean" tell you whether a real model adds value.
Delivery times have a variance of 49 square minutes. What is the standard deviation?Related
Answer: 7 minutes
The SD is the square root of the variance: √49 = 7, back in minutes.
Two models score 0.861 and 0.864 AUC; the first is a readable logistic regression, the second a large ensemble. Explanations are legally required. Which is usually better to ship?Related
Answer: The logistic regression
A tiny gain rarely justifies losing explainability when it is required.
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- 2 more topics in “Evaluating models” before its exam: Overfitting, underfitting and regularisation, Cross-validation and tuning hyperparameters.
- Module 6 exam: Evaluating models · 12 questions · 25 min, without help. 6 topics of this module still to finish first.
- Then the next module, k-NN, decision trees and ensembles. 62 topics left in the course before the final exam.