Sub topic 9
Watching prediction and score distributions
This chapter assumes you can run a two-sample test and read a p-value, and that you know the Kolmogorov-Smirnov (KS) test and the Population Stability Index (PSI) from the earlier chapters. It also assumes you have a deployed classifier or regressor that logs its outputs.
Why watch predictions
Prediction drift is a change in the distribution of what the model outputs. It matters because it is cheap and fast. Predictions exist the moment the model runs, so you don't have to wait for labels. They also summarize many inputs in one number, so a shift across several weak features can show up here first.
A shift in predictions is a symptom, not a diagnosis. It can come from three places:
- The inputs changed (covariate shift), so the model reacts to new data.
- The population changed in a way the model correctly tracks, such as a seasonal rise in real fraud.
- The pipeline broke, for example a feature became null and the model fell back to a default score.
What to monitor
The right output to track depends on the model type.
| Model type | Track | Reason |
|---|---|---|
| Binary classifier | Predicted probability (score) | Shows shifts the label hides |
| Binary classifier | Share of positive predictions at the decision threshold | The rate that business users see |
| Multiclass classifier | Predicted class frequencies | Detects a class vanishing or dominating |
| Regressor | Predicted value distribution | Detects range or scale changes |
Monitor the raw score, not only the thresholded label. A score distribution can move a lot while the positive rate barely changes, and the reverse is also possible. Both views are useful.
Computing it
The tests you already know apply directly. Use KS or PSI on continuous scores. Use chi-square on predicted class counts. The reference window is usually a period right after deployment, or the validation set, as covered in the chapter on reference data.
import numpy as np
from scipy.stats import ks_2samp, chi2_contingency
rng = np.random.default_rng(0)
# Predicted probabilities: reference window vs current window
ref_scores = rng.beta(2, 5, size=5000)
cur_scores = rng.beta(2.6, 5, size=5000)
ks = ks_2samp(ref_scores, cur_scores)
print(f"Score KS statistic={ks.statistic:.3f}, p-value={ks.pvalue:.2e}")
# Predicted class counts at a 0.5 threshold, as a 2 x 2 table
ref_pos = int((ref_scores >= 0.5).sum())
cur_pos = int((cur_scores >= 0.5).sum())
table = np.array([
[ref_pos, len(ref_scores) - ref_pos],
[cur_pos, len(cur_scores) - cur_pos],
])
chi2, p_value, dof, _ = chi2_contingency(table)
print(f"Positive rate: ref={ref_pos / len(ref_scores):.3f}, "
f"cur={cur_pos / len(cur_scores):.3f}, p-value={p_value:.2e}")Common errors
- Trusting the p-value alone. With thousands of predictions per window, tiny and harmless shifts give very small p-values. Report the effect size (the KS statistic or PSI) next to the p-value, and alert on the effect size.
- Ignoring calibration changes. If you retrain or recalibrate the model, the score distribution changes by design. Reset the reference window at that point, or you will alert on a deliberate change.
- Comparing windows of different sizes or mix. Weekday and weekend traffic can differ. Compare like with like, such as this Monday with recent Mondays.
- Reading a stable output as a healthy model. Predictions can stay stable while the link between inputs and outcomes changes (concept drift). Output monitoring does not replace performance monitoring.
Exercise
Your fraud model's score distribution has a KS statistic of 0.02 with p-value 1e-5 on windows of 2 million predictions each. Should you page someone? What would you check first?
Show answer
Probably not. With millions of rows, a very small p-value appears even for a trivial shift, and a KS statistic of 0.02 is a small effect. Compare it with your normal week-to-week variation and your alert threshold on effect size. If it exceeds that threshold, next check whether feature drift or a data quality problem explains it, then check labels or proxy signals.
Exercise
You retrain and recalibrate the model, and the next day the score distribution alert fires. What is the likely cause and what should you do?
Show answer
The score distribution changed by design because of the new model or calibration. Confirm the deployment time matches the alert, then set a new reference window drawn from the new model's outputs.