Skip to content

Change-points, and deciding when to retrain

Date a shift in a monitored metric, write a retraining trigger, and see why a retrain only ever produces a candidate.

Advanced ~14 min13 steps

You will be able to

  • Tell online detectors apart from a retrospective test
  • Read a change-point timeline as a reason to look
  • Write a retraining trigger, and choose between recording it and re-running the plan
  • Explain why a dip followed by a recovery doesn't show that retraining worked

Read first

01

A line tells you that. A detector tells you when.

Read

An alert rule asks whether a number crossed a line today. A change-pointChange pointThe moment a series' level (mean) jumps — a relocated station, a new instrument, a policy taking effect. detector asks a different question: did this metric's level shift, and at which run?

That date is what you take to the people who know the data. A shift in the same week as a pipeline release is a very different story from a slow slide.

02

How many runs do you need?

Predict

Predict first

A monitor has run six times, and its metric jumped at the last two runs. What do the detectors say?

They report a change at the newest runThey report nothing yetThey report an error
Reveal

Nothing yet. They need at least 8 runs of a metric, and the app says so rather than guessing. An alert rule that uses a detector stays unknown until then. For the first weeks of a model's life, use plain thresholds, and let the detectors take over as the history grows.

03

Read a timeline

Explore

Under a monitor's run history, Change-points plots one metric across runs, with a mark wherever a detector signaled.

Change-points on a timelineWhen did this monitored metric shift, and which detectors noticed?
View data
runPSI of tenuredetectors
1,764,892,800,0000.0743
1,765,497,600,0000.0424
1,766,102,400,0000.0672
1,766,707,200,0000.0797
1,767,312,000,0000.0531
1,767,916,800,0000.0799
1,768,521,600,0000.0762
1,769,126,400,0000.0464
1,769,731,200,0000.0402
1,770,336,000,0000.0630
1,770,940,800,0000.0787
1,771,545,600,0000.0840
1,772,150,400,0000.0470
1,772,755,200,0000.0539
1,773,360,000,0000.0835
1,773,964,800,0000.0647
1,774,569,600,0000.0618
1,775,174,400,0000.0648
1,775,779,200,0000.0693
1,776,384,000,0000.0742
1,776,988,800,0000.0785
1,777,593,600,0000.0627
1,778,198,400,0000.0745
1,778,803,200,0000.0518
1,779,408,000,0000.1904pettitt
1,780,012,800,0000.1864
1,780,617,600,0000.1794page_hinkley, cusum
1,781,222,400,0000.1903
1,781,827,200,0000.1858
1,782,432,000,0000.1858
1,783,036,800,0000.1820
1,783,641,600,0000.1787
1,784,246,400,0000.2098
1,784,851,200,0000.1985
1,785,456,000,0000.1844
1,786,060,800,0000.1912
1,786,665,600,0000.1840
1,787,270,400,0000.1711
1,787,875,200,0000.2223
1,788,480,000,0000.1744

This simulated metric shifts at week 24. Find the marks. The retrospective test sits on the shift, and the online detectors sit a little after it, since they need a few runs of evidence.

Hover over the marks and compare the dates with the level of the line.

04

Four detectors

Read
DetectorHow it worksGood for
Page–HinkleyPage–Hinkley testAn online alarm that tracks how far a metric has strayed from its running mean and fires when it wanders too far.Tracks how far the metric strays from its running meanNoticing soon after a shift, online
CUSUMCUSUM testTracks the running sum of (recursive or OLS) residuals; a stable regression keeps it inside the boundary lines.Adds up deviations from a baseline set by the early runsSmall, sustained shifts, online
ADWINADWINA detector that keeps a window of recent runs and drops the older part whenever the two parts clearly differ.Drops the older part of a window when the two parts differ by more than chance allowsFew false alarms; needs many runs and a clear shift
PettittPettitt testA rank-based test for one shift in level — K is the largest gap between the ranks before and after a split.Tests for one shift in the whole series, with a p-valueDating a shift, looking back

Online detectors restart after each signal, so one metric can signal several times.

05

A signal is a reason to look

Reflect

The detectors can still raise false alarms over long stable stretches, Page–Hinkley and CUSUM especially. And ADWIN staying quiet over a few dozen runs doesn't show that nothing changed.

Page–Hinkley signaled last Tuesday, and the other three are quiet. What would you look at before you tell anyone? What would you want to see in the data, and who would you ask about that week?

06

Three reasons to retrain

Read

A retraining policyRetraining policyThe conditions under which a model is trained again on newer data, on a schedule or when monitoring says so. is a trigger checked after each monitor run. It can mix three kinds of reason:

share_drifted() >= 0.5
metric("roc_auc") < model.roc_auc - 0.03
model.age_days > 90

These are drift, falling performance, and age. Join them with OR for "any of these". Drift alone is a weak reason, as the model may still be fine. Falling performance is the strongest, and it arrives last.

You can also set up a schedule of the kind Model retraining, or press Retrain now.

If the Python or R setup changed since registration, the version's page says so. Check results re-scores the training rows against the saved scores; then pick Retrain or Keep using it. Monitors record this as env_drift.

07

Did the retrain help?

Explore

You retrain when a metric looks bad. The next run looks better. Did retraining do that?

CExplorable · Regression to the mean

Why do the worst performers often improve with no treatment at all?

What does the selected group average on the second test?

1.25
How sure?
0.50
0.10
600

The diagonal means "same score twice". The large dot is the selected group's average: it sits below the diagonal, with no treatment.

Commit your prediction above to see the result

Make your prediction first; the figure appears when you commit.

Make your prediction to see the result.

Select the group with extreme first scores, and watch their second scores move back toward the average, with no treatment at all. Lower the correlation, and the move gets larger.

A monitored metric is noisy in the same way. If you act on the worst runs, the next run tends to look better whatever you did. To judge a retrain, compare the old and new versions on the same rows.

08

What's live the morning after?

Predict

Predict first

Your policy re-runs the plan when its trigger fires. It fires overnight. An endpoint follows champion. What serves tomorrow's requests?

The retrained version: it replaced the championThe old champion, with a new candidate waitingNothing: the endpoint is down until someone approves
Reveal

The old champion. A retrain re-runs the plan on the dataset's newest version and registers a Candidate. It never promotes one, so a bad batch of data can't reach production by itself. Promotion goes through the gates, with a person asking for it.

09

Set the policy

In the app

Open Gates & policy and find Retraining.

  • Turn on Check after monitor runs, and write a Trigger.
  • When it fires can be Only record it or Re-run the plan. Start with recording, so you learn how often it fires.
  • Days between sets the wait after a retrain, 7 by default.

The history below shows when it fired, why, and what came of it. Only a single learner's plan can be re-run; rebuild an ensemble or a Discover scorer by hand.

10

Rollback is one move

Read

If a promoted version misbehaves, open the version table, and use the Aliases button on the previous version to make it champion again.

Monitors and endpoints that follow the alias move with it. Rollback goes through the same gates as any other promotion, so a held rollback in an emergency is what an override with a reason is for.

That's why you keep the previous version live, and why callers should use aliases rather than version numbers.

11

Check your understanding

Checkpoint

Check yourself

You want to date one shift in six months of history, with a p-value. Which detector fits?

Show the answer

Answer: a

Pettitt looks back over the whole series for a single shift, and gives a p-value. The other two watch runs as they arrive, and signal a little after a shift.

Check yourself

After a bad month you retrain and promote. Next month's AUC recovers. What can you conclude?

Show the answer

Answer: b

The recovery is compatible with a real improvement, and also with regression to the mean. A paired comparison separates the two.

Check yourself

Your trigger is share_drifted() >= 0.5 OR metric("roc_auc") < model.roc_auc - 0.03. This batch has no outcomes, and 60% of features drifted. What happens?

Show the answer

Answer: a

Unknown OR true is true. If the drift clause were false instead, the trigger would be unknown and wouldn't fire.

12

Find a change-point yourself

In the app

Copy a metric's values from your monitor's run history into a file, oldest first, or use any ordered series. Then try Pettitt's test.

Python
import numpy as np
import pandas as pd

x = pd.read_csv("monitor_runs.csv")["auc"].to_numpy()

def pettitt(x):
    n = len(x)
    u = [np.sign(x[t + 1:, None] - x[: t + 1]).sum() for t in range(n - 1)]
    t = int(np.argmax(np.abs(u)))
    k = abs(u[t])
    return {"first_after": t + 1, "K": float(k), "p": min(1.0, 2 * np.exp(-6 * k**2 / (n**3 + n**2)))}

print(pettitt(x))  # first_after counts from 0
R
x <- read.csv("monitor_runs.csv")$auc

pettitt <- function(x) {
  n <- length(x)
  u <- sapply(1:(n - 1), function(t) sum(sign(outer(x[(t + 1):n], x[1:t], "-"))))
  t <- which.max(abs(u))
  k <- abs(u[t])
  c(first_after = t + 1, K = k, p = min(1, 2 * exp(-6 * k^2 / (n^3 + n^2))))
}

pettitt(x)  # first_after counts from 1
13

Recap

Recap
  • Online detectors signal soon after a shift; Pettitt dates one shift looking back. All of them need at least 8 runs.
  • A signal is a reason to look, not proof that something changed.
  • A retrain produces a candidate and never promotes one; the gates decide from there.
  • Judge a retrain by comparing versions on the same rows, because bad months tend to be followed by better ones.

Concepts in this lesson