Skip to content
BIASED

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 P(X,Y)=P(Y∣X)P(X)=P(X∣Y)P(Y)P(X,Y)=P(Y\mid X)P(X)=P(X\mid Y)P(Y). Here XX is the observed feature vector and YY the later repair label.

  • Covariate shift: P(X)P(X) changes while P(Y∣X)P(Y\mid X) remains fixed. More blurry uploads arrive, but the relationship between blur and repair need stays the same.
  • Label shift: P(Y)P(Y) changes while P(X∣Y)P(X\mid Y) remains fixed. The mixture of good and bad previews changes, while each class retains its feature distribution.
  • Concept change: P(Y∣X)P(Y\mid X) 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 XX 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 p=(0.6,0.3,0.1)p=(0.6,0.3,0.1) and current fractions q=(0.2,0.3,0.5)q=(0.2,0.3,0.5). With every fraction positive, define the population stability index

PSI=∑i(qi−pi)log⁡qipi.\mathrm{PSI}=\sum_i(q_i-p_i)\log\frac{q_i}{p_i}.

Expanding the product gives DKL(q∥p)+DKL(p∥q)D_{KL}(q\|p)+D_{KL}(p\|q), so PSI is a symmetric sum of two discrete KL divergences. For these fractions it is 1.0832201.083220. 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 pp is a fixed reference distribution and current counts are OiO_i with total nn, Pearson's discrepancy is ∑i(Oi−npi)2/(npi)\sum_i(O_i-np_i)^2/(np_i). For counts (2,3,5)(2,3,5) and expected counts (6,3,1)(6,3,1), it is 18.66666718.666667. 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 A=[0,1,1,2,3]A=[0,1,1,2,3] and B=[1,2,3,4,5]B=[1,2,3,4,5], define FA(t)F_A(t) as the fraction of A at most tt, and similarly FB(t)F_B(t). The two-sided KS statistic is D=sup⁡t∣FA(t)−FB(t)∣D=\sup_t|F_A(t)-F_B(t)|. At t=1t=1, the fractions are 3/53/5 and 1/51/5, 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 (105)=252\binom{10}{5}=252 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 204/252≈0.809524204/252\approx0.809524. 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 k(x,z)=⟨ϕ(x),ϕ(z)⟩k(x,z)=\langle\phi(x),\phi(z)\rangle, the squared difference between sample means is

∥1n∑iϕ(xi)−1m∑jϕ(zj)∥2=1n2∑i,i′k(xi,xi′)+1m2∑j,j′k(zj,zj′)−2nm∑i,jk(xi,zj).\left\|\frac1n\sum_i\phi(x_i)-\frac1m\sum_j\phi(z_j)\right\|^2 =\frac1{n^2}\sum_{i,i'}k(x_i,x_{i'})+\frac1{m^2}\sum_{j,j'}k(z_j,z_{j'})-\frac2{nm}\sum_{i,j}k(x_i,z_j).

This is the nonnegative, biased empirical squared MMD, obtained by expanding a squared norm. For the linear kernel k(x,z)=xzk(x,z)=xz, it becomes the squared difference of ordinary means. The samples above have means 1.4 and 3, so it equals 2.562.56. But [−1,1][-1,1] and [−2,2][-2,2] 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 1−0.9520≈64.15%1-0.95^{20}\approx64.15\%. Independence is required for that calculation. A Bonferroni threshold of 0.05/20=0.00250.05/20=0.0025 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

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.

Full notes

Answers are saved on the server and tied to this browser until you sign in.