Classification Metrics and Decision Thresholds › Practical Implications

Michael BrenndoerferOctober 24, 20268 min read
Machine Learning from ScratchAll chapters
Part 4 of 15Model Evaluation and Selection
Chapter 32Classification Metrics and Decision Thresholds › Practical Implications
Reading section 8 of 10 · Practical Implications · 8 minSection 8 of 10 · 8 min

Section 8 of 10 · 8 min read

Classification Metrics and Decision Thresholds › Practical ImplicationsSection view · Sections in this chapter8 / 10 ↓
Reading tools Definitions, links & notes

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Notes & comments

Metrics serve two different jobs: comparing scores before a deployment decision and operating a score after one. For comparison, ROC AUC is a reasonable default when both classes are represented and the question is ordering; average precision is often more informative when positives are rare and false alerts compete for finite review capacity. For deployment, neither summary is the deliverable. The deliverable is a fixed threshold, the confusion matrix it produces on held-out data, and a statement of the cost or service level implied by that operating point. A model comparison can end with an AUC; an operational decision cannot.

Cost elicitation belongs to the modeling work rather than to a final sign-off. A false positive may consume analyst time, create customer friction, or trigger unnecessary account freezes; a false negative may produce chargebacks, missed maintenance, or regulatory exposure. Estimate these components where evidence permits and record the uncertainty in the ratio. When no credible ratio can be assembled, present recall, precision, false positive rate and alert volume over the thresholds. Cost curves can still be shown for explicitly assumed ratios, but cannot be specified without costs. Choosing an operating point expresses an operational tradeoff even when that tradeoff has not been fully priced. The same discussion should establish whether one threshold is defensible across segments. Different error-cost ratios can justify different probability cutoffs. Different base rates can change the appropriate cutoff on a shared raw score or require segment-aware probability estimation. If scores already represent the relevant segment-conditional probabilities and error costs are common, the same probability cutoff remains optimal across segments.

Best Practices

Keep the roles of training, validation, and test data distinct. The scorer is fitted on training data, the threshold is selected on validation data by minimizing observed cost or by applying a justified closed-form cutoff, and the test split is opened once to report the resulting rule. When the score is a calibrated probability, you should compare the analytic cutoff with the empirical minimizer; disagreement is information about calibration or finite-sample variability, not a reason to force the two numbers together. When the score is only a ranking, skip the closed form and minimize empirical cost directly.

Report the decision as an interval and a cost, not as a suspiciously precise threshold. Because predictions change only when a score is crossed, the optimal threshold is usually a plateau; the midpoint is a convenient representative, but the endpoints and the cost across the plateau are more informative than three decimal places. Bootstrap the selection procedure to show how far the threshold moves under resampling, and, when estimating cost uncertainty, report it separately because the two quantities have different units. The illustration above used 300 resamples; more resamples can reduce Monte Carlo noise in this resampling summary, but cannot repair limited validation data or establish interval coverage by themselves.

Alongside the chosen threshold, report recall, precision, false positive rate, alert volume, and the confusion matrix on held-out data. State the positive class and the score orientation explicitly, since reversing the score reverses its ranking and requires changing the decision convention. If average precision is quoted, quote the prevalence of the evaluation set with it; if ROC AUC is quoted, make clear that it is a ranking summary and not evidence that the deployed alert volume is acceptable.

Data Requirements and Preprocessing

The minimum inputs are paired labels and scores for validation and test data, with the positive class oriented so that larger scores mean stronger evidence for the event of interest. Both classes must be present for ROC AUC; the stated average-precision definition requires at least one positive, and at least one positive prediction must occur at a threshold for precision to be defined without an explicit convention. Costs should be supplied in the same units, and any segment identifiers needed for subgroup reporting should be retained. For the closed-form probability cutoff, the scores must be probabilities for the deployment population; for empirical cost selection, arbitrary finite scores are acceptable.

Little preprocessing is required for the rank-based summaries because ROC AUC and average precision are invariant to strictly increasing transformations of the score. Rescalings that are defined and strictly increasing on the score domain do not change its ordering; a logarithm, for example, requires positive scores, but they do change the numeric threshold, so the threshold must be expressed on the same scale and orientation as the scores that will be seen in deployment. Ties should be handled as tied groups rather than broken arbitrarily. Missing scores need an explicit policy, and a calibration layer, if used, is a separate fitted component with its own validation requirements.

Prevalence deserves its own check. Under a pure prevalence shift that holds both class-conditional score distributions fixed, the identity P=Rπ/(Rπ+FPR(1−π))P = R\pi/(R\pi + \text{FPR}(1-\pi)) translates recall and false positive rate into deployment precision when the alert probability is positive. Label-only enrichment of a validation set can create such a shift. More general population changes can alter the class-conditional distributions and therefore the ROC curve itself, so changing π\pi in the formula alone is not a substitute for re-evaluating on a representative sample.

Common Pitfalls

A damaging mistake is selecting the threshold on the test set and then reporting performance on the same observations. That is leakage with extra steps: the reported cost is optimized on the data used to judge it, which can bias the reported cost downward and removes an independent evaluation of the choice. This selection effect is a repeated-sample statement, not a guaranteed ordering for every realized result. The fix is procedural rather than mathematical: record the validation-selected threshold before opening the test split, and do not revise it after seeing test results.

A second recurring mistake you should avoid is treating F1F_1 as if it were a decision rule. Maximizing F1F_1 encodes an implicit and usually unstated tradeoff between precision and recall, and it does not use the stated error costs. It is entirely possible for the F1F_1-optimal threshold to sit far from the cost-optimal one, especially when prevalence or the cost ratio is extreme. If a stakeholder requests the F1F_1-optimal threshold, show it beside the cost-optimal rule and name the difference in expected cost.

Other pitfalls follow from using the wrong summary for the wrong job. A high ROC AUC can coexist with an unusable number of false alerts at the operating point, and average precision estimated at one prevalence cannot be assumed to transfer unchanged to another. Applying the closed form cFP/(cFP+cFN)c_{FP}/(c_{FP}+c_{FN}) to an uncalibrated margin or vote fraction produces a threshold that looks principled but has no probability interpretation. Reporting a threshold to many decimal places when the cost curve is flat over a wide interval overstates the precision of the selection, and ignoring segment-level error rates can hide a rule that is acceptable on average and harmful to a subgroup.

Computational Considerations

The threshold sweep requires one sort followed by linear scans; its runtime depends on the sample size and implementation. Sorting the scores once costs O(nlog⁡n)O(n \log n), cumulative sums produce all distinct confusion matrices in O(n)O(n), and the ROC curve, precision-recall curve, and cost curve can all reuse the same sweep. Memory is linear in the sample size, dominated by the sorted scores and the cumulative count arrays. For a single validation or test set, this is practical for millions of observations on a modern machine, and the dominant cost is usually the sort rather than the metric arithmetic.

Repeated resampling multiplies that cost. A bootstrap with BB resamples performs BB sorts and sweeps, so the total work is O(B nlog⁡n)O(B\,n \log n); the 300-resample illustration is modest, while thousands of resamples on very large data can become the bottleneck. Reuse curve arrays across plotting and reporting cells, avoid recomputing the sweep for each figure, and parallelize resamples when the implementation allows. Calibration adds a separate fitting cost and should be validated as its own step rather than folded silently into threshold selection.

Performance and Deployment Considerations

Track alert volume and, when outcomes are available, precision and confusion counts at the fixed threshold. Precision and the confirmation rate among alerts describe the same fraction; estimate it from complete or representative alert outcomes. False-negative counts and recall also need outcomes for unflagged cases, so reviewed alerts alone cannot supply a full confusion matrix. ROC AUC can complement these operational quantities, but needs both labeled classes and can stay unchanged under a pure prevalence shift. Segment-level summaries can expose differences hidden by aggregate results.

The threshold should be revisited when error costs, prevalence, or the class-conditional score distribution change enough to move the operating point. A change in prevalence alone can leave recall and false positive rate unchanged under a pure shift while moving precision, so alert capacity and review workload should be monitored separately from ranking quality. If the score is used as a probability, check its calibration for the target population and recalibrate if needed before applying the closed-form cutoff; if it is used only as a ranking, rerun empirical cost selection on a representative validation sample. The honest deployment report includes the chosen threshold or plateau, the held-out cost, the alert volume, and the uncertainty from the selection procedure.

Comments

Add to the conversation

A question, a correction, or an example from your own work.

No comments yet. Be the first to share your thoughts!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy