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.
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
A line tells you that. A detector tells you when.
ReadAn 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.
How many runs do you need?
PredictPredict first
A monitor has run six times, and its metric jumped at the last two runs. What do the detectors say?
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.
Read a timeline
ExploreUnder a monitor's run history, Change-points plots one metric across runs, with a mark wherever a detector signaled.
View data
| run | PSI of tenure | detectors |
|---|---|---|
| 1,764,892,800,000 | 0.0743 | |
| 1,765,497,600,000 | 0.0424 | |
| 1,766,102,400,000 | 0.0672 | |
| 1,766,707,200,000 | 0.0797 | |
| 1,767,312,000,000 | 0.0531 | |
| 1,767,916,800,000 | 0.0799 | |
| 1,768,521,600,000 | 0.0762 | |
| 1,769,126,400,000 | 0.0464 | |
| 1,769,731,200,000 | 0.0402 | |
| 1,770,336,000,000 | 0.0630 | |
| 1,770,940,800,000 | 0.0787 | |
| 1,771,545,600,000 | 0.0840 | |
| 1,772,150,400,000 | 0.0470 | |
| 1,772,755,200,000 | 0.0539 | |
| 1,773,360,000,000 | 0.0835 | |
| 1,773,964,800,000 | 0.0647 | |
| 1,774,569,600,000 | 0.0618 | |
| 1,775,174,400,000 | 0.0648 | |
| 1,775,779,200,000 | 0.0693 | |
| 1,776,384,000,000 | 0.0742 | |
| 1,776,988,800,000 | 0.0785 | |
| 1,777,593,600,000 | 0.0627 | |
| 1,778,198,400,000 | 0.0745 | |
| 1,778,803,200,000 | 0.0518 | |
| 1,779,408,000,000 | 0.1904 | pettitt |
| 1,780,012,800,000 | 0.1864 | |
| 1,780,617,600,000 | 0.1794 | page_hinkley, cusum |
| 1,781,222,400,000 | 0.1903 | |
| 1,781,827,200,000 | 0.1858 | |
| 1,782,432,000,000 | 0.1858 | |
| 1,783,036,800,000 | 0.1820 | |
| 1,783,641,600,000 | 0.1787 | |
| 1,784,246,400,000 | 0.2098 | |
| 1,784,851,200,000 | 0.1985 | |
| 1,785,456,000,000 | 0.1844 | |
| 1,786,060,800,000 | 0.1912 | |
| 1,786,665,600,000 | 0.1840 | |
| 1,787,270,400,000 | 0.1711 | |
| 1,787,875,200,000 | 0.2223 | |
| 1,788,480,000,000 | 0.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.
Four detectors
Read| Detector | How it works | Good 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 mean | Noticing 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 runs | Small, 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 allows | Few 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-value | Dating a shift, looking back |
Online detectors restart after each signal, so one metric can signal several times.
A signal is a reason to look
ReflectThe 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?
Three reasons to retrain
ReadA 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.
Did the retrain help?
ExploreYou 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?
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 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.
What's live the morning after?
PredictPredict first
Your policy re-runs the plan when its trigger fires. It fires overnight. An endpoint follows champion. What serves tomorrow's requests?
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.
Set the policy
In the appOpen 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.
Rollback is one move
ReadIf 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.
Check your understanding
CheckpointCheck 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.
Find a change-point yourself
In the appCopy 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.
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 0x <- 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 1Recap
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