Regression Metrics: MAE, MSE, RMSE & R²
Accuracy is for categories — to grade a number-predicting model you measure how far off it is.
What you will learn
- Compute MAE, MSE and RMSE for a regression model
- Interpret R² as “how much variation is explained”
- Pick the right metric for the job
You cannot use accuracy on numbers
Accuracy asks “was the prediction exactly right?” — fine for categories, useless for numbers. A house price prediction of 49.8 lakh when the truth is 50 is not “wrong”, it is very close. Regression metrics measure how close, by looking at the size of the errors.
The error for one row is simply prediction − truth. The metrics below are different ways to summarise all those errors into one number.
The three error metrics
- MAE — Mean Absolute Error: the average size of the errors, ignoring sign. Easy to read: “on average we are off by this much.”
- MSE — Mean Squared Error: square each error first, then average. Squaring punishes big misses much harder than small ones.
- RMSE — Root Mean Squared Error: the square root of MSE. This brings the number back into the original units (e.g. lakh), so it is easy to interpret while still punishing big errors.
A fully worked example
A model predicts three house prices (in lakh). Let us compute all three metrics by hand so the formulas feel concrete.
| True price | Predicted | Error | Absolute error | Squared error |
|---|---|---|---|---|
| 50 | 48 | −2 | 2 | 4 |
| 60 | 63 | +3 | 3 | 9 |
| 70 | 69 | −1 | 1 | 1 |
- MAE = (2 + 3 + 1) ÷ 3 = 6 ÷ 3 = 2.0 lakh — typical miss is about 2 lakh.
- MSE = (4 + 9 + 1) ÷ 3 = 14 ÷ 3 ≈ 4.67 — in “lakh squared”, hard to picture.
- RMSE = √4.67 ≈ 2.16 lakh — back in lakh, slightly above MAE because the 3-lakh miss was squared.
Now the same numbers with scikit-learn, which has ready-made functions:
from sklearn.metrics import mean_absolute_error, mean_squared_error, r2_score
y_true = [50, 60, 70]
y_pred = [48, 63, 69]
mae = mean_absolute_error(y_true, y_pred)
mse = mean_squared_error(y_true, y_pred)
rmse = mse ** 0.5
r2 = r2_score(y_true, y_pred)
print('MAE: ', round(mae, 2))
print('MSE: ', round(mse, 2))
print('RMSE:', round(rmse, 2))
print('R2: ', round(r2, 3))Note: Output: MAE: 2.0 MSE: 4.67 RMSE: 2.16 R2: 0.965 MAE, MSE and RMSE match our hand calculation exactly. The R² of 0.965 says the model explains about 96.5% of the variation in prices — read on for what that means.
R²: how much variation is explained
R² (R-squared) answers a different question: of all the up-and-down variation in the real values, how much does the model explain? It runs from 1.0 (perfect — explains everything) down through 0 (no better than just guessing the average every time) and can even go negative (worse than guessing the average).
Unlike MAE/RMSE, R² has no units, so you can compare it across totally different problems. An R² of 0.965 is excellent; an R² near 0 means your features are not helping.
| Metric | Units | Good value | Best for |
|---|---|---|---|
| MAE | Same as target | Lower | A plain “average miss” everyone understands |
| RMSE | Same as target | Lower | When big errors should be punished more |
| R² | None (0 to 1) | Closer to 1 | Comparing across different datasets |
Watch out: Because MSE and RMSE square the errors, a single huge mistake (an outlier) can blow them up. If your data has wild outliers, MAE gives a steadier picture of typical performance.
Tip: A great habit: report RMSE (in real units, so a person understands the typical error) and R² (unitless, so you can compare models and datasets) together. They tell two halves of the story.
Q. A regression model has R² = 0.0. What does that mean?
✍️ Practice
- Change one prediction to be wildly off (e.g. 90 instead of 69) and watch RMSE jump far more than MAE.
- Explain in one sentence why accuracy cannot be used to grade a house-price model.
🏠 Homework
- Invent five true/predicted number pairs and compute MAE and RMSE by hand, then check them with scikit-learn.