Sub topic 9
Watching Prediction and Score Distributions
This chapter assumes you can read basic Python and NumPy, know what a classifier score is, and understand hypothesis tests and p-values. It also assumes you have seen the Kolmogorov-Smirnov (KS) test, the chi-square test and the Population Stability Index (PSI) from the earlier chapters on univariate drift. Here you apply them to a different target: the model's own outputs.
Why watch the outputs
A production model might take 200 input features. Testing each feature gives you 200 p-values, and most of the changes they flag will not matter. The model's output is a single number or label per row, and it is a function of all the inputs. If the inputs shift in a way the model is sensitive to, the output distribution usually shifts too.
Output monitoring has three practical advantages:
- It needs no labels. You can compute it the moment predictions are made, even if ground truth arrives weeks later.
- It is one series per model, not one per feature, so it is cheap to alert on.
- It sees the model's view of the world. A feature can drift heavily without changing the predictions at all, and you may not care about that drift.
It also has limits, covered in the gotchas section below. Prediction drift is a symptom, not a diagnosis.
What to track
The right output statistic depends on the model type.
| Model type | Output to monitor | Suitable comparison |
|---|---|---|
| Binary classifier | Predicted probability (score) | KS test, PSI on score bins |
| Binary classifier | Share of rows above the decision threshold (positive rate) | Chi-square on 2 x 2 counts, or a tolerance band |
| Multiclass classifier | Predicted class counts | Chi-square on 2 x k counts |
| Multiclass classifier | Max probability (confidence) | KS test, PSI |
| Regression | Predicted value | KS test, PSI, plus mean and quantiles |
| Ranking or recommender | Score of top-ranked items, share of each category shown | KS test, chi-square |
Track both the raw score and the thresholded decision. They answer different questions. The score distribution tells you whether the model's internal view has moved. The positive rate tells you whether the business effect has moved, for example how many loans are rejected or how many alerts are sent to reviewers. A small shift in scores near the threshold can produce a large shift in decisions.
Where the monitoring points sit
A worked example
The script below simulates a reference window and a current window of scores from a binary classifier. The current scores are shifted slightly upward. It runs a KS test on the scores, a chi-square test on the decisions at a 0.5 threshold, and PSI on the scores.
import numpy as np
from scipy.stats import chi2_contingency, ks_2samp
def psi(reference, current, bins=10, eps=1e-6):
edges = np.quantile(reference, np.linspace(0, 1, bins + 1))
edges[0], edges[-1] = -np.inf, np.inf
edges = np.unique(edges)
ref_pct = np.histogram(reference, bins=edges)[0] / len(reference)
cur_pct = np.histogram(current, bins=edges)[0] / len(current)
ref_pct = np.clip(ref_pct, eps, None)
cur_pct = np.clip(cur_pct, eps, None)
return float(np.sum((cur_pct - ref_pct) * np.log(cur_pct / ref_pct)))
rng = np.random.default_rng(42)
ref_scores = rng.beta(2.0, 5.0, size=10_000)
cur_scores = rng.beta(2.4, 5.0, size=10_000)
# 1. Score distribution
ks = ks_2samp(ref_scores, cur_scores)
print(f"Score KS statistic={ks.statistic:.3f}, p-value={ks.pvalue:.2e}")
print(f"Score PSI={psi(ref_scores, cur_scores):.3f}")
# 2. Decision distribution at a 0.5 threshold
threshold = 0.5
table = np.array([
[(ref_scores >= threshold).sum(), (ref_scores < threshold).sum()],
[(cur_scores >= threshold).sum(), (cur_scores < threshold).sum()],
])
chi2, p_value, dof, _ = chi2_contingency(table)
print(f"Positive rate: reference={table[0, 0] / table[0].sum():.3f}, "
f"current={table[1, 0] / table[1].sum():.3f}")
print(f"Decision chi2={chi2:.1f}, dof={dof}, p-value={p_value:.2e}")Read the output in this order:
- The KS statistic is the largest gap between the two cumulative distributions. It is an effect size between 0 and 1. The p-value only says whether that gap is distinguishable from noise.
- PSI summarizes the shift across quantile bins of the reference scores. A common rule of thumb reads below 0.1 as stable, 0.1 to 0.25 as moderate, and above 0.25 as large. Treat those cutoffs as starting points, not laws.
- The positive rate shows what the shift means in practice. Here it is the share of rows that would now be flagged.
With 10,000 rows per window, the p-values will be tiny even for a small shift. That is expected, and it leads to the first gotcha.
Interpreting a shift
A change in prediction distribution has several possible causes, and the monitoring signal alone cannot tell them apart.
| Cause | What it looks like | How to confirm |
|---|---|---|
| Covariate shift in sensitive features | Scores move, and feature tests flag the features the model relies on | Check drift on the top features by importance |
| Label shift (the class mix changed) | Positive rate rises or falls, and features correlated with the label move | Compare with other signals of the true class mix, such as business volumes |
| Upstream pipeline bug | Sudden step change, often with missing values or odd ranges | Check data quality metrics for the same time |
| Model or preprocessing change | Step change at a deploy time | Compare the change time with the release log |
| Seasonality or a known event | Regular cycle, or a spike matching a campaign | Compare with the same period in a previous cycle |
| Segment mix change | Overall shift, but each segment looks stable | Compute the metric per segment |
The last row is easy to miss. If traffic moves from a low-risk region to a high-risk region, the overall score distribution shifts even though the model behaves identically in each region. Slicing by a few stable segments, such as country, channel or device, separates mix changes from behavior changes.
Gotchas
Large samples make tests oversensitive. The KS and chi-square p-values shrink as the sample grows. With 100,000 rows a trivial shift gives a p-value near zero. Alert on the effect size (KS statistic, PSI, change in positive rate), not on the p-value alone. If you do use p-values, require both a small p-value and an effect size above a floor you chose.
Small windows are noisy. If a daily window has 200 rows, the positive rate will wander by several percentage points from chance. Use a longer window, or compute a bootstrap interval for the reference rate and alert when the current rate leaves it.
No prediction drift does not mean no problem. Concept drift changes the relation between inputs and the label. If the inputs and the predictions stay put while the true outcomes change, output monitoring sees nothing. Only performance monitoring with labels catches that case. Offsetting shifts in two features can also cancel in the score.
Prediction drift can be correct behavior. A fraud model should flag more transactions during a real fraud wave. In that case the shift is the model working. The test cannot tell you which situation you are in. Combine it with feature drift and, when available, labels.
Scores from different model versions are not comparable. After a retrain, the score scale can change even when quality improves. Recompute the reference window from the new model's outputs, for example from a shadow period, and do not compare against the old model's scores.
Calibration matters for thresholds. If the score is a calibrated probability, a shift in mean score is a shift in the expected positive rate, which is easy to interpret. If the model is uncalibrated, the same shift has no direct meaning, and you should lean on rank-based or quantile-based comparisons such as PSI on reference quantiles.
Heavy ties break binning. Models that output a few distinct values, such as a tree ensemble with shallow trees, can give repeated quantile edges. The psi function above removes duplicate edges with np.unique, so it uses fewer bins in that case. Check how many bins were actually used.
Practical setup
- Log the raw score, the decision, the model version and a timestamp for every prediction. Without the raw score you cannot recompute anything later.
- Choose a reference window from a period the model was known to behave well, such as the first stable weeks after launch or the validation set when the inputs are representative.
- Compare fixed-size or fixed-duration windows, such as daily or weekly, against that reference. A rolling reference of the previous week catches sudden changes. A fixed reference catches slow change that a rolling reference would absorb.
- Plot the mean score, selected quantiles (for example the 10th, 50th and 90th) and the positive rate over time next to the test results. The plot shows direction and timing, which a single statistic does not.
- Add per-segment versions for the two or three segments that matter most to the business.
Relationship to the next steps
Prediction drift tells you that something changed and how large it is for the model's outputs. It does not tell you whether accuracy fell. The later chapters on delayed labels and on drift versus performance show how to decide whether a flagged shift needs action.
Exercise
A fraud model scores 50,000 transactions per day. Your daily KS test on the scores returns a p-value below 1e-10 every day for a week, but the KS statistic is 0.02 and the positive rate moved from 1.20% to 1.22%. The score distribution also looks identical in each of your three main regions. What do you conclude, and how should you change the alert rule?
Show answer
The shift is statistically detectable but tiny. The large sample size makes the p-value extremely small, while the KS statistic of 0.02 and the positive-rate change of 0.02 percentage points show a negligible effect. The per-region check shows no segment-level change either. Do not treat it as an incident. Change the alert rule to require an effect size above a chosen floor (for example KS statistic above 0.1, PSI above 0.1, or a positive-rate change beyond a set tolerance), optionally in combination with the p-value, so that only meaningful shifts page someone.