Learning outcomes

After this lesson, you will be able to:

Guiding questionA demand forecast may miss by 2 units or by 200. One average does not show how dangerous rare large misses are.
RegressionA machine-learning task in which a model predicts a numerical value and performance is assessed by the difference between prediction and actual value.

1. The regression task and residual

Regression predicts a numerical value: price, time, temperature, demand or energy use. For observation i, actual value is yᵢ and prediction is ŷᵢ. The residual is eᵢ = yᵢ − ŷᵢ. A positive residual means underprediction; a negative one means overprediction.

If actual demand is 120 and prediction is 110, the residual is +10. If actual is 80 and prediction is 90, it is −10. Direction differs, but both absolute errors equal 10. Metrics aggregate errors over a sample and do not replace segment or scenario analysis.

The residual is actual minus predicted.The residual is actual minus predicted.ActualPredictionResidualeᵢ = yᵢ − ŷᵢPositive: underprediction · Negative: overprediction
Figure 1. A residual retains the direction of the error.

2. MAE: Mean Absolute Error

MAE is the mean of absolute prediction errors. A miss of 20 contributes twice as much as a miss of 10. It is expressed in the target's unit: MAE = 6 minutes means a mean absolute deviation of six minutes.

MAE does not show bias direction: systematic underprediction and overprediction may produce the same score. It is less sensitive to a single large error than squared metrics, but it is not immune to outliers.

MAE
MAE = (1/n) Σ |yᵢ − ŷᵢ|
n is the number of observations; yᵢ is actual and ŷᵢ is predicted. Average the absolute residuals.

3. MSE: Mean Squared Error

MSE is the mean of squared residuals. Squaring disproportionately increases large errors: 20² = 400, while 10² = 100. This is useful when rare large misses are particularly costly.

The drawback is squared units. If the target is in kWh, MSE is in (kWh)². Squared loss is also sensitive to outliers and annotation errors; inspect extreme values before drawing conclusions.

MSE
MSE = (1/n) Σ (yᵢ − ŷᵢ)²
Average squared residuals. The unit becomes the square of the target unit.
Comparing error growthSquared error grows faster than absolute error.Increasing error magnitudeAbsolute errorSquared error
Figure 2. Schematic comparison of linear and squared penalties, not empirical data.

4. RMSE: square root of MSE

RMSE is the square root of MSE. It retains the greater influence of large errors but returns the result to the target's original unit. A temperature RMSE can therefore be discussed in degrees.

For the same set of errors, RMSE is never smaller than MAE. A larger gap is a reason to inspect large residuals. It is a diagnostic clue, not an explanation by itself. Inspect residuals rather than assuming a cause.

RMSE
RMSE = √MSE
Take the square root of MSE; the original target unit is restored.

5. R²: coefficient of determination

The standard definition is R² = 1 − SSE/SST, where SSE = Σ(yᵢ − ŷᵢ)² and SST = Σ(yᵢ − ȳ)²; ȳ is the mean actual value.

R² = 1 means perfect predictions. R² = 0 means the model is no better than predicting the evaluation-set mean under squared error. A negative value means it is worse than that baseline. R² is not a percentage of correct predictions and does not establish causality.

Distinguish the mathematical reference in R² from an operational baseline model: SST uses the mean of actual values in the evaluation sample itself. A practical baseline is usually fitted on train and predicts the training mean. Its test score therefore need not produce R² = 0. R² can be negative even when all target values are non-negative; it has no fixed lower bound.

R²
R² = 1 − SSE / SST
SSE is the sum of squared residuals; SST is the sum of squared deviations from the actual mean ȳ.

6. One set of errors, different conclusions

Suppose absolute errors are A = [2, 2, 2, 10] and B = [4, 4, 4, 4]. Both have MAE = 4. But MSE(A) = 28 and MSE(B) = 16; RMSE(A) ≈ 5.29 and RMSE(B) = 4. If large misses are costly, B is preferable.

No metric chooses a model without context. MAE shows mean absolute error, RMSE emphasizes large misses, and R² compares squared error with a mean baseline. Inspect residuals.

Key takeawayMAE shows mean absolute error; RMSE reacts more strongly to large misses.

7. Baseline comparison and honest evaluation

A complex model should outperform a simple strategy. For a continuous target, a baseline may always predict the training-set mean; for a time series, it may use the latest or seasonal value. Choose it for the real scenario without using test answers.

Fit the model and baseline on training data only. Compare MAE, RMSE and R² on the same validation or test observations. If using cross-validation from lesson 1.5.6, compare models on identical folds and keep the final test set for the last check.

Absolute metrics cannot be compared directly across different target units or scales. Inspect errors by target range, region and period.

8. Limitations and common mistakes

Do not treat MAE and RMSE as interchangeable: MAE aggregates absolute errors linearly, while RMSE gives larger errors more weight. Do not report MSE in the original target unit. Do not interpret R² as an accuracy percentage.

Zero or near-zero targets, skewed distributions, unequal error costs and outliers may require additional metrics and segment analysis. First identify which error is costly and which unit is meaningful; then select a metric, baseline and independent evaluation.

Practical exercise

Actual values: [10, 12, 15, 20, 25]. Predictions: [12, 11, 14, 18, 35]. Calculate residuals, MAE, MSE, RMSE and R². Replace the last prediction 35 with 27 and recalculate. Explain which metric changes more and why. Compare with a baseline that predicts the training mean. State the unit and do not call R² an accuracy percentage.

What to submitA residual table, four metrics, baseline comparison and a short interpretation.

Summary and next step

Regression evaluation is not about one universal number. Interpret performance through units, outlier sensitivity, a baseline and real-world error costs. The next theme develops tools and mathematical foundations for reproducible experiments.

References

  1. scikit-learn — Regression metrics — regression metrics and definitions.
  2. scikit-learn — r2_score — R² definition and caveats.
  3. Forecasting: Principles and Practice — Evaluating forecast accuracy — forecast error measures.

Key terms

RegressionРегрессия

A task in which a model predicts a numerical value.

ResidualОстаток

The difference between an actual value and a prediction.

MAEMean Absolute Error

Mean absolute deviation in the target's unit.

MSEMean Squared Error

Mean of squared residuals; large errors receive greater weight.

R-squaredКоэффициент детерминации

Comparison of model squared error with a mean-prediction baseline.

Self-check

Choose one answer for each question. Explanations appear after checking.

Question 1

What does a residual of +8 mean?

Question 2

Which metric averages absolute errors?

Question 3

Why is MSE more sensitive to a large miss?

Question 4

Which statement about RMSE is correct?

Question 5

What does R² < 0 mean?

Question 6

How should two models be compared?