Visual explainer
Model Evaluation
Why you cannot trust training scores and how train, validation, and test splits keep you honest.
Model evaluation measures how well predictions match the task on data kept out of fitting and selection. Choose a metric that reflects the mistakes that matter, then use an evaluation split that resembles the intended use.
The bars reuse the synthetic classifier from machine learning basics: 4/4 training answers are correct, compared with 3/4 held-out answers. Each division is one example, on a common four-example scale. The gap shows why the training score is insufficient. It does not, by itself, prove memorization; noise, distribution shift and sampling variation can also produce a gap.
Give Splits Different Jobs
Start a separate allocation example with 1,000 rows: 700 training, 150 validation and 150 final test. Segment lengths are proportional to row counts. Training fits parameters, validation helps choose settings, and the test assesses the chosen procedure after those decisions are fixed.
The 70/15/15 ratio is illustrative. Random splitting assumes the resulting sets represent the target task appropriately. Related records may need grouping; forecasting needs chronological separation. More rows do not repair a split that lets the same subject or future information cross the boundary. See scikit-learn's validation guidance.
Compare Predictions With Truth
For metric arithmetic, switch to a separate synthetic cohort of 100 cases, not the 150-case test allocation above. Define the positive class as the outcome we want to detect. Rows show actual labels and columns show predicted labels, following the confusion-matrix convention.
There are 40 true positives (TP): actual positives predicted positive. The 20 false negatives (FN) are missed positives. The 10 false positives (FP) are negative cases flagged positive, and the 30 true negatives (TN) are correctly rejected negatives. Equal cell areas identify categories; they do not encode count magnitude. The counts sum to 100, with 60 actual positives and 50 positive predictions.
Choose On Validation
This independent ten-case validation illustration compares candidates A, B and C, which get 7, 8 and 6 answers right. At 30 drawing units per correct answer, B has the longest bar. Select B if validation accuracy is the chosen criterion; the isolated test lock supplies no feedback to this choice.
Fix the settings, preprocessing and decision threshold before final testing. Repeatedly changing the model to improve the reported test score makes that set part of selection. A new untouched assessment is then needed. Heavy validation reuse can overfit validation too; the lock is a protocol, not a promise that every future score will match.
Count All Correct Predictions
Return to the 100-case confusion fixture. The bracket combines TP40 and TN30: accuracy is (40+30)/100 = 0.70. The remaining 30 errors combine FN20 and FP10. Segment lengths use five drawing units per case; the full track is all 100 cases. This is the fraction of matching labels.
Accuracy weighs each case equally. If missing a positive costs more than a false alarm, that single fraction hides an important distinction. An untouched test estimates performance under its sampling conditions; it guarantees neither an identical deployment score nor protection from distribution shift.
Ask About Positive Predictions
Restrict attention to the 50 positive predictions: 40 TP and 10 FP. Precision is 40/(40+10) = 0.80. The bracket is the denominator; the solid segment is the numerator. A dashed, labelled FP segment makes false alarms identifiable without colour.
This scene uses seven drawing units per case to enlarge the selected subset. The other 50 cases are excluded from this question, not assigned zero weight in the original confusion counts. Precision helps assess the usefulness of alerts. It is undefined if there are no positive predictions; software needs an explicit convention for that case.
Ask About Actual Positives
Change the denominator to all 60 actual positives: 40 found and 20 missed. Recall is 40/(40+20) = 2/3, approximately 0.667. The per-case scale stays at seven drawing units, so the TP segment has the same length as before while the full bracket grows.
Precision and recall answer different questions. Recall is undefined when the evaluated set contains no actual positives. If one summary is useful, F1 combines them as 2TP/(2TP+FP+FN) = 80/110, approximately 0.727. F1 omits true negatives and still does not encode the application's error costs.
Move The Decision Threshold
Keep the same 100 cases and fix their scores: 40 positives score 0.9; 10 negatives score 0.8; 20 positives score 0.4; 10 negatives score 0.35; and 20 negatives score 0.1. These scores are invented rankings for arithmetic, not calibrated probabilities. Predict positive when score is at least the chosen threshold.
At 0.5, the counts reproduce TP40, FP10, FN20, TN30. Lowering the threshold to 0.3 admits the 20 missed positives and 10 more negatives: TP60, FP20, FN0, TN20. The plot shows only positive predictions at four drawing units per case, with a common scale across rows. Recall rises to 60/60 = 1, while precision falls to 60/80 = 0.75. Accuracy becomes 80/100 = 0.80. Whether the extra alerts are worthwhile depends on costs; choose the threshold on validation data, then freeze it for test evaluation.
Rotate Validation Blocks
Revisit the 1,000-row allocation, keeping the final 150 test rows separate. Combine training and validation into 850 development rows. Five equal blocks contain 170 rows each. Each row of the drawing is a fresh fit: V marks the validation block, while the other four blocks supply 680 training rows. Each block validates once, and the five validation scores can be averaged to compare settings. Fit preprocessing separately inside each training fold.
Cross-validation uses more fits to reduce dependence on one partition; it does not eliminate uncertainty or guarantee a better model. Five is an example, not a rule triggered by a row-count cutoff. Use a splitting scheme that respects class representation, subject groups or chronology as appropriate. After selection, refitting on all 850 development rows is possible before final testing. Continue with cross-validation.
Where It Breaks
A separate one-feature example makes leakage numerical. The training values are 0 and 2, so their mean is 1. The held-out value is 8. Both number lines use the same scale: circles are training values, the triangle is held out, and diamonds are fitted means. The amber route shows the forbidden influence of the test value on preprocessing.
Using all three rows changes the mean to (0+2+8)/3 = 10/3, approximately 3.33. Correct train-only centering produces training values -1 and 1, then transforms the test value to 7. The leaked mean instead produces training values -10/3 and -4/3, with test value 14/3. Test information has changed the fitted transform. This establishes contamination, not a measured accuracy gain: its effect depends on the downstream model and data.
Split first and fit learned transformations on training data, then apply those parameters to held-out data. Pipelines help maintain that boundary during cross-validation. Even a clean pipeline cannot make an unrepresentative test set a guarantee of future performance.
The Quick Version
- Evaluate on data excluded from fitting and selection.
- Validation chooses settings; a reserved test assesses the fixed procedure.
- TP40, FP10, FN20 and TN30 give 70% accuracy.
- Precision is 40/50; recall is 40/60.
- Lowering a threshold can find positives and increase false alarms.
- Cross-validation rotates validation blocks across separate fits.
- Fit preprocessing inside training splits to prevent held-out information leakage.