Part VII — Model Evaluation, Validation & Feature Engineering · Chapter 10

Grade and audit a machine learning pipeline honestly

Hook

Five chapters, five different lenses for judging a model: a confusion matrix, a ranking curve, a fold-by-fold breakdown, a grid search, a scaling check. Point every one of them at the same classifier and see which lens actually changes your mind about how good it is.

Intuition

One scored classifier, ten examples. Slide the decision threshold across three candidates and watch accuracy, precision, recall, and F1 — short for the F1 score — move independently — sometimes together, sometimes in opposite directions.

Formalize

A real evaluation doesn't pick one metric — it runs the whole scoreboard and asks where the numbers agree and where they don't:

accuracy, F1 (one threshold)AUC (every threshold at once)per-fold accuracy (where it fails)best-F1 threshold (grid search)\text{accuracy, F1 (one threshold)} \quad\big|\quad \text{AUC (every threshold at once)} \quad\big|\quad \text{per-fold accuracy (where it fails)} \quad\big|\quad \text{best-F1 threshold (grid search)}
  1. Each metric was built in isolation

    Every one of these — accuracy, F1, AUC, per-fold accuracy, best-threshold F1 — was built in its own chapter, looking at the classifier through only one lens at a time.

  2. None of them is the right answer

    Each answers a different question, and a model that looks good on one can look mediocre on another — the point of a real evaluation is to run all of them and compare, not to pick a favorite.

Play

At the default threshold of 0.50.5, accuracy is a respectable 0.70.7 but F1 lags at 0.730.73. The ranking AUC — short for Area Under the Curve — of 0.760.76 says the model's raw ordering of examples is decent but not sharp. And the fold breakdown shows exactly why: two folds are trivially easy (accuracy 1.01.0), while three folds straddling the decision boundary score only 0.50.5 each — the same overall accuracy, but now you know precisely where the model is guessing.

Worked example

Ten scored examples, five positive and five negative, with three overlapping scores right around the boundary:

  1. One threshold, two disagreeing scores

    At threshold 0.50.5, all six examples scoring 0.5\geq0.5 get predicted positive:

    • TP (true positives) =4=4
    • FP (false positives) =2=2
    • FN (false negatives) =1=1
    • TN (true negatives) =3=3

    Accuracy =0.7=0.7 looks fine. But precision is only 2/32/3 and F1 lands at 8/110.7278/11 \approx 0.727 — the two false alarms cost more in F1 than they cost in accuracy.

  2. A threshold-free verdict

    Ranking every pair of one positive against one negative, the positive scores higher in 19 of 25 pairs: AUC =19/25=0.76=19/25=0.76. This doesn't move if the deployed threshold changes — it's a property of the scores themselves, not of wherever the cutoff happens to sit.

  3. Where the fixed threshold actually fails

    Splitting the ten examples into five folds of two, in score order, and scoring the same threshold-0.50.5 classifier on each:

    • Fold 1 (scores 0.9,0.80.9, 0.8, both label 11): both predicted 11 — accuracy 1.01.0
    • Fold 2 (scores 0.70.7 label 00, 0.650.65 label 11): both predicted 11, so the label-00 one is wrong — accuracy 0.50.5
    • Fold 3 (scores 0.60.6 label 00, 0.550.55 label 11): both predicted 11, same pattern — accuracy 0.50.5
    • Fold 4 (scores 0.40.4 label 00, 0.30.3 label 11): both predicted 00, so the label-11 one is wrong — accuracy 0.50.5
    • Fold 5 (scores 0.2,0.10.2, 0.1, both label 00): both predicted 00 — accuracy 1.01.0

    [1.0,0.5,0.5,0.5,1.0][1.0, 0.5, 0.5, 0.5, 1.0] — mean 0.70.7, matching the aggregate exactly, but now visibly concentrated in three folds where a positive and a negative sit within 0.10.1 of each other.

  4. A better threshold, found by search

    Grid searching every candidate threshold by F1 finds 0.30.3 scores 10/130.76910/13 \approx 0.769 — better than the default's 0.7270.727, at the cost of accepting three false positives instead of two. Whether that trade is worth it depends on what the model is for, which no metric in this part can answer by itself.

Checkpoint

Find the threshold, among the three candidates, that scores the highest F1 — not the highest accuracy.

Pick a threshold to try it
Summary
"is this model good?"    accuracy, F1, AUC, per-fold accuracy, best-threshold F1 — pick the question, then the metric\text{"is this model good?"} \;\Rightarrow\; \text{accuracy, F1, AUC, per-fold accuracy, best-threshold F1 — pick the question, then the metric}

No single number in this part is the honest one — each is honest about a different question. Accuracy answers "how often is it right, at this cutoff?" F1 answers "how well does it balance catching positives against false alarms?" AUC answers "how good is its ranking, independent of any cutoff?" Cross-validation answers "how much would this number have changed on different data?" And grid search over the threshold answers "given everything above, what's the best cutoff to actually ship?" A real pipeline runs all five and reports the disagreement, not just the number that looked best. This closes Part IX. The next part turns from evaluating models to a new roster of architectures — GRUs, ResNets, transfer learning, and the rest of the machinery modern deep learning is built from.