A delivery app predicts how long each order will take. The evaluation report shows an R² of 0.915, the release note calls the model "91.5% accurate", and the app starts promising arrival times within 5 minutes. Support tickets follow: about 3 orders in 10 miss that window. A month later the team checks the model on short downtown trips, sees an R² of 0.09 and concludes it doesn't work there. Its errors downtown are almost the same as everywhere else.
The common misconception
Many developers read R² as an accuracy percentage for regression: 0.915 means 91.5% of the predictions are right, and a high R² means the predictions are close enough to use. It's easy to see why:
It usually lands between 0 and 1, like a percentage, and reports often print it as one.
It's the default: score on every scikit-learn regressor returns R², so it's the first number people see.
On a single test set, a higher R² really does mean smaller squared errors, so it works for ranking models.
The half-truth: R² is a fair way to compare models on the same data. But it measures how much better the model is than predicting the average, not how close its predictions are to the truth.
What actually happens
Regression has no "correct" prediction to count. A forecast of 41 minutes for a 43-minute trip is neither right nor wrong, only off by 2 minutes. Every regression metric is a different summary of those gaps.
R² compares your errors with the average's errors
is 1 minus the model's squared errors divided by the squared errors of always predicting the mean of the test targets. The scikit-learn reference spells out the scale: 1.0 is perfect, a constant model that predicts the average gets 0.0, and the score can be negative because a model can be arbitrarily worse than that. So 0.915 says the model's squared error is 8.5% of the average's. It says nothing about how many predictions are close.
The same errors, a different R²
The denominator is the spread of the target in whatever data you score. Across all trips, from 1 to 30 km, delivery times vary a lot, so the average is a terrible guess and beating it is easy. Among trips under 5 km, times are similar, the average is already decent, and the same model has little left to beat.
import numpy as npfrom sklearn.dummy import DummyRegressorfrom sklearn.linear_model import LinearRegressionfrom sklearn.metrics import mean_absolute_error as mae, r2_scorefrom sklearn.metrics import root_mean_squared_error as rmsefrom sklearn.model_selection import train_test_splitrng = np.random.default_rng(0)km = rng.uniform(1, 30, size=(5000, 1))jam = 30 * (rng.random(5000) < 0.05)minutes = 8 + 3 * km[:, 0] + rng.normal(0, 4, 5000) + jamX_tr, X_te, y_tr, y_te = train_test_split(km, minutes, random_state=0)base = DummyRegressor().fit(X_tr, y_tr) # always predicts the meanprint(f"baseline MAE {mae(y_te, base.predict(X_te)):.1f}")model = LinearRegression().fit(X_tr, y_tr)short = X_te[:, 0] < 5 # trips under 5 kmfor name, rows in [("all trips", slice(None)), ("under 5 km", short)]: true, pred = y_te[rows], model.predict(X_te[rows]) within = np.mean(abs(true - pred) <= 5) print(f"{name:<10} R2 {r2_score(true, pred):.2f} MAE {mae(true, pred):.1f}" f" RMSE {rmse(true, pred):.1f} within 5 min {within:.0%}")# baseline MAE 22.9# all trips R2 0.92 MAE 4.8 RMSE 7.8 within 5 min 70%# under 5 km R2 0.09 MAE 5.3 RMSE 8.7 within 5 min 66%
The "91.5% accurate" model lands within 5 minutes on 70% of orders. On short trips its R² collapses from 0.92 to 0.09, yet its average error only moves from 4.8 to 5.3 minutes. The model didn't break downtown; the yardstick changed. scikit-learn's guide says it directly: because the target's variance depends on the dataset, R² may not be meaningfully comparable across different datasets. That includes two segments of your own data.
MAE and RMSE speak in minutes
is the average size of the errors: on a typical order, the estimate is 4.8 minutes off. squares the errors, averages them and takes the square root, so it's in minutes too, but big misses weigh more. Google's Machine Learning Crash Course puts the difference this way: MAE represents the average prediction error, while RMSE represents the spread of the errors and is more skewed by larger errors. Here RMSE is 7.8 against an MAE of 4.8, because 5% of orders lose 30 minutes in a jam. A wide gap between the two is a signal in itself: a few large misses are driving the error.
The baseline puts both in context. Always predicting the average trip time is off by 22.9 minutes on a typical order; the model cuts that to 4.8. That's the comparison R² summarizes, in a unit a product manager can use.
Metric
Answers
Units
Watch out for
R²
How much better than predicting the mean?
None, at most 1
Changes with the target's spread; can be negative
MAE
How far off is a typical prediction?
Target units
Treats one 30-minute miss like six 5-minute misses
RMSE
How big are errors, with large misses weighted more?
Target units
A few big errors can dominate it
Share within tolerance
How often are we close enough?
% of predictions
You have to choose the tolerance
How to apply it in your project
Start from a baselineScore DummyRegressor, which predicts the training mean, with MAE. Every model should be judged by how far below it lands.
Report errors in the target's unitsPut MAE, and RMSE when large misses matter, next to R² in every report.
Measure the tolerance directlyIf the business has a tolerance, such as 5 minutes or 10% of the price, report the share of predictions inside it.
Compare R² only on the same test setUse it to rank models scored on identical data, never to compare segments or datasets.
Break errors down by segmentLook at MAE per region, price band or customer type to find where the model really struggles.
Key takeaways
R² measures improvement over predicting the mean, not the share of correct predictions: 0.915 came with only 70% of orders within 5 minutes.
It depends on the target's spread: the same model scored 0.92 overall and 0.09 on short trips, with MAE 4.8 and 5.3.
MAE is the typical error; RMSE weighs big misses more, so a wide gap between them means a few large errors.
Pick the metric from what errors cost, report it in the target's units, and compare it with a baseline.
التعليقات (0)