Stop 07 · Supervised Learning: RegressionTopics · 7/8

Regression Metrics (MAE, RMSE, R²)

Part of the Machine Learning Roadmap

In short

When you predict a number like a flat's price, 'right or wrong' doesn't work. You need to know how far off you are, and these three metrics tell you in different ways.

MAE is the average size of errors in the target's units, RMSE punishes big errors more, and R² shows how much of the variation the model explains compared with predicting the mean. Choose the metric that matches what mistakes cost.

The mascot holds a watermelon next to a brass balance scale on a small wooden table.

Think of it like this

Guessing weights at the village fair

At the fair you guess each watermelon's weight before it goes on the scale. MAE is your average miss in kilos. RMSE punishes one wild miss much more than many small ones. R² asks how much better you did than someone who just guessed the average weight every time.

Watch it happen

Errors on five flat prices (in lakh)

2
0
-1
1
3
2
-2
3
-10
4

1/5Each cell is predicted minus actual price for one flat. Four small misses and one big one.

The big ideas

What you need to know

MAE is easy to explain

'On average we're off by 3.6 lakh.' Same units as the target, and outliers don't dominate it.

RMSE hates big misses

Squaring makes large errors count heavily. Use it when one huge miss is much worse than several small ones.

R² is relative

1 is perfect, 0 is no better than predicting the mean, and it can go negative for a bad model.

Report more than one

MAE plus RMSE tells you both the typical error and whether a few big misses are hiding in there.

See it in code

Walk through the code

python
1import numpy as np2from sklearn.metrics import mean_absolute_error, mean_squared_error, r2_score3 4actual    = np.array([50, 62, 45, 70, 90])    # flat prices in lakh5predicted = np.array([52, 61, 48, 68, 80])6 7mae  = mean_absolute_error(actual, predicted)8rmse = np.sqrt(mean_squared_error(actual, predicted))9r2   = r2_score(actual, predicted)10print(f"MAE {mae:.1f}  RMSE {rmse:.2f}  R2 {r2:.2f}")

1/4Real prices and model guesses. The last flat is off by 10 lakh.

Same five flats as the scene. It prints MAE 3.6, RMSE 4.86 and R2 0.91.

Save yourself the pain

Common mistakes

Oops

Saying 'R² is 0.9, so predictions are 90% accurate'.

Do this instead

R² is explained variance, not accuracy. Quote MAE or RMSE when people ask how far off you are.

Oops

Comparing RMSE across datasets with different units or scales.

Do this instead

Compare errors only on the same target. For cross-dataset comparisons, use a relative measure and explain it.

Your mission

Watch an outlier move the metrics

~15 min

Quick check

Two models have the same MAE, but model B has a much higher RMSE. What does that tell you?

Go deeper

  1. 1Compute MAE, RMSE and R² for your house price model with sklearn.metrics.
  2. 2Explain your MAE in rupees to a non-technical friend.
  3. 3Add one huge error to the predictions and see how much RMSE jumps compared with MAE.

Also part of these roadmaps

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge