Regression evaluation metrics
Clear, exam-focused notes on common regression evaluation metrics (residuals, MSE, RMSE, MAE, MAPE, R², adjusted R², explained variance), when to use each, derivations, diagrams to draw, and worked numerical examples with units.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Regression models predict continuous quantities (for example, height in metres or temperature in kelvin). Engineers need numbers to decide whether a model is good enough to deploy, to compare models, and to detect problems such as bias, high variance or systematic error. Evaluation metrics turn prediction errors into interpretable scores so you can answer: "Is model A better than model B?" and "Does the model meet the required accuracy for my application?".
Key ideas
Start from data and model predictions.
- Observed value (also called target or true value) is the measured value denoted y_i. Unit: SI unit of the quantity (e.g., m for length).
- Predicted value is the model output denoted ŷ_i (read "y-hat"). Same unit as y_i.
- Residual (or error) for a sample i is e_i = y_i − ŷ_i. Residuals inherit the unit of y.
From residuals we build metrics:
- Mean squared error (MSE): average of squared residuals. It penalises large errors more because of squaring.
- Root mean squared error (RMSE): square root of MSE; same unit as y and easier to interpret.
- Mean absolute error (MAE): average of absolute residuals; less sensitive to outliers than MSE.
- Mean absolute percentage error (MAPE): average of absolute percentage errors; unitless and expressed as percent but unstable when y_i ≈ 0.
- Median absolute error: median of |e_i|; robust to outliers.
- Mean error (ME) or bias: average residual (ME = (1/n) Σ e_i); unit: same as y; indicates systematic under- or over-prediction but is not an accuracy metric because positive and negative errors can cancel.
- Coefficient of determination (R²): fraction of variance in y explained by the model, defined (under the standard assumptions below) as 1 − SSE/SST, where SSE is sum of squared errors and SST is total sum of squares. R² can be negative if the model is worse than predicting the mean.
- Adjusted R²: R² adjusted for the number of predictors to penalise unnecessary complexity. Important when comparing models with different numbers of features.
- Explained variance: measures the reduction in variance of targets due to the model; similar to R² but computed from variances rather than sums of squares (useful in some libraries).
Assumptions and exact identities commonly required in exams:
- Define SSE = Σ_i (y_i − ŷ_i)^2 (sum of squared residuals).
- Define SST = Σ_i (y_i − ȳ)^2 (total sum of squares), where ȳ = (1/n) Σ_i y_i.
- Define SSR = Σ_i (ŷ_i − ȳ)^2 (regression sum of squares).
For ordinary least squares (OLS) linear regression with an intercept term, the identity SST = SSR + SSE holds. From that identity we get the exact formula for R²:
- R² = SSR / SST = 1 − SSE / SST.
Derivation (standard exam proof) that SST = SSR + SSE when model includes intercept:
- Start with y_i − ȳ = (y_i − ŷ_i) + (ŷ_i − ȳ).
- Square both sides and sum over i: Σ(y_i − ȳ)^2 = Σ(y_i − ŷ_i)^2 + Σ(ŷ_i − ȳ)^2 + 2Σ(y_i − ŷ_i)(ŷ_i − ȳ).
- The cross term 2Σ(y_i − ŷ_i)(ŷ_i − ȳ) equals zero under OLS normal equations because Σ e_i = 0 and Σ e_i·(ŷ_i − ȳ) = 0 (these follow from the intercept and orthogonality of residuals to fitted values).
- Therefore SST = SSE + SSR. QED.
Practical notes about metric choice:
- Use RMSE when large errors are especially bad (penalises big deviations).
- Use MAE if you want a measure robust to outliers and with linear penalty.
- Use MAPE when you need percentage errors, but avoid when true values can be zero or near-zero.
- Use R² to assess proportion of variance explained; compare only models fit on the same dataset (or use adjusted R² when comparing models with different feature counts).
- Do not compare RMSE/MAE across datasets with different target scales or units; use standardized or relative metrics if scales differ.
Diagrams to draw in an exam (describe exactly):
- Scatter plot of y_i (vertical axis) vs ŷ_i (horizontal axis); draw the 45° line y=ŷ. Label axes "Predicted ŷ (units)" and "True y (units)". Good predictions lie close to the 45° line.
- Residual plot: plot residuals e_i on vertical axis vs ŷ_i on horizontal axis; draw horizontal zero line at e=0 and label axes "Predicted ŷ" and "Residual e = y − ŷ". Look for patterns: non-random structure suggests model misspecification.
- If requested, sketch histograms or boxplots of residuals and a QQ-plot (quantiles of residuals vs theoretical normal), label axes.
Reviewer note: I have stated the orthogonality conditions used in the SST = SSR + SSE derivation; verify that the brief justification (residuals orthogonal to fitted values under OLS with intercept) is acceptable for your exam context.
Formulas
e_i = y_i − ŷ_i — e_i is residual for sample i; unit: same as y (SI unit), applies always.
SSE = Σ_{i=1}^n (y_i − ŷ_i)^2 — SSE is sum of squared errors; unit: (unit of y)^2; applies to any regression model for n samples.
SST = Σ_{i=1}^n (y_i − ȳ)^2 — SST is total sum of squares where ȳ = (1/n)Σ y_i; unit: (unit of y)^2; applies to any dataset.
SSR = Σ_{i=1}^n (ŷ_i − ȳ)^2 — SSR is regression sum of squares; unit: (unit of y)^2; defined for any model; in OLS with an intercept, SST = SSR + SSE.
MSE = (1/n) · Σ_{i=1}^n (y_i − ŷ_i)^2 — Mean squared error; unit: (unit of y)^2; applies to sample of size n (population version uses 1/n or 1/N depending on convention).
RMSE = sqrt(MSE) — Root mean squared error; unit: unit of y; applies when you want interpretable error in original units.
MAE = (1/n) · Σ_{i=1}^n |y_i − ŷ_i| — Mean absolute error; unit: unit of y; robust linear penalty.
MAPE = (100%/n) · Σ_{i=1}^n |(y_i − ŷ_i)/y_i| — Mean absolute percentage error; unitless (expressed as %); DO NOT use when any y_i = 0 and unstable when any y_i is near zero.
R² = 1 − SSE/SST = SSR/SST — Coefficient of determination; unitless fraction between −∞ and 1; requires SST ≠ 0 (i.e., y not all equal). For OLS with an intercept evaluated on the training data, 0 ≤ R² ≤ 1; negative values can occur on test data or for models without an intercept.
Adjusted R² = 1 − (1 − R²)·(n − 1)/(n − p − 1) — p is number of predictors (excluding intercept), n is sample size; unitless; penalises extra predictors. Requires n > p + 1 (denominator positive); can be negative; equals 1 only for a perfect fit.
Explained Variance score = 1 − Var(y − ŷ)/Var(y) — unitless; Var denotes variance computed with a consistent denominator for both terms (e.g., ddof = 0 as in many libraries); relates to R² but computed from variances. Requires Var(y) ≠ 0.
Worked examples
Example 1 — small regression errors (units: metres, m) Data (n=4): i: 1, 2, 3, 4 y_i (m): 2.0, 3.5, 3.0, 4.5 ŷ_i (m): 1.8, 3.7, 2.6, 4.2 Step 1: residuals e_i = y_i − ŷ_i (m): 1: 0.2, 2: −0.2, 3: 0.4, 4: 0.3 Step 2: SSE = Σ (e_i)^2 = 0.2^2 + (−0.2)^2 + 0.4^2 + 0.3^2 = 0.04 + 0.04 + 0.16 + 0.09 = 0.33 (m^2). Step 3: MSE = SSE/n = 0.33/4 = 0.0825 (m^2). Step 4: RMSE = sqrt(MSE) = sqrt(0.0825) = 0.2873 m. Step 5: MAE = (|0.2| + |−0.2| + |0.4| + |0.3|)/4 = (0.2 + 0.2 + 0.4 + 0.3)/4 = 1.1/4 = 0.275 m. Step 6: Compute R². First ȳ = (2.0+3.5+3.0+4.5)/4 = 13.0/4 = 3.25 m. SST = Σ(y_i − ȳ)^2 = (−1.25)^2 + 0.25^2 + (−0.25)^2 + 1.25^2 = 1.5625 + 0.0625 + 0.0625 + 1.5625 = 3.25 (m^2). Then R² = 1 − SSE/SST = 1 − 0.33/3.25 = 1 − 0.101538 = 0.898462 ≈ 0.898. Final answers (rounded): MSE = 0.0825 m², RMSE = 0.287 m, MAE = 0.275 m, R² ≈ 0.898.
Example 2 — percentage error (units: metres) Data (n=3): y = [1.0, 2.0, 4.0] m, ŷ = [0.9, 2.2, 3.6] m. Absolute percentage errors: |(1.0−0.9)/1.0|=0.1→10%, |(2.0−2.2)/2.0|=0.1→10%, |(4.0−3.6)/4.0|=0.1→10%. MAPE = (100%/3)·(0.1+0.1+0.1) = (100%/3)·0.3 = 10%. Final answer: MAPE = 10%. Note: If any y_i were 0, MAPE would be undefined for that i.
Common mistakes
- Interpreting R² without checking SST: if all y_i are equal, SST = 0 and R² is undefined.
- Comparing R² of models trained on different datasets or with different preprocessing (not allowed).
- Forgetting that R² can be negative for models that perform worse than a constant mean predictor.
- Confusing RMSE and standard deviation of residuals; RMSE equals the standard deviation of residuals only when residuals have zero mean (they do in OLS with intercept) and when you use population denominator n. Do not confuse RMSE with the residual standard error (RSE) used in linear regression inference, which is sqrt(SSE/(n − p − 1)) when an intercept is included.
For your exam
Types of questions you will get:
- Definitions: define residual, MSE, RMSE, MAE, MAPE, R², adjusted R². A full answer gives formula, units, and interpretation.
- Short notes: when to prefer MAE over RMSE, and limitations of MAPE.
- Derivations: show SST = SSR + SSE for OLS with intercept, then derive R² = 1 − SSE/SST. Show why residuals sum to zero under OLS with intercept.
- Numericals: compute MSE, RMSE, MAE and R² for small datasets. Steps must show residuals, sums, units, and final rounded answers with units.
- Diagrams: draw prediction vs true with 45° line and residual plot; label axes and explain patterns.
A full-marks answer includes: clear definitions (bolded), formulas, step-by-step derivation (for sums-of-squares identity), careful numeric steps with units, and a short interpretation of results.
Quick check
- If a model always predicts the sample mean ȳ, what is R²?
- Why is RMSE usually larger than or equal to MAE?
- What happens to MAPE when any true value y_i = 0? Answers: 1) R² = 0. 2) Because squaring penalises larger errors more, RMSE ≥ MAE for the same data (with equality when all |e_i| are equal). 3) MAPE is undefined (division by zero); the metric cannot be used when y_i = 0.
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?