Why Threshold Selection Needs Its Own Validation
A binary classifier often produces a score for each sample rather than a final positive-or-negative decision. The decision requires a threshold: samples scoring at or above it are called positive, and those below it are called negative. In genomic applications, the threshold can substantially change how many affected samples are detected and how many unaffected samples are incorrectly flagged.
A threshold is part of the prediction procedure. If it is chosen to make sensitivity or specificity look best on the same outcomes later used to report those measures, the reported performance is optimistic: those outcomes have influenced the procedure being evaluated. The remedy is to choose the threshold using training data or inner-validation predictions, then assess it on untouched outer-fold predictions. The outer fold must not influence the threshold, the model, or any other analysis choice.
These definitions assume that both classes are represented in the evaluation set; otherwise the corresponding denominator is zero and that measure is undefined. A score need not be a probability for a threshold rule to be used. If the score is a probability, \(t=0.5\) is not automatically the right threshold: the appropriate choice depends on the intended use and the relative consequences of false negatives and false positives.
Choose the Threshold Inside the Training Process
In nested cross-validation, an outer fold is set aside for evaluation. Threshold selection belongs entirely inside the outer training data. One option is to generate inner-validation predictions within that training set, select a threshold from those predictions using a declared rule, fit the model on the full outer training set, and apply the selected threshold to scores for the untouched outer fold. The outer-fold labels are revealed only for evaluation.
A threshold-selection rule should be stated before examining outer-fold results. Common choices include maximizing Youden’s index, \(J=\text{sensitivity}+\text{specificity}-1\), on inner-validation predictions, or choosing the threshold that achieves a prespecified minimum specificity while maximizing sensitivity. The first treats the two rates symmetrically; the second reflects an operational constraint. Neither is universally best. If the consequences of errors differ, the rule should reflect the application rather than being selected after seeing outer results.
Thresholds chosen from fitted training predictions can be used, but those predictions may be unusually favorable because the model was fitted to the same samples. Inner-validation predictions offer a more defensible basis for selection. Whatever selection method is used, the outer fold remains reserved for evaluation.
Worked Example: Maximizing Youden’s Index on Inner Predictions
Suppose inner-validation predictions for eight hypothetical samples give four actual positives and four actual negatives. The positive-class scores are 0.92, 0.78, 0.61, and 0.44; the negative-class scores are 0.81, 0.55, 0.36, and 0.20. Consider thresholds 0.45, 0.60, and 0.75, and choose the one with the largest Youden’s index.
At \(t=0.45\), three of the four positive scores meet or exceed the threshold, so sensitivity is \(3/4=0.75\). Two of the four negative scores fall below it, so specificity is \(2/4=0.50\). Thus \(J=0.75+0.50-1=0.25\).
At \(t=0.60\), three positive scores meet or exceed the threshold, giving sensitivity \(3/4=0.75\). Three negative scores fall below it, giving specificity \(3/4=0.75\). Thus \(J=0.75+0.75-1=0.50\).
At \(t=0.75\), two positive scores meet or exceed the threshold, giving sensitivity \(2/4=0.50\). Three negative scores fall below it, giving specificity \(3/4=0.75\). Thus \(J=0.50+0.75-1=0.25\). The specified rule therefore selects \(t=0.60\), which has the largest inner-validation value of \(J\). This calculation selects the threshold; it does not provide an unbiased estimate of its performance.
Evaluate the Selected Rule on Untouched Outer Predictions
After selecting a threshold using only outer-training data, apply it to the scores for the corresponding outer fold. Compare the resulting predictions with that fold’s labels to calculate sensitivity and specificity. Do not revise the threshold after seeing these results. In cross-validation, repeat the full selection-and-evaluation process separately for each outer fold.
A fold-specific threshold is usually appropriate because each outer training set can select its own threshold using its own inner predictions. If performance is summarized across outer folds, state how the fold results were combined. For example, pooling the outer-fold confusion counts gives pooled sensitivity \(=\sum TP/(\sum TP+\sum FN)\) and pooled specificity \(=\sum TN/(\sum TN+\sum FP)\). This describes the predictions at the thresholds selected within the respective folds; it does not mean one universal threshold was selected for all samples.
Worked Example: Calculating Outer-Fold Performance
In a hypothetical outer fold, the model and threshold were determined without using the fold’s labels. At the selected threshold \(t=0.60\), the fold contains 10 actual positives and 10 actual negatives. Eight positives score at least 0.60, while three negatives also score at least 0.60.
The confusion counts are \(TP=8\), \(FN=10-8=2\), \(FP=3\), and \(TN=10-3=7\). Therefore:
On this untouched outer fold, the classifier detects 80% of actual positives and correctly classifies 70% of actual negatives at the threshold chosen inside the training data. These are estimates from this evaluation fold, not guarantees about future samples. In particular, the outer-fold labels were not used to obtain the threshold.
Threshold Selection Under an Operational Constraint
Sometimes the objective is not to balance sensitivity and specificity. A laboratory might require estimated specificity of at least 0.80 on inner-validation predictions, then seek the greatest sensitivity among thresholds meeting that constraint. The constraint and selection rule must be fixed using training data, not adjusted in response to outer-fold results.
Worked Example: Enforcing a Minimum Specificity
Consider the following hypothetical results from inner-validation predictions, each calculated on 20 positives and 20 negatives. The rule is to require specificity of at least 0.80 and, among eligible thresholds, select the one with the greatest sensitivity.
| Threshold | True positives | True negatives | Sensitivity | Specificity |
|---|---|---|---|---|
| 0.55 | 17 of 20 | 12 of 20 | 0.85 | 0.60 |
| 0.70 | 14 of 20 | 17 of 20 | 0.70 | 0.85 |
| 0.80 | 11 of 20 | 19 of 20 | 0.55 | 0.95 |
The rates follow directly from the counts: at 0.70, for example, sensitivity is \(14/20=0.70\) and specificity is \(17/20=0.85\). Threshold 0.55 fails the specificity constraint. Thresholds 0.70 and 0.80 satisfy it, and 0.70 has the greater sensitivity, so the inner predictions select \(t=0.70\).
Suppose the corresponding untouched outer fold contains 20 positives and 20 negatives. At the selected threshold, 15 positives and 16 negatives are correctly classified. The outer-fold sensitivity is \(15/20=0.75\), and its specificity is \(16/20=0.80\). These outer results evaluate the procedure; they do not retroactively change the threshold. The outer specificity happens to meet the target, but the inner constraint cannot guarantee that every future evaluation set will do so.
Why Reusing Evaluation Outcomes Is Optimistic
The source of optimism can be seen by considering several candidate thresholds. Each threshold produces a noisy estimate of performance. Choosing the threshold with the largest observed estimate tends to select one that performed well partly by chance. If \(\widehat{M}_j\) is an estimate of a performance measure for candidate \(j\), then
The expectation inequality follows because the maximum is at least each candidate’s estimate on every data set; taking expectations preserves that inequality. Under comparable unbiased candidate estimates, the selected maximum therefore tends to exceed the best candidate’s expected performance. The same logic applies if a threshold is chosen to maximize sensitivity subject to an observed specificity requirement. Evaluating the selected threshold on an independent outer fold avoids using the same random outcomes for both selection and assessment.
This justification does not imply that every selected threshold is severely optimistic, nor does it quantify the size of the optimism. The amount depends on such factors as the number of candidate thresholds, the variability of the estimates, and their dependence. The practical safeguard is procedural: keep outer outcomes out of threshold selection.
Diagnostics, Alternatives, and Limitations
Thresholds can be unstable when small changes in the inner data produce large changes in the selected value. Check the sensitivity and specificity across the candidate thresholds, the number of samples in each class, and whether the chosen value lies in a broad region of similar performance or at an isolated peak. If small changes alter the choice substantially, report that instability and avoid presenting a single threshold as universally established.
A prespecified threshold is an alternative when it has a defensible basis independent of the evaluation data. It removes data-driven threshold selection from the validation procedure, though the resulting sensitivity and specificity still need evaluation. A single validation split can be used to select a threshold, but the choice may be sensitive to that split. Nested cross-validation repeats selection within each outer training set and gives an evaluation that accounts for the selection process; it does not make the estimate exact or eliminate sampling uncertainty.
A common mistake is to inspect outer-fold sensitivity and specificity at several thresholds, select the most attractive one, and then report those same outer-fold results as unbiased evaluation. The correction is to treat that inspection as additional tuning: the outer outcomes are no longer untouched. Select a threshold using training or inner-validation predictions, or obtain new independent evaluation data for an assessment after the choice. Also distinguish a threshold from a model parameter: the threshold converts scores to class labels, but selecting it is still a data-dependent decision and must be included in the validation design.
Check Your Understanding
Answer each question, then compare your reasoning with the solutions below.
- A team selects the threshold that maximizes sensitivity on an outer fold, then reports that same outer-fold sensitivity. What is the problem?
- At a fixed threshold, a test set has 12 positives, of which 9 are predicted positive, and 20 negatives, of which 15 are predicted negative. Calculate sensitivity and specificity.
- Inner-validation results show that threshold 0.65 has sensitivity 0.72 and specificity 0.84; threshold 0.75 has sensitivity 0.61 and specificity 0.91. If the rule requires specificity of at least 0.80 and then maximizes sensitivity, which threshold is selected?
- Why can a threshold selected by maximizing observed inner-validation performance have an overly favorable inner estimate, and what data should be used to evaluate it?
Solutions. (1) The outer labels were used to select the threshold and to estimate performance, so the reported value is subject to selection optimism. Select using training or inner-validation data and reserve outer predictions for evaluation. (2) Sensitivity is \(9/12=0.75\). Specificity is \(15/20=0.75\). (3) Both thresholds meet the specificity constraint; 0.65 has greater sensitivity, so select 0.65. (4) Maximizing over noisy estimates tends to select a value that benefited from favorable random variation. Evaluate the selected rule using untouched outer-fold predictions, or independent evaluation data.