Every model is trained on a snapshot of the world. When the inputs it sees in production stop looking like that snapshot, its accuracy can fall long before anyone notices in the business numbers. Measuring that shift, data drift, is the job of InsightMLFlow's monitoring agent. This article explains exactly how it measures it.

Two datasets, compared feature by feature
Drift detection compares a reference dataset (usually the training data or a known-good period) with a current one (recent production inputs). For each feature the agent computes a drift statistic and a level, then an overall score for the model.
The population stability index
For a numeric feature the agent cuts the reference data into ten bins at its deciles, so each bin holds a tenth of the reference values. It counts the share of current values falling in each bin and sums, over the bins, the difference in share times the log of their ratio. A small epsilon (10⁻⁶) avoids dividing by zero when a bin is empty. A categorical variant does the same over categories.
| PSI for a feature | Level the agent reports |
|---|---|
| below 0.1 | no significant change |
| 0.1 to 0.2 | moderate drift |
| above 0.2 | significant drift |
The overall drift score is the mean PSI across features, and the agent reports drift as detected when that mean is above 0.2. These are the conventional PSI bands; they are a starting point, not a law, and very large or very small datasets can push PSI around.
The Kolmogorov-Smirnov test
Alongside PSI the agent runs a two-sample Kolmogorov-Smirnov test (scipy.stats.ks_2samp) per numeric
feature: the largest gap between the two cumulative distributions, with a p-value. KS is sensitive to shifts anywhere in the distribution;
PSI is easier to read as a magnitude. Reading both helps: a low KS p-value with a small PSI often means a real but small change on a large
sample. A chi-squared test covers categorical features.
What happens when drift is found
The agent saves a drift report: per-feature statistics and levels, the overall score, and a language-model explanation of which features moved and what might explain it. Then the settings you chose decide what happens next:
- Alerts. Alert rules on drift and performance thresholds are defined per model and stored with it, with email or Slack notification.
- Retraining. Auto-retrain is a switch you turn on. The retraining trigger records why and hands over to the pipeline agent when a pipeline is given; with the switch off, a person starts it.
- Monitoring settings (a PSI threshold of 0.2, a performance-drop threshold of 0.05, a daily check) are stored with the model's configuration as defaults, and you can change each one.
Choosing the reference
The reference decides what "normal" means, so choose it on purpose. The training data is the usual choice, because drift from it is drift away from what the model learned. A recent known-good production window works better when training data was resampled or balanced and so never looked like production. Whatever you choose, keep the reference fixed until you retrain; a reference that moves every week hides slow drift. And check that both datasets were prepared the same way: a unit change or a new default value in a pipeline shows up as drift that has nothing to do with customers.
A routine that works
- Pick a reference window you trust and keep it fixed until the model is retrained.
- Run drift detection on a regular window of production inputs, from your scheduler.
- Look at per-feature results first: one feature with PSI 0.4 is a different story from ten at 0.15.
- When the mean crosses 0.2, check recent performance, then decide whether to retrain, and record the decision.
A worked example: why the mean can hide a problem
Suppose a model has twenty features. Nineteen are stable, each with a PSI of 0.02, and one, avg_basket_value, has shifted
sharply, with a PSI of 0.9. The overall score is the mean: (19 × 0.02 + 0.9) ÷ 20 = 0.064. That is well under 0.2, so the report says no
drift detected, while one input has moved more than four times past the “significant” line. The per-feature levels in the report
do flag it as significant; the summary number does not. Always read the per-feature table.
Edge cases worth knowing
- Values outside the reference range. The bins are built from the reference data's deciles, from its minimum to its maximum. Current values below the old minimum or above the old maximum fall outside every bin and are not counted, so a feature whose values have moved entirely beyond the reference range can show a smaller PSI than you would expect. The KS test does see them, which is one more reason to read both.
- Few distinct values. When many reference values are identical, decile edges coincide and are merged. A numeric 0/1 flag ends up with a single bin and a PSI of zero whatever happens to it. Store flags and codes as categories, so the categorical PSI and the chi-squared test are used instead.
- Very large samples. With hundreds of thousands of rows, KS and chi-squared p-values become tiny for differences that do not matter. Use the p-value to ask whether a change is real, and PSI to ask whether it is large.
- Only shared columns. Drift is computed for columns present in both datasets. A column renamed in the pipeline simply drops out of the report, so compare the feature count with what you expect.
Target drift
If you name the target column, the agent also computes PSI (and KS, for a numeric target) on the target itself and reports it separately; it is not part of the overall score. A shift in the target's distribution, when labels are available, is often a stronger reason to re-examine the model than input drift alone.
Questions
Does the performance view measure accuracy?
Not directly. It summarises recent drift reports for a deployment (how many showed drift, the average score and its trend). Measuring accuracy needs labelled outcomes, which you compute in your own evaluation and track as a run.