Judging numeric predictions.
Read absolute error, squared error, and residuals without mistaking one number for the whole story.
Start with the meaning.
Regression predicts a quantity: a price, temperature, duration, or demand count. A residual is the actual value minus the predicted value. A positive residual means the model predicted too low; a negative one means it predicted too high. Looking at residuals matters because a single average can hide a pattern. A model may be accurate for low prices and systematically underestimate expensive homes.
Mean absolute error, often MAE, averages the absolute sizes of residuals. If errors are 2, -3, and 4 units, their absolute sizes are 2, 3, and 4, so MAE is 3 units. Root mean squared error, RMSE, first squares errors, averages them, and takes the square root. Large misses affect RMSE more strongly. Because both are in the target's unit, they can be interpreted against a practical tolerance: an error of 3 minutes may be fine for a day-long delivery and disastrous for a minute-long process.
How the idea works.
A percentage error can seem intuitive but becomes unstable when actual values are zero or near zero. It can also weight small targets very strongly. R-squared compares squared-error performance with predicting the mean of the observed target values; a value near 1 means the model explains much of the variation under that comparison, while a negative value is possible when it performs worse than the mean baseline. It does not guarantee that individual predictions are acceptable.
The choice of metric expresses a cost. If a rare very large error is unacceptable, RMSE or a quantile of errors may reveal it. If typical error matters most, MAE may communicate better. If underprediction has a different cost from overprediction, report them separately or use a task-specific loss. A model card or report should name the metric, unit, dataset, and population. “MAE 3” alone is not enough to know whether a system is useful.
Plots of residuals against predictions or important features can reveal structure. A growing spread at larger predictions suggests the model's uncertainty changes with scale. A curved residual pattern suggests a linear model missed a nonlinear relationship. Those observations do not prove a cause, but they point to questions about representation, data quality, and whether a single average score is hiding different regimes.
Follow the code.
from sklearn.metrics import mean_absolute_error, root_mean_squared_error
actual = [10, 20, 30]
predicted = [12, 17, 34]
residuals = [a - p for a, p in zip(actual, predicted)]
print(residuals)
print(mean_absolute_error(actual, predicted))
print(root_mean_squared_error(actual, predicted))The residuals are -2, 3, and -4. Their absolute sizes average to 3, so the MAE is 3 units of the target. RMSE is larger because squaring gives extra weight to the error of 4. Both metric functions compare aligned actual and predicted sequences; swapping the order does not change these two magnitudes, but it would reverse the sign convention of a residual list. The code does not train a model. It isolates the meaning of an evaluation calculation.
A score from three cases is a teaching example, not a stable estimate. In a useful evaluation, predictions come from a model that did not fit on these target answers. The test cases should represent the decisions for which the score is reported, and the report should include the distribution of errors rather than only a mean.
What the result does not say.
Prediction intervals express a range of plausible outcomes under stated assumptions or a calibrated method. A point prediction such as 20 does not communicate how uncertain the future value is. Not every regression estimator supplies a trustworthy interval automatically; it requires its own method and evaluation.
Target values can be noisy or subjective. If two measurements of the same quantity disagree, there is a limit to what any model can predict from the available features. Better labels and clearer measurement may improve a system more than changing the algorithm.
One clear idea.
A regression metric measures a particular kind of error in a particular unit; inspect who and what it hides.
The ML cookbook
Complete, explained Python workflows sit alongside this reading course.