Classification and Thresholds
Learning goal: understand probability scores, thresholds, confusion matrix, precision, recall, specificity.
A classification model does not output "yes" or "no": it outputs a probability score between 0 and 1. Turning that into an actionable decision requires choosing a threshold: a score above the cutoff is treated as "will exceed capacity." Changing the threshold does not change the model itself, but it dramatically changes the trade-off between precision and recall.
| Predicted \ Actual | Actually exceeds threshold | Actually does not exceed threshold |
|---|---|---|
| Predicted exceeds threshold | True Positive (caught it) | False Positive (false alarm) |
| Predicted does not exceed | False Negative (missed it) | True Negative (correctly ruled out) |
from sklearn.metrics import precision_score, recall_score
proba = model_clf.predict_proba(valid[feature_cols])[:, 1]
for threshold in [0.3, 0.5, 0.7]:
pred = (proba >= threshold).astype(int)
precision = precision_score(valid["target_binary"], pred)
recall = recall_score(valid["target_binary"], pred)
print(threshold, round(precision, 3), round(recall, 3))Before choosing a threshold, write down the real cost of each type of error: missing a site that really will exceed capacity (a False Negative) may mean degraded service or emergency reallocation cost; flagging a site that would have been fine (a False Positive) wastes the resources spent pre-allocating. Once both costs are quantified, choosing a threshold becomes a decision that can be reviewed, not a feeling.
Precision
- Asks: of the cases the model flagged as exceeding the threshold, how many really did
- Raising the threshold usually increases precision
- Prioritize this when false alarms are costly
Recall
- Asks: of all cases that really exceeded the threshold, how many were caught
- Lowering the threshold usually increases recall
- Prioritize this when missing a true case is costly
Suppose missing one true case costs roughly three times as much as one false alarm, in overtime reallocation cost. In that situation, a team would typically choose a lower threshold, trading some precision for higher recall, because the cost of missing a true case is clearly larger. That choice, and the cost assumption behind it, should be written into the deployment document.
- Choosing a threshold because a number 'feels right,' without comparing it to the actual business cost
- Applying the same threshold to every site without checking whether each site's cost structure is actually the same
- Reporting only accuracy without also reporting precision and recall at the chosen threshold
- Not re-checking fairness across group_attribute subgroups after the threshold is chosen
Warning
Lowering the classification threshold from 0.5 to 0.3 most likely causes what change?