Retraining: When, on What, and How to Promote
Every deployed model is trained on the past and judged on the present, and the gap grows each day. The monitors of the previous lessons tell you that a gap has opened; retraining closes it. Three decisions make up a retraining policy: when to retrain (on a schedule, when a monitor fires, or continuously), on what data (a sliding window, everything so far, or everything with recent data weighted up), and how to promote the new model (an offline comparison against the current one on recent data, then a careful rollout). Each choice has a cost, and one trap, the feedback loop, can make retraining quietly worse than not retraining.
When: scheduled, triggered, continuous
- Scheduled (periodic): retrain every week or month whatever happens. Simple, predictable, easy to staff and to audit. It wastes compute when nothing changed and reacts late when something changes right after a run.
- Triggered: retrain when a monitor fires: an error-rate detector on matured labels, a drift alarm on important features, a business KPI out of its band. It reacts to real change and saves the runs that would not help, but only as well as the monitor: a missed drift is never retrained for, and a noisy monitor retrains on every false alarm.
- Continuous: retrain on every new batch, or update online (online learning). Freshest, but every update is a deployment, so it needs the guarded-update machinery of replay and rollback, and a bad batch reaches users fast.
Most teams combine them: a schedule as the default, a trigger that can pull the next run forward, and a manual button for incidents.
On what: windows and weights
- Sliding window (the last few months): follows drift fastest and forgets old concepts on purpose. A short window is noisy (few rows) and forgets rare events (a once-a-year pattern falls out of the window).
- Expanding window (all data so far): the most data and the lowest variance, the right choice when the concept is stable. Under drift it averages old and new concepts, and the old ones dominate more every month.
- Weighted (all data, recent rows weighted up, for example halving the weight every two months via
sample_weight): a compromise between the two, with one more knob (the half-life).
Which wins depends on how fast the concept moves, so measure it on your own history with a time-ordered backtest, never with a random split.
From scratch: no retraining, periodic, triggered
A simulated stream of 24 months, 1,000 rows each, two features. The true decision boundary turns slowly, 3 degrees per month, and on month 14 it jumps by a further 40 degrees. Labels for a month are known at the end of that month, so a model used in a month can be trained on the months before it. Every strategy trains a LogisticRegression on the last 3 months; they differ only in when.
import numpy as np
from sklearn.linear_model import LogisticRegression
rng = np.random.default_rng(0)
months, n = 24, 1000
data = []
for m in range(months):
angle = np.deg2rad(3.0 * m + (40.0 if m >= 14 else 0.0)) # slow turn + a jump at month 14
X = rng.normal(size=(n, 2))
y = (X @ np.array([np.cos(angle), np.sin(angle)]) + 0.3 * rng.normal(size=n) > 0).astype(int)
data.append((X, y))
def fit(last): # train on the 3 months before `last + 1`
X = np.vstack([data[k][0] for k in range(last - 2, last + 1)])
y = np.concatenate([data[k][1] for k in range(last - 2, last + 1)])
return LogisticRegression().fit(X, y)
def error(model, m):
X, y = data[m]
return float((model.predict(X) != y).mean())
def run(policy):
model, retrains, errs = fit(2), 0, []
base = np.mean([error(model, k) for k in range(3)]) # its error on its own data
for m in range(3, months):
if m > 3:
last_err = error(model, m - 1) # labels of last month just matured
due = (policy == "monthly" or (policy == "every 6 months" and (m - 3) % 6 == 0)
or (policy == "triggered" and last_err > base + 0.03))
if due:
model, retrains = fit(m - 1), retrains + 1
base = np.mean([error(model, k) for k in range(m - 3, m)])
errs.append(error(model, m))
return np.array(errs), retrains
print("policy mean error worst month error m14-16 retrains")
for policy in ("never", "every 6 months", "triggered", "monthly"):
errs, r = run(policy)
print(f"{policy:16s} {errs.mean():.3f} {errs.max():.3f} "
f"{errs[14 - 3:17 - 3].mean():.3f} {r}")policy mean error worst month error m14-16 retrains
never 0.320 0.582 0.458 0
every 6 months 0.164 0.331 0.260 3
triggered 0.132 0.308 0.220 5
monthly 0.115 0.269 0.207 20
Measured as the mean error over months 3 to 23 (1,000 rows each, every month evaluated before its labels are used): never retraining ends at 0.320, with a worst month of 0.582, worse than guessing, because the boundary has turned by more than 90 degrees by the end. Retraining every 6 months brings the mean to 0.164 with 3 runs. The trigger (last month's error more than 0.03 above the model's error on its own training months) reaches 0.132 with 5 runs, and does better in months 14 to 16 (0.220 against 0.260) because it does not wait for a date. Retraining every month is best, 0.115, but needs 20 runs. On this stream, a quarter of the runs buys most of the benefit; whether the last 0.017 is worth 15 more retrainings, validations and rollouts is a cost question, not a statistics question.
Sliding, expanding or weighted?
The same stream, retrained every month, with three choices of training data. A second stream without any drift shows the other side of the trade-off.
import numpy as np
from sklearn.linear_model import LogisticRegression
def stream(turn, jump, seed, months=24, n=1000):
rng = np.random.default_rng(seed)
out = []
for m in range(months):
angle = np.deg2rad(turn * m + (jump if m >= 14 else 0.0))
X = rng.normal(size=(n, 2))
y = (X @ np.array([np.cos(angle), np.sin(angle)]) + 0.3 * rng.normal(size=n) > 0).astype(int)
out.append((X, y))
return out
def mean_error(data, window, half_life=2.0):
errs = []
for m in range(3, len(data)):
first = m - 3 if window == "sliding (3 months)" else 0
X = np.vstack([data[k][0] for k in range(first, m)])
y = np.concatenate([data[k][1] for k in range(first, m)])
w = None
if window == "weighted (half-life 2)":
age = np.concatenate([np.full(len(data[k][1]), m - 1 - k) for k in range(first, m)])
w = 0.5 ** (age / half_life)
model = LogisticRegression().fit(X, y, sample_weight=w)
errs.append((model.predict(data[m][0]) != data[m][1]).mean())
return float(np.mean(errs))
for name, data in (("drifting stream", stream(3.0, 40.0, 0)),
("stable stream", stream(0.0, 0.0, 1))):
print(name)
for window in ("sliding (3 months)", "expanding (all)", "weighted (half-life 2)"):
print(f" {window:24s} mean error {mean_error(data, window):.4f}")drifting stream
sliding (3 months) mean error 0.1155
expanding (all) mean error 0.2278
weighted (half-life 2) mean error 0.1315
stable stream
sliding (3 months) mean error 0.0923
expanding (all) mean error 0.0920
weighted (half-life 2) mean error 0.0923
On the drifting stream the expanding window is twice as bad as the sliding one (0.2278 against 0.1155): by month 20 it is still dominated by months whose boundary pointed elsewhere. Weighting with a half-life of 2 months lands in between (0.1315). On the stable stream the three are practically equal (0.0920 to 0.0923), with the expanding window slightly ahead because it has the most data. The choice is a bet on how fast your concept moves; a backtest on your own history settles it.
Promotion: champion against challenger
A retrained model is a challenger; the model in production is the champion. Never promote a challenger because training finished. Compare both offline on the same recent, held-out data, data neither was trained on and as close to today as labels allow, with a rule written down before looking:
- the challenger is better on the main metric by a margin larger than the noise (a paired bootstrap over the same rows gives the noise);
- it is not worse by more than a tolerance on any important segment;
- it passes the same sanity checks as any release: calibration, latency, output range, the tests in CI.
Then it goes through the registry and a shadow or canary rollout, so online behaviour gets a vote too.
import numpy as np
from sklearn.linear_model import LogisticRegression
rng = np.random.default_rng(0)
def month(m, n=1000):
angle = np.deg2rad(3.0 * m)
X = rng.normal(size=(n, 2))
y = (X @ np.array([np.cos(angle), np.sin(angle)]) + 0.3 * rng.normal(size=n) > 0).astype(int)
return X, y
data = [month(m) for m in range(12)]
stack = lambda ks: (np.vstack([data[k][0] for k in ks]), np.concatenate([data[k][1] for k in ks]))
champion = LogisticRegression().fit(*stack(range(0, 6))) # deployed six months ago
challenger = LogisticRegression().fit(*stack(range(6, 11))) # retrained on recent months
X_eval, y_eval = data[11] # newest matured month, unseen by both
ok_champ = champion.predict(X_eval) == y_eval
ok_chall = challenger.predict(X_eval) == y_eval
diffs = []
for _ in range(2000): # paired bootstrap over the same rows
i = rng.integers(0, len(y_eval), len(y_eval))
diffs.append(ok_chall[i].mean() - ok_champ[i].mean())
lo, hi = np.percentile(diffs, [2.5, 97.5])
print(f"accuracy on month 11 (n={len(y_eval)}): champion {ok_champ.mean():.3f}, challenger {ok_chall.mean():.3f}")
print(f"difference {ok_chall.mean() - ok_champ.mean():+.3f}, 95% bootstrap interval [{lo:+.3f}, {hi:+.3f}]")
segments = {"x0 < 0": X_eval[:, 0] < 0, "x0 >= 0": X_eval[:, 0] >= 0}
seg_ok = True
for name, mask in segments.items():
d = ok_chall[mask].mean() - ok_champ[mask].mean()
seg_ok &= d > -0.02
print(f" segment {name:8s} n={int(mask.sum())}: champion {ok_champ[mask].mean():.3f}, "
f"challenger {ok_chall[mask].mean():.3f}")
promote = lo > 0.0 and seg_ok
print("decision:", "promote the challenger (to canary)" if promote else "keep the champion")accuracy on month 11 (n=1000): champion 0.829, challenger 0.894
difference +0.065, 95% bootstrap interval [+0.047, +0.083]
segment x0 < 0 n=476: champion 0.845, challenger 0.908
segment x0 >= 0 n=524: champion 0.815, challenger 0.882
decision: promote the challenger (to canary)
The challenger is better by 0.065 in accuracy on 1,000 rows from month 11, and the 95 % paired-bootstrap interval for the difference, [+0.047, +0.083], excludes zero. It is also better in both segments (0.908 against 0.845 for x0 < 0, 0.882 against 0.815 for x0 >= 0), so the rule says promote, to a canary first. The bootstrap resamples rows and evaluates both models on the same resampled rows; that pairing removes the noise the two share and gives a much tighter interval than comparing two separate confidence intervals.
Feedback loops
Retraining assumes that the new labels describe the world. Often they describe the world as changed by the model:
- A credit model rejects risky applicants, so only approved loans produce repayment labels. Retrained on them, the model never learns about the applicants it rejects, and if it once wrongly rejected a group, it never gets the data to correct itself (selective labels).
- A recommender shows items it predicts you will click; clicks on shown items become the training data; items it never shows never get clicks. Popular items get more popular (exposure bias).
- A fraud model blocks transactions, fraudsters adapt to whatever is not blocked, and the next training set contains only the fraud the model missed.
Countermeasures: keep a small random exploration share (approve or show a random sample regardless of the score, within the limits of the business and of fairness rules), log the propensity (the probability of the action) so that later training can reweight, evaluate on data from the exploration share, and document the loop in the model card.
The cost of retraining
Retraining is not free. Each run costs compute and data engineering; each new version needs validation, review, possibly a fairness and compliance check, and a rollout that can go wrong. Frequent retraining also makes behaviour harder to explain ("why did my score change?") and weakens the meaning of an audit ("which model decided this?"). Retrain as often as the measured gain is worth, automate the steps that are the same every time (continuous training), and keep the previous versions for rollback.
Pitfalls
- Promoting on the training metric or on a random split of the new data: compare on a later, untouched period.
- A trigger without hysteresis: a monitor near its threshold fires every day, and the system retrains daily on noise. Require the condition for several periods, or a minimum gap between runs.
- Retraining on corrupted data: if the alarm was a pipeline bug, retraining teaches the model the bug. Check data quality before retraining.
- Forgetting recurring patterns: a short sliding window drops last year's holiday season. Keep old versions, or add seasonal features.
- Ignoring the loop: with selective labels, offline metrics on logged data look better and better while the model is getting worse on the population it no longer sees.
Practice
- In the first example, why does "every 6 months" do so badly around month 14, and what does "triggered" need to react there?
- On the stable stream, which window wins and why? Would you expect the same with a real stable stream of only 100 rows per month?
- Change the promotion rule so that the challenger must also be at least 0.005 better on average. Would the decision in the example change?
Answers
- Its retraining months are 9, 15 and 21. The jump at month 14 is served by the model trained on months 6 to 8, and the retraining at month 15 uses months 12 to 14, two of which still follow the old boundary; the next fix only comes at month 21. "Triggered" only needs one month of matured labels with the error above its baseline: it can react at the start of month 15 and again at month 16 if the new model is still off. No policy can avoid month 14 itself, since its labels only exist at its end.
- On a stable stream all windows learn the same boundary; the expanding window has the most data and therefore the least noise in its estimate, but with 1,000 rows a month the differences are tiny (the printed errors differ only in the third or fourth decimal). With 100 rows a month the sliding window would have only 300 rows and its noise would show more clearly; the expanding window's advantage grows.
- No: the difference is +0.065 and even the lower end of the interval (+0.047) is far above 0.005. A margin matters when the improvement is real but small, where it keeps you from paying the rollout cost and risk for a negligible gain. Write it as "lower bound of the interval above 0.005" to make it strict.
Test yourself
Which retraining schedule reacts fastest to a sudden change that happens just after a scheduled run?
- Every 6 months
- Triggered by an error-rate monitor on matured labels
- Never retrain
- Yearly
When is an expanding window (all data so far) the best choice?
- When the concept drifts quickly
- When the concept is stable, so more data only reduces variance
- Never
- When labels are delayed
On which data should a challenger be compared with the champion?
- The challenger's training data
- A random split of all historical data
- Recent labelled data that neither model was trained on
- The champion's validation set from last year
A credit model is retrained only on loans it approved. What is the risk?
- Overfitting to rejected applicants
- Selective labels: it never sees outcomes for applicants it rejects, so its mistakes there are never corrected
- The model becomes too large
- Labels arrive faster