Home / Machine Learning

Evaluation Metrics for Regression

By Updated

Interact with the line and data points to see how MAE, MSE, RMSE, and $R^2$ quantify model performance in real-time.

Overview

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.

2.5
30
Interactive Plot
Regression Line
$y_{pred} =$ 1.20$x$ + 2.00

Mean Absolute Error

MAE
0.000
Average of absolute differences. Treats all errors equally.

Mean Squared Error

MSE
0.000
Average of squared differences. Heavily punishes large errors (outliers).

Root Mean Sq. Error

RMSE
0.000
Square root of MSE. Returns error metric to original units.

R-Squared Score

$R^2$ (Coeff. of Det.)
0.000
Proportion of variance explained by the model. 1.0 is perfect, <0 is worse than mean.

Understanding Regression Metrics

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.

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.

1. Mean Absolute Error (MAE)

What it is: The average of the absolute differences between the true values and the predicted values.
Formula: $ \frac{1}{n} \sum_{i=1}^{n} |y_i - \hat{y}_i| $
Interpretation: It tells you, on average, how far off your predictions are. It's easy to understand because it's in the same units as the target variable. It treats all errors equally, big or small.

2. Mean Squared Error (MSE)

What it is: The average of the squared differences between the true and predicted values.
Formula: $ \frac{1}{n} \sum_{i=1}^{n} (y_i - \hat{y}_i)^2 $
Interpretation: By squaring the errors, MSE penalizes larger errors much more heavily than smaller ones. This makes it sensitive to outliers. Its units are squared, which can make it hard to interpret directly.

3. Root Mean Squared Error (RMSE)

What it is: The square root of the MSE.
Formula: $ \sqrt{\frac{1}{n} \sum_{i=1}^{n} (y_i - \hat{y}_i)^2} $
Interpretation: RMSE is the most popular metric. Like MSE, it punishes large errors, but by taking the square root, it returns the error metric to the original units of the target variable, making it more interpretable than MSE.

4. R-Squared ($R^2$)

What it is: The proportion of the variance in the dependent variable that is predictable from the independent variable(s).
Formula: $ 1 - \frac{\sum (y_i - \hat{y}_i)^2}{\sum (y_i - \bar{y})^2} $
Interpretation: $R^2$ ranges from 0 to 1. A score of 1.0 means the model perfectly explains the data's variance. A score of 0.0 means the model is no better than just predicting the mean of the target variable. A negative score means the model is even worse than that!

Five houses, four metrics

Definitions blur together until you put numbers through them. Here are five predicted and actual house prices, in thousands of pounds:

HouseActualPredictedErrorAbsolute errorSquared error
1200190−1010100
2250265+1515225
3180175−5525
4300290−1010100
5400340−60603600
  • MAE = (10 + 15 + 5 + 10 + 60) / 5 = 20. On average the model is £20k out.
  • MSE = (100 + 225 + 25 + 100 + 3600) / 5 = 810. In squared thousands of pounds, which is not a unit anyone can picture.
  • RMSE = √810 = 28.5. Back in thousands of pounds, and noticeably larger than the MAE.
  • MAPE = mean of (10/200, 15/250, 5/180, 10/300, 60/400) = mean of 5%, 6%, 2.8%, 3.3%, 15% = 6.4%.

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², and what "explained variance" means

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)

  • R² = 1 — perfect predictions.
  • R² = 0 — exactly as good as always guessing the average. Your model has added nothing.
  • R² < 0 — worse than guessing the average. Entirely possible on test data, and always worth investigating rather than reporting.

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.

Choosing by the shape of the mistake you can tolerate

Each metric encodes an opinion about which errors matter.

MetricUnitsOutliersBest when
MAESame as targetTreated like any other errorEvery pound of error costs the same
MSESquaredDominates the scoreYou are optimising and want smooth gradients
RMSESame as targetHeavily weightedLarge misses are disproportionately expensive
MAPEPercentExplodes near zeroRelative error matters across different scales
NoneFollows MSEExplaining to stakeholders how much you beat the average
Huber lossSame as targetDamped past a thresholdYou 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.

Reporting numbers people can act on

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

Five metrics, and the one case that separates them

MAE, RMSE, R^2, MAPE and median absolute error on the same predictions -- then one outlier is introduced, and only some of them notice.

example_01.pyscikit-learn
Output

Try it yourself

Use the controls and the interactive plot to build a strong intuition for these metrics.

  1. The Impact of a Single Outlier: Start with the "Good Linear Fit" dataset. Drag one of the green data points far away from the prediction line. Watch the metrics change. You'll notice that MSE and RMSE increase dramatically compared to MAE. This is because they square the error, heavily penalizing this large deviation (outlier).
  2. Good Fit vs. Poor Fit: Use the "Initial Dataset" dropdown. Switch between "Good Linear Fit" and "Poor Fit (High Bias)". Observe how all error metrics (MAE, MSE, RMSE) are much higher for the poor fit. Now look at the $R^2$ score. For the good fit, it should be high (e.g., > 0.8), while for the poor fit, it will be very low, possibly even negative, indicating the model is useless.
  3. Manually Improving the Fit: Select the "Poor Fit" dataset. The orange line will be far from the data. Now, click and drag the handles on the ends of the orange line to move it closer to the green data points. As you manually improve the fit, watch all the error metrics decrease and the $R^2$ score increase towards 1.0.
  4. The Effect of Noise: Select the "Good Linear Fit" and use the "Noise Level" slider. As you increase the noise, the data points become more scattered. Notice that even with the best possible line, the error metrics will rise, and the maximum achievable $R^2$ score will fall. This shows that the inherent randomness in data puts a limit on how well any model can perform.

Which Metric Should You Use?

  • Use MAE when you want a simple, interpretable metric that is not sensitive to outliers. For example, forecasting sales where a few large errors are acceptable.
  • Use RMSE when large errors are particularly undesirable and you want to penalize them more. It's the most common metric for regression tasks. For example, predicting house prices where a large error could be very costly.
  • Use $R^2$ when you want to understand the proportion of variance your model explains. It's great for communicating the overall "goodness of fit" of your model to a non-technical audience.

Questions people ask

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.

Recap in one screen

  • MAE is the average miss in the target's own units; it treats all errors equally.
  • MSE and RMSE square the errors, so a few big misses dominate; RMSE brings the units back.
  • RMSE much larger than MAE is a reliable signal that outliers are present.
  • R² compares your model to predicting the mean; below zero it has lost to the mean.
  • MAPE is intuitive as a percentage but breaks near zero.
  • Always report a baseline, always plot the residuals.

Recall check

0 of 3

Say the answer out loud before you reveal it — recalling it is what makes it stick, and rereading it is not.

  1. What does this module say about “Overview”?

  2. What does this module say about “The Four Key Metrics”?

  3. What does this module say about “Mean Squared Error (MSE)”?

Cheat sheet

Evaluation Metrics for Regression

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.

MACHINE LEARNING · vizlearn.in/machine_learning/evaluation_metrics_for_regression.html

About the author

Ashish Jangra builds and maintains VizLearn. Every module here is written and the visualisation behind it hand-built, so the numbers in a readout come from the same code that draws the picture. Corrections are genuinely welcome and get priority over everything else — if a page states something wrong, or an animation misrepresents what the algorithm does, get in touch.