Sub topic 14
Setting thresholds and limiting false alarms
This chapter assumes you can compute a KS statistic, a chi-square p-value and a PSI score, as covered in the earlier chapters on univariate tests and PSI. It also assumes you know what a p-value is. The question here is what to do with those numbers: at what value should a person be paged?
Why default thresholds fail
A drift test run on every feature, every hour, will produce false alarms. Suppose you monitor 50 features with a p-value cutoff of 0.05. Even when nothing has changed, you expect about 2.5 features to be flagged each run. Over 24 hourly runs, an alert fires almost every day.
Large samples create a second problem. With 100,000 rows per window, a KS test detects shifts far too small to affect the model. The p-value is tiny, but the shift is not important. An alert based on the p-value alone then measures sample size more than it measures harm.
Use effect size, not only p-values
Alert on how big the shift is. Use the KS statistic, the PSI value, or the domain classifier AUC as the effect size. A p-value says whether a difference is detectable. An effect size says whether it is large.
Common starting points for PSI are below 0.1 (stable), 0.1 to 0.25 (moderate shift) and above 0.25 (large shift). These are conventions from credit scoring, not laws. Treat them as a first guess and tune them against your own history.
Calibrate on history
The most reliable method is to measure your own noise. Take a period when the model was healthy. Compute the drift score for every window pair in that period. Then set the threshold above the normal range.
import numpy as np
def calibrate_threshold(healthy_scores, quantile=0.99):
"""Return a threshold that healthy history exceeded only 1% of the time."""
return float(np.quantile(healthy_scores, quantile))
rng = np.random.default_rng(0)
# Simulated daily PSI values from a healthy 90-day period
healthy_psi = np.abs(rng.normal(0.04, 0.02, size=90))
threshold = calibrate_threshold(healthy_psi)
print(f"Alert when PSI > {threshold:.3f}")
today = 0.12
print("ALERT" if today > threshold else "ok")This ties the false alarm rate to a number you chose. A 0.99 quantile on daily scores gives roughly one false alarm per 100 days per feature.
Techniques to limit false alarms
- Require persistence. Alert only when the score exceeds the threshold for several consecutive windows, such as 3 of the last 4. A single noisy window does not page anyone.
- Use two severity levels. A warning goes to a dashboard or ticket. A critical alert pages a person. For example, PSI above 0.1 is a warning and above 0.25 is critical.
- Correct for many features. Apply a Bonferroni correction, which divides the p-value cutoff by the number of tests, or alert on the count of drifted features instead of each one.
- Weight by importance. Drift in a feature the model barely uses matters less. Set tighter thresholds on high-importance features.
- Match the window to the traffic. Small windows give noisy scores. Use windows large enough that a stable feature gives a stable score.
Common errors
- Copying the PSI 0.25 rule without checking it against your data.
- Alerting on p-values with very large windows.
- Setting a threshold once and never reviewing it. Revisit thresholds after each false alarm and each missed incident.
- Treating every alert as equally urgent. Link alerts to the response playbook so each has a defined next step.
Exercise
You monitor 40 features with a KS test at p < 0.05 on hourly windows of 200,000 rows. You receive many alerts, yet model accuracy is stable. Give two changes that would reduce false alarms.
Show answer
Alert on an effect size such as the KS statistic or PSI instead of the p-value, because large windows make tiny shifts significant. Also calibrate thresholds on healthy history, require persistence over several windows, or correct for the 40 tests (for example with a Bonferroni correction or by alerting on the count of drifted features).