Why a 90% alert can mean an 8.3% chance of an incident
An incident classifier trained on a deliberately balanced archive assigns a new message a 90% incident probability. In production, only one message in a hundred concerns an incident. An engineer proposes multiplying every score by 0.01/0.50. That would turn 90% into 1.8%. You can test this adjustment with a pencil and two piles of messages.
An alert’s precision depends on prevalence
Illustrative sensitivity 90% and false-positive rate 10%; Bayes’ rule converts alert likelihoods to posterior probability.
Rebuild the balanced archive
Imagine a binary message feature called a flag. It appears on 90% of incidents and 10% of ordinary messages. In a balanced archive of 100 incidents and 100 ordinary messages, the flagged pile contains 90 incidents and 10 ordinary messages. A model trained to report the incident frequency for flagged messages should say 90%.
In a hypothetical live batch with 100 incidents and 9,900 ordinary messages, keep the same flag frequencies within each class. The flagged pile now contains 90 incidents and 990 ordinary messages. Its incident frequency is , about 8.33%. The numerator stayed at 90. The denominator grew in a way that depended on how often ordinary messages carried the flag.
Transfer the likelihood ratio
Let be the sampled incident fraction and the target fraction. For features , let be the sampled posterior probability. Under class-dependent sampling that leaves the feature distribution within each class intact, Bayes’ rule gives
The first factor transfers to the target population. Divide out the old prior odds and multiply by the new ones. With ,
The sample prior odds are one, so a 90% sampled probability supplies likelihood ratio 9. Target prior odds are . Posterior odds become , yielding probability . On a log-odds scale the repair is a constant additive offset. The nonlinear conversion back to probability explains why multiplying the probabilities by one constant fails.
Which parts of the system change?
| Sample probability | Probability at a 1% live incident rate |
|---|---|
| 50% | 1.00% |
| 90% | 8.33% |
| 99% | 50.00% |
A sampled probability of 50% gives no evidence beyond the balanced prior. In production the same evidence leaves you at the live prior. A 99% sample probability supplies likelihood ratio 99, just enough to bring live posterior odds to one. Because the correction is strictly increasing for interior priors, it preserves the review ordering. A dashboard using fixed probability thresholds can nevertheless change dramatically. What AUC measures in a review queue
from fractions import Fraction as F
def transfer(p, sample_rate, live_rate):
factor = live_rate * (1 - sample_rate) / (sample_rate * (1 - live_rate))
return factor * p / (1 - p + factor * p)
assert transfer(F(9, 10), F(1, 2), F(1, 100)) == F(1, 12)
Practice
SelectionThe archive kept every incident but chose ordinary messages by searching for suspicious words. Does the same correction apply?Show answer
Ordinary messages with those words are overrepresented even conditional on being ordinary. The archive’s feature likelihood ratio can differ from the live one. Correcting the prior alone cannot reconstruct the missing distribution. A representative live sample or known feature-dependent sampling probabilities can help identify the necessary correction.
Operational thresholdWith the same priors, what sampled probability corresponds to a live probability of 10%?Show answer
Live odds require a likelihood ratio of . Balanced-sample odds therefore equal 11 and the sampled probability is , about 91.67%. This conversion assumes that the input probabilities are calibrated for the sampled population.