Regression evaluation metrics

Compare definitions of commonly used regression error measures.

By

Arrows grouped on an archery target.
Photo by Wacky1976. Wikimedia Commons, CC BY-SA 4.0.

How close are our predictions?

Suppose we have predicted a material property. Before I call the model useful, I want you to compare those predictions with measurements. A graph is a good start, but a single error measure answers only one part of our question. Let us see what each measure keeps track of.

Four panels compare MAE, MSE, RMSE and R-squared. MAE and MSE average the errors using one over N. R-squared compares squared errors with a mean baseline and can be negative.
The four measures answer different questions. Let us read the chart together below; the formulas are also provided as selectable text.

Let us read the four measures

I use \(y_i\) for a measured value and \(\hat y_i\) for its prediction. We have \(N\) observations, and \(\bar y\) is their measured mean. The symbol \(\sum\) tells us to add the contribution from every observation.

Definitions for one target, with equally weighted observations
MeasureFormulaWhat you can read from it
Mean absolute error (MAE)\(\displaystyle \frac{1}{N}\sum_{i=1}^{N}|y_i-\hat y_i|\)The average size of an error, in the target’s units. Smaller is better when we compare predictions for the same task.
Mean squared error (MSE)\(\displaystyle \frac{1}{N}\sum_{i=1}^{N}(y_i-\hat y_i)^2\)Square each error before averaging. Large errors contribute more strongly; the units are squared.
Root mean squared error (RMSE)\(\displaystyle \sqrt{\frac{1}{N}\sum_{i=1}^{N}(y_i-\hat y_i)^2}\)Take the square root of MSE to return to the target’s units. It remains sensitive to large errors.
Coefficient of determination (R²)\(\displaystyle 1-\frac{\sum_{i=1}^{N}(y_i-\hat y_i)^2}{\sum_{i=1}^{N}(y_i-\bar y)^2}\)Compare squared prediction errors with the errors from predicting the measured mean. For a nonconstant target, 1 means perfect predictions, 0 matches that mean baseline, and a negative value is worse than the baseline.

Notice the factor \(1/N\): MAE and MSE are means, rather than sums. Also, R² can be negative; it is not restricted to the interval from 0 to 1. For a constant measured target, the usual R² formula has a zero denominator and needs separate handling.

Let us read the chart together

MAE: how large are our errors, on average?

I would begin with the top-left panel. For each material, you find the difference between its measured property and our prediction. We take the size of that difference, so an overestimate cannot cancel an underestimate, and then average those sizes. If our MAE is 6.67 MPa, you can read that as an average absolute error of 6.67 MPa. Whether that is useful depends on the property range and the accuracy your application needs.

MSE: what happens when a few errors are large?

Now look at the top-right panel. We square each error before averaging. An error of 10 contributes 100, while an error of 2 contributes only 4. I use this comparison to show you why a few large mistakes can strongly affect MSE. If our property is measured in MPa, MSE is measured in MPa², so we should not read an MSE of 50 as an error of 50 MPa.

RMSE: can we return to the property’s units?

Let us move to the bottom-left panel. We take the square root of MSE. You can now compare the result with a measurement in the original units: √50 gives an RMSE of about 7.07 MPa. We have restored the units, but large errors still have a strong influence. I would look at both MAE and RMSE, together with the individual prediction errors.

R²: are we doing better than a simple guess?

Finally, look at the bottom-right panel. Imagine that we ignore the inputs and predict the measured mean for every observation. R² compares our model’s squared errors with that baseline on the same observations. A score of 1 means perfect predictions; 0 means that we match the mean baseline. If you see a negative R², our predictions have a larger squared error than the baseline. The score is not restricted to 0–1.

For our small example below, R² is 0.8125. We have reduced the summed squared error by 81.25% relative to the mean baseline on these three observations. That does not by itself show that we will predict a new material accurately. We still need a fair evaluation on observations that were not used for fitting or choosing the model.

Try three observations with me

Here is a small illustrative example, rather than an experimental dataset. Imagine measured strengths of 100, 120 and 140 MPa, with predictions of 110, 115 and 135 MPa. Our measured-minus-predicted errors are −10, 5 and 5 MPa.

Now you can ask a materials question: is an error of about 7 MPa acceptable for this application? The score alone cannot make that decision for us. We need the measurement uncertainty, the useful property range and the cost of a poor prediction.

What can R² hide from us?

Before you choose the model with the larger R², I would like you to pause. We are comparing squared errors with a particular baseline, and that comparison has limits.

A perfect correlation, but poor predictions

Let us keep the illustrative measurements of 100, 120 and 140 MPa, but now predict 120, 140 and 160 MPa. Every prediction is 20 MPa too high. The predictions and measurements have a correlation of 1, so its square is also 1.

Our squared prediction errors add to 1200 MPa², while the mean-baseline errors still add to 800 MPa². The R² in our chart is therefore 1 − 1200/800 = −0.5. You can see why I would check the actual errors instead of using a correlation as a substitute for this score: these predictions are worse than predicting the measured mean.

For an ordinary least-squares regression with an intercept, evaluated on its own fitting observations, R² does equal the squared correlation between fitted and measured values when both vary. That special relationship is not a general rule for arbitrary predictions or test data.

Which comparison should we trust?

I would compare models on the same held-out observations, using the same target units. A model can fit its training measurements closely and still predict new materials poorly. Keep the test data separate from fitting and model selection, and inspect a predicted-versus-measured plot alongside these numbers.

Let us put these definitions to work in regression with one input variable, then continue to regression with several input variables. You can also explore why a close fit can miss a trend.

For the library definitions and the constant-target caveat, see scikit-learn’s regression metrics guide and its R² reference.

Help me keep these tutorials going

If this tutorial helped you, you can support the time I spend creating examples and checking the code.

Support is voluntary. My tutorials remain freely available.