Monitoring and drift
Compute discrepancies, distinguish their assumptions and calibrate a repeated alert policy.
Observe service and decisions
The preview service is healthy, but editors report that its queue is less useful. Request success and CPU load cannot establish whether the uploaded cards resemble the evaluation data. Conversely, a changed input distribution does not by itself establish that decisions became worse. Monitoring must distinguish these observations.
Observe the decision as well as the endpoint
Keep service indicators such as errors, queue age and complete-request delay. Add schema failures, missing features, score distributions, action rates and label coverage. Once labels mature, compute quality on the corresponding prediction cohort. A label received today may evaluate a prediction from last week and a different release.
State the shift assumption
Separate kinds of distribution change
Write . Here is the observed feature vector and the later repair label.
- Covariate shift: changes while remains fixed. More blurry uploads arrive, but the relationship between blur and repair need stays the same.
- Label shift: changes while remains fixed. The mixture of good and bad previews changes, while each class retains its feature distribution.
- Concept change: changes. A new publication standard can change whether the same feature pattern requires repair.
These are assumptions about a joint distribution. Several can fail at once. Unlabelled inputs can reveal a marginal change in but cannot establish that the conditional label rule stayed fixed. Even an unchanged input marginal can accompany a changed label rule.
Read a discrepancy with its assumptions
Compute a discrepancy and state its calibration
The following samples and bin counts are original fictional fixtures. They illustrate arithmetic and small-sample limits; they are not records from learners or a trained model.
Fixed-bin proportions
For three fixed bins, let reference fractions be and current fractions . With every fraction positive, define the population stability index
Expanding the product gives , so PSI is a symmetric sum of two discrete KL divergences. For these fractions it is . The middle bin contributes zero; the first and third account for the change. The value depends on binning, and it is not a p-value. A zero bin needs an explicit policy: report a newly observed category or record a smoothing rule and its influence. A conventional fixed cutoff does not calibrate every sample size and workload.
Category counts
If is a fixed reference distribution and current counts are with total , Pearson's discrepancy is . For counts and expected counts , it is . The expected count of one is too small to casually apply the usual large-sample chi-square approximation. If the reference proportions were themselves estimated from a small sample, a two-sample procedure must also account for that uncertainty. A large discrepancy and a valid calibrated test are different objects.
Compare empirical samples
Empirical cumulative distributions
For samples and , define as the fraction of A at most , and similarly . The two-sided KS statistic is . At , the fractions are and , giving 0.4; checking all observed values finds no larger difference.
The usual continuous-distribution KS calibration has assumptions that matter when values tie (SciPy). Here we instead enumerate all assignments of the pooled observations to two labelled groups. Under the null that observations are exchangeable between groups, 204 assignments have a statistic at least 0.4. The exact permutation p-value is . A visible discrepancy in five observations per group is weak evidence under this test. Failure to reject does not establish equality.
Compare feature representations
Maximum mean discrepancy compares average feature representations in a kernel space (Gretton et al.). If , the squared difference between sample means is
This is the nonnegative, biased empirical squared MMD, obtained by expanding a squared norm. For the linear kernel , it becomes the squared difference of ordinary means. The samples above have means 1.4 and 3, so it equals . But and have the same mean and yield zero despite different spread. Kernel choice determines which differences are visible; calibration still requires a suitable sampling assumption.
Evidence from a broader study
Rabanser, Günnemann and Lipton compared shift detection approaches over defined datasets and perturbations. Their results support combining a representation with two-sample testing in the evaluated settings, and investigating whether a detected shift is harmful. They do not establish one detector as best for every service. No benchmark data, plots or measured scores from that study are used in our fixtures.
Align populations and label time
Define the population before comparing it
Record the time window, input filters, feature version, model version and grouping unit. Comparing one scanner family in the reference window with all scanners today can manufacture a change through population selection. Keep a stable reference when testing for a change; use a rolling reference only with a stated reason, since gradual drift can disappear when the reference moves with it.
A useful alert has an owner and a follow-up measurement. A feature shift can trigger investigation of a decoder update. A growing label gap can trigger inspection of the review workflow. Neither observation alone authorizes automatic retraining or deletion of user data.
Calibrate the alerting policy
A repeated test is an alerting policy
If twenty independent tests each have a 5% false-alarm probability, the chance of at least one false alarm is . Independence is required for that calculation. A Bonferroni threshold of bounds the family-wise error for twenty valid tests without requiring independence, but can reduce detection power.
Monitoring also repeats through time. Overlapping windows are dependent, and observing a metric every minute creates more opportunities to alert. Choose windows and follow-up actions before inspecting a suspected incident, calibrate on appropriate stable periods, and measure detection delay as well as false alarms. A useful operational policy may require persistence or corroboration, but those changes must be evaluated as part of the policy.
What changed
The service-health dashboard now has a separate view of population change and delayed decision quality. Every discrepancy carries its reference, sample size and calibration method. The tiny KS example explains why a large-looking difference can still have a high p-value.
Limits
A drift detector can miss a change in an unobserved feature or in the label relationship. A large sample can flag a negligible shift. Reviewer labels can be selective or inconsistent. Repeated correlated observations can make an independent-sample test overconfident. A detector's output begins an investigation; real harm needs outcome evidence and context.
What to retain
Align windows, versions and populations. Separate input shift from quality loss. Report label maturity. Distinguish a discrepancy from its p-value. Calibrate the repeated alerting policy. Keep an owner and a concrete follow-up action.
Next
Retraining and continual learning asks which new evidence justifies a new candidate and how that candidate should be compared with the deployed release.
References
-
SciPy contributors. Two-sample Kolmogorov–Smirnov test, documentation version 1.18.0, checked 13 November 2026: statistic and continuous, independent-sample assumptions. No implementation or sample data reused.
-
Arthur Gretton, Karsten M. Borgwardt, Malte J. Rasch, Bernhard Schölkopf and Alexander Smola. A Kernel Two-Sample Test. JMLR 13, 723–773, 2012, section 2: mean embeddings and empirical MMD. Our scalar samples are original.
-
Stephan Rabanser, Stephan Günnemann and Zachary C. Lipton. Failing Loudly: An Empirical Study of Methods for Detecting Dataset Shift. NeurIPS, 2019: scope of the empirical shift-detection comparison. Reference only.
-
SciPy contributors. Pearson chi-square test, documentation 1.18.0: fixed reference probabilities and small-count limitations.
-
Zachary Lipton, Yu-Xiang Wang and Alexander Smola. Detecting and Correcting for Label Shift with Black Box Predictors. ICML, 2018: the label-shift assumption.
-
SciPy contributors. Permutation tests, documentation 1.18.0: exhaustive allocation of pooled independent samples under the exchangeability null. The enumeration here is independently implemented.
Check your understanding
The same questions as in Pulse. Answers are shared between modes.
Go deeper — optional
Code and labs do not count toward the main percentage or the certificate.
- Discrepancies and exact permutation tailsoptional
These are invented small samples, not learner data. The exhaustive permutation calculation assumes exchangeability of the pooled labels. PSI is a discrepancy, not a p-value; the tiny expected category counts do not justify an asymptotic Pearson p-value.
~20 min · easier on a computer · The corresponding lesson and basic Python functions.
Self-check in the notebook — not part of mastery or the certificate.
Answers are saved on the server and tied to this browser until you sign in.