Validation metrics and holdout
Quick answer
Mean absolute error is the mean of absolute differences between observed and predicted numeric targets. It retains the target units, here seconds; smaller is better. Validation scores support model selection. Freeze the candidate and evaluation rule before examining the test labels. A test score describes the reserved sample, not a universal guarantee of future accuracy. Examples use local Python 3.13.5 and scikit-learn 1.8.0 where imported. All fixtures are synthetic; ByteMind library execution is unverified.
Compare candidates on validation rows
Validation outcomes are [6,10] seconds. Compare the baseline [6,6] and linear predictions [5,11] using identical rows.
from sklearn.metrics import mean_absolute_erroractual = [6,10]print(mean_absolute_error(actual,[6,6]))print(mean_absolute_error(actual,[5,11]))Expected output:
2.01.0The candidate has smaller validation MAE by one second. Select linear regression under the predeclared rule: lower MAE wins; ties favor baseline.
Inspect signed errors as well as MAE
Two validation predictions have equal absolute error but opposite signed errors. Use observed minus predicted as the residual convention.
actual = [6,10]predicted = [5,11]r = [a-p for a,p in zip(actual,predicted)]print(r)print(sum(abs(e) for e in r)/len(r))print(sum(r)/len(r))Expected output:
[1, -1]1.00.0Zero mean signed residual does not mean zero prediction error. MAE is one second because errors do not cancel.
Common mistakes
Never choose the candidate after comparing test scores. If you adjust the pipeline in response to test results, that test set is no longer an untouched holdout. Check row alignment and units; empty arrays do not define MAE. With only two evaluation rows, statistical uncertainty is substantial; do not claim a reliable generalization advantage.
Practice and next steps
Compute MAE for observed [3,5,7] and predicted [4,5,4]. Explain why the test set must remain reserved until the model and metric are fixed. The final milestone performs the holdout evaluation. The separate pure-Python exercise assesses the underlying calculation, not library execution.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Validation metrics and holdout — knowledge check
Apply experiment design and evaluation reasoning to synthetic examples.
MAE for [2,5] versus [3,2]?
What are MAE units for duration in seconds?
When should you choose the model?
Observed 6, predicted 8: residual under this convention?
What does a two-row test score establish?