Interact with the line and data points to see how MAE, MSE, RMSE, and $R^2$ quantify model performance in real-time.
In regression, our goal is to predict a continuous value, like a price or a temperature. But how do we know if our model's predictions are any good? Evaluation metrics are the tools we use to measure a model's performance and quantify its error. This lab visualizes four of the most common regression metrics, allowing you to see how they respond to changes in data and model fit in real-time.
In regression, our goal is to predict a continuous value, like a price or a temperature. But how do we know if our model's predictions are any good? Evaluation metrics are the tools we use to measure a model's performance and quantify its error. This lab visualizes four of the most common regression metrics, allowing you to see how they respond to changes in data and model fit in real-time.
Each metric tells a slightly different story about your model's errors. The interactive plot above shows the true data points (green dots), the model's prediction line (orange), and the errors, or residuals (dashed red lines), which are the distances between each true point and the line.
Definitions blur together until you put numbers through them. Here are five predicted and actual house prices, in thousands of pounds:
| House | Actual | Predicted | Error | Absolute error | Squared error |
|---|---|---|---|---|---|
| 1 | 200 | 190 | −10 | 10 | 100 |
| 2 | 250 | 265 | +15 | 15 | 225 |
| 3 | 180 | 175 | −5 | 5 | 25 |
| 4 | 300 | 290 | −10 | 10 | 100 |
| 5 | 400 | 340 | −60 | 60 | 3600 |
The gap between MAE 20 and RMSE 28.5 is the whole lesson. Four houses are predicted within £15k; one is out by £60k. Squaring turns that single house into 3600 of the 4050 total — 89% of the MSE comes from one row out of five. RMSE is loudly telling you there is a bad miss somewhere; MAE quietly averages it in.
So a rule you can use immediately: if RMSE is much larger than MAE, you have outliers. Go and look at them before you touch the model.
R² answers a different question from the others: not "how wrong am I?" but "how much better am I than the laziest possible model?"
That lazy model is predicting the mean of the target for every row. Compute its total squared error, compute your model's, and:
R² = 1 − (your squared error / the mean-predictor's squared error)
The trap is that R² never falls when you add a feature to a linear model, even a column of random numbers, because the extra freedom can only reduce training error. Adjusted R² corrects for this by penalising the number of predictors, and is the one to quote when comparing models with different numbers of features.
The other trap is comparing R² across datasets. An R² of 0.4 might be superb in a noisy domain like human behaviour and embarrassing in a controlled physical measurement. It is a comparison against the mean of this dataset, so it means nothing across two.
Each metric encodes an opinion about which errors matter.
| Metric | Units | Outliers | Best when |
|---|---|---|---|
| MAE | Same as target | Treated like any other error | Every pound of error costs the same |
| MSE | Squared | Dominates the score | You are optimising and want smooth gradients |
| RMSE | Same as target | Heavily weighted | Large misses are disproportionately expensive |
| MAPE | Percent | Explodes near zero | Relative error matters across different scales |
| R² | None | Follows MSE | Explaining to stakeholders how much you beat the average |
| Huber loss | Same as target | Damped past a threshold | You want RMSE's behaviour without outlier tyranny |
Two practical notes. MAPE is undefined when an actual value is zero and blows up when one is near zero — for demand forecasting where zeros are common, use MAE or a symmetric variant instead. And MSE is the loss most regressors minimise internally, so evaluating with MSE tells you how well the optimiser did its stated job, not necessarily how useful the model is.
A metric on its own is a number without a verdict. Three habits make it a decision.
Quote a baseline beside it. "RMSE 28.5" means nothing alone. "RMSE 28.5, against 61.0 for predicting the average and 34.2 for last year's model" is a result. Build the dumb baseline first, every time.
Say what the error means in the target's units. "Typically wrong by £20k on a £250k house" is a sentence a business owner can price. Percentages help here, which is one of the few genuine arguments for MAPE.
Plot the residuals. The single most informative thing you can do with a regression model costs two lines of code: plot predicted values against errors. A shapeless cloud around zero is healthy. A curve means the model is missing a non-linear relationship. A funnel widening to the right means the error grows with the size of the target, and predicting the logarithm often fixes it. A handful of points far from the rest are the outliers your RMSE has been complaining about.
from sklearn.metrics import mean_absolute_error, mean_squared_error, r2_score
import numpy as np
y_true = [200, 250, 180, 300, 400]
y_pred = [190, 265, 175, 290, 340]
mae = mean_absolute_error(y_true, y_pred) # 20.0
rmse = np.sqrt(mean_squared_error(y_true, y_pred)) # 28.46
r2 = r2_score(y_true, y_pred) # 0.87
baseline = np.full_like(y_true, np.mean(y_true), dtype=float)
print(mean_absolute_error(y_true, baseline)) # the number to beat
MAE, RMSE, R^2, MAPE and median absolute error on the same predictions -- then one outlier is introduced, and only some of them notice.
Use the controls and the interactive plot to build a strong intuition for these metrics.
Which metric should I optimise during training? Usually MSE or Huber, because they are smooth and differentiable. You can train on MSE and still report MAE — the training loss and the reporting metric do not have to match, and often should not.
My R² is negative on the test set. What happened? The model is doing worse than predicting the average. Common causes: severe overfitting, a distribution shift between train and test, or a preprocessing step fitted on the wrong data.
Is RMSE always bigger than MAE? Yes, or equal — they are only equal when every error has the same magnitude. The ratio between them is a quick outlier detector.
How do I compare models predicting different targets? Not with RMSE, which lives in the target's units. Use MAPE or R², or normalise RMSE by the target's mean or range.
Should I remove outliers to improve my metrics? Only if they are genuine errors — a price of £1 for a house, a sensor reading of 999. Removing real but inconvenient values makes your metric look better and your model worse in exactly the cases that matter.
Can I use accuracy for regression? Not directly, but "within £10k" style tolerance accuracy is a legitimate business metric and is often the one stakeholders actually care about. Report it alongside, not instead of, a proper error measure.
Say the answer out loud before you reveal it — recalling it is what makes it stick, and rereading it is not.
What does this module say about “Overview”?
In regression, our goal is to predict a continuous value, like a price or a temperature. But how do we know if our model's predictions are any good? Evaluation metrics are the tools we use to measure a model's performance and quantify its error. This lab visualizes four of the most common regression metrics, allowing you to see how they respond to changes in data and model fit in real-time.
What does this module say about “The Four Key Metrics”?
Each metric tells a slightly different story about your model's errors. The interactive plot above shows the true data points (green dots), the model's prediction line (orange), and the errors, or residuals (dashed red lines), which are the distances between each true point and the line.
What does this module say about “Mean Squared Error (MSE)”?
Definitions blur together until you put numbers through them. Here are five predicted and actual house prices, in thousands of pounds:
In regression, our goal is to predict a continuous value, like a price or a temperature. But how do we know if our model's predictions are any good? Evaluation metrics are the tools we use to measure a model's performance and quantify its error. This lab visualizes four of the most common regression metrics, allowing you to see how they respond to changes in data and model fit in real-time.