Single logo
  • Courses
  • Blog
  • About
Join for freeJoin free
Learning pathMonitor and Improve a Model in Production
  1. 1
    Monitoring Drift and Retraining: When a Model Gets Worse With No Code Change
  2. 2
    Drift Detection in Code: PSI Bin by Bin, the KS Test, Evidently and a Measured Threshold
  3. 3
    Shadow, Canary and Rollback: Releasing a New Model Without Betting Everything on It
  4. 4
    A/B Tests for Models: Did the New Model Make Things Better for People?
  5. 5
    When Labels Arrive Weeks Late: What to Watch Before You Can Grade the Model
  6. 6
    Retraining Triggers: Schedule, Drift and Performance, Wired to One Retrain Pipeline
  7. 7
    The User Feedback Loop: Why Thumbs Up Isn't the Truth, and What a Small Random Review Adds
  8. 8
    Debugging a Model in Production: A Four-Step Runbook, Cheap Checks First
  1. Blog
  2. /
  3. Machine Learning
  4. /
  5. MLOps and Production ML

Learning path: Monitor and Improve a Model in Production · Step 6 of 8

Retraining Triggers: Schedule, Drift and Performance, Wired to One Retrain Pipeline

When should a model be retrained? A schedule, drift and a performance floor run side by side for twelve simulated churn weeks, each feeding the same retrain function and gate. Drift fires three times for no gain and misses the week the rule changes.

Chaand Sheikh

·27 November 2026Monitoring and Release

What you will learn

  • Name the three retraining triggers and the question each one asks
  • Run all three side by side over twelve simulated weeks and see each fire when the others stay quiet
  • Wire a trigger to a retrain function that trains a candidate and runs a gate
  • Explain why a trigger only requests a retrain and the gate decides what ships

Before you start

  • Drift Detection in Code
  • CI/CD for ML: A Quality Gate

When should a model get retrained? There are three common answers: on a schedule, when drift shows up, and when performance drops. Here we run all three side by side over twelve simulated weeks and wire them into one retrain pipeline, with a gate that decides if the new model ships.

Servicing a car

Think about when you take your car in for a service.

  • By mileage. Every 10,000 km, whatever's going on. Simple, and sometimes a waste.
  • By warning light. A sensor spots something odd and the light comes on. It can come on while the car drives perfectly well.
  • By how it drives. It pulls to one side, the brakes feel soft. The most direct sign, but by then something's already wrong.

And the garage is a separate step. Any of the three gets the car in the door. None of them says the repair was any good.

Three triggers, three questions

Here are the same three for a churn model, on synthetic data:

TriggerQuestionCarOur rule
ScheduleHas it been long enough?MileageEvery 6 weeks
DriftDo the inputs look different?Warning lightPSI on spend above 0.2
PerformanceAre the answers getting worse?How it drivesAUC below 0.70 (illustrative floor)

Each one can fire while the others stay quiet. Let's see that happen. (PSI is explained in Drift Detection in Code; AUC in ROC and AUC.)

The triggers in code

triggers.py is a small simulation with fixed seeds. make_week builds one week of customers with tenure, spend and support calls:

import numpy as np
import pandas as pd
from checks import psi
from data import auc, fit
from gate import drift_policy, run_gates

EVERY = 6        # schedule: every 6 weeks
FLOOR = 0.70     # performance floor, illustrative
SPEND_UP = 5     # from week 5 customers spend more
RULE_CHANGE = 9  # from week 9 calls mean less churn


def make_week(week, n, seed):
    rng = np.random.default_rng(seed)
    tenure = rng.integers(1, 61, n)
    mean = 85 if week >= SPEND_UP else 60
    spend = rng.normal(mean, 20, n).clip(5, 200)
    calls = rng.poisson(2, n)
    c = -0.5 if week >= RULE_CHANGE else 0.5
    z = (-0.04 * (tenure - 24) + 0.03 * (spend - 60)
         + c * (calls - 2) - 0.4)
    y = rng.random(n) < 1 / (1 + np.exp(-z))
    return pd.DataFrame({
        "tenure": tenure, "spend_usd": spend,
        "calls": calls, "feature_version": "v1",
        "churn": y.astype(int)})

Two changes are planted:

  • From week 5, customers spend more (mean 85 instead of 60). Same rule for who leaves, just different inputs.
  • From week 9, the rule itself changes. Calls now mean less churn, not more, and the inputs look exactly the same.

The model is a scaled logistic regression (fit in data.py). Each week the loop checks all three triggers:

ref = make_week(0, 4000, seed=0)
current = fit(ref)
ref_spend = ref["spend_usd"]
history = []
print("week psi  auc   fired             cand  promote")
for week in range(1, 13):
    history.append(make_week(week, 500, 100 + week))
    test = make_week(week, 1000, 200 + week)
    d = psi(ref_spend, test["spend_usd"])
    a = auc(current, test)
    fired = []
    if week % EVERY == 0:
        fired.append("schedule")
    if drift_policy(d) == "train candidate":
        fired.append("drift")
    if a < FLOOR:
        fired.append("performance")
    cand_auc, promote = "-", "-"
    if fired:
        cand, window, r = retrain(history, current, test)
        cand_auc = round(r["cand_auc"], 3)
        promote = r["promote"]
        if promote:
            current = cand
            ref_spend = window["spend_usd"]
    print(week, round(d, 2), round(a, 3),
          "+".join(fired) or "-", cand_auc, promote)

week % EVERY is the schedule. drift_policy is the drift check. a < FLOOR is performance. Whichever fire go into the fired list, and that list is all a trigger produces. It's a request, nothing more.

Wiring a trigger to the pipeline

What happens to that request? retrain is a small stand-in for a full training pipeline (A Training Pipeline as a DAG) and its quality gate (CI/CD for ML: A Quality Gate):

def retrain(history, current, test):
    window = pd.concat(history[-3:])
    cand = fit(window)
    return cand, window, run_gates(
        cand, current, window, test)

It takes a window, the last three weeks of labelled rows, and fits a candidate on it. run_gates in gate.py then compares candidate and current model on this week's test batch, so both are judged on the same fresh rows:

from checks import check_features, check_input
from data import FEATURE_VERSION, auc

MAX_DROP = 0.005


def run_gates(cand, current, train_df, holdout):
    cand_auc = auc(cand, holdout)
    cur_auc = auc(current, holdout)
    short = holdout[holdout["tenure"] <= 12]
    problems = check_input(train_df) + check_features(
        train_df, FEATURE_VERSION)
    s_new, s_cur = auc(cand, short), auc(current, short)
    gates = {
        "data valid": not problems,
        "auc ok": cand_auc >= cur_auc - MAX_DROP,
        "slice ok": s_new >= s_cur - 0.02,
    }
    return {"gates": gates, "cand_auc": cand_auc,
            "cur_auc": cur_auc,
            "promote": all(gates.values())}


def drift_policy(psi_value, limit=0.2):
    """Drift asks for a candidate, never promotes."""
    if psi_value > limit:
        return "train candidate"
    return "wait"

Three gates: the training data is valid, overall AUC didn't drop by more than 0.005, and AUC on the short-tenure slice (tenure <= 12) didn't drop by more than 0.02 (see Slice Evaluation). If promote is true, the candidate becomes current and its window becomes the new drift reference. If not, the current model stays.

Twelve weeks, side by side

week psi  auc   fired             cand  promote
1 0.01 0.761 - - -
2 0.02 0.783 - - -
3 0.01 0.754 - - -
4 0.02 0.772 - - -
5 1.36 0.752 drift 0.753 True
6 0.56 0.747 schedule+drift 0.747 True
7 0.28 0.773 drift 0.773 True
8 0.01 0.757 - - -
9 0.03 0.569 performance 0.668 True
10 0.02 0.692 performance 0.76 True
11 0.01 0.735 - - -
12 0.01 0.717 schedule 0.742 True
Current model AUC per week, and which trigger fired 0.5 0.6 0.7 0.8 floor 0.70 0.569 1 2 3 4 5 6 7 8 9 10 11 12 fired D S+D D P P S week (S = schedule, D = drift, P = performance)
Simulated churn weeks. Drift fires in weeks 5-7 while AUC is fine; in week 9 AUC falls and drift stays silent.

Weeks 5 to 7: the light is on

Weeks 1-4 are quiet. In week 5 spend goes up: PSI jumps to 1.36 and drift fires. But the current model's AUC is 0.752. It's fine. The candidate gets 0.753: no real change, but it passes, so it's promoted.

In weeks 6 and 7 drift fires again, because the reference is still catching up. Same story: 0.747 against 0.747, then 0.773 against 0.773. Three retrains and basically nothing gained. The inputs moved, but the rule stayed the same. The warning light was on, and the car drove fine.

Week 9: drift stays quiet

Now the rule changes. PSI is 0.03. Drift says nothing at all, because the inputs didn't move. And AUC has dropped to 0.569, so performance fires. The candidate gets 0.668: better, but only a third of its window has the new rule in it.

In week 10 AUC is 0.692, still under the floor. It fires again, and now the candidate reaches 0.76.

In week 12 the schedule fires with nothing else on, and AUC goes from 0.717 to 0.742. So that blind trigger found something here, while in week 6 it found nothing.

One honest note: this simulation knows its labels in the same week. With late labels the performance trigger fires later, and that's its big weakness (When Labels Arrive Weeks Late).

The gate still decides

Six retrains, and all six got promoted. So does the gate do anything? Those windows were all clean data, so there was nothing to stop. Here's a window that isn't clean, from incident.py: 3,000 good rows plus 1,000 rows with spend recorded in cents. Excerpt from its output:

psi spend 8.28 -> train candidate
raw window gates {'data valid': False, 'auc ok': False, 'slice ok': False}
raw candidate auc 0.738
promote False

PSI on spend is 8.28, so drift asks for a candidate. The candidate scores 0.738 against the current model's 0.775. Every gate is false, so promote is false. A trigger only opens the door. The gate decides what walks through. (How to trace an incident like this one step by step is in Debugging a Model in Production.)

Common mistakes

  • Letting a trigger promote. drift_policy returns "train candidate", never "deploy". Every request goes through the same gate.
  • Relying on drift alone. It fired three times for almost no gain and stayed silent when the rule changed.
  • Relying on performance alone. It's the direct signal, but it needs labels, and labels are often late.
  • Training the candidate on a window that hasn't caught up. In week 9 only a third of the window had the new rule, so the first fix was partial.

Recap

TriggerStrengthWeakness, seen here
ScheduleSimple safety netBlind: wasted in week 6, useful in week 12
DriftEarly, needs no labels3 retrains for no gain; silent at the rule change
PerformanceDirectLate, and needs labels
GateDecides what shipsBlocked the cents window: promote False

Use more than one trigger, send them all into the same pipeline, and let the same gate decide.

Try it yourself

Set EVERY to 4 in triggers.py, run it again, and count how many retrains actually gained anything.

Built this? Share your solution in the StudyEasy AI Community.

Join free on Skool →
← Previous
When Labels Arrive Weeks Late: What to Watch Before You Can Grade the Model
Next →
The User Feedback Loop: Why Thumbs Up Isn't the Truth, and What a Small Random Review Adds
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool
Go deeper with a course

Machine Learning Engineer: From First Model to ML Engineer

Learn machine learning in Python, then ship it: data analysis, regression, classification, tuning, deployment and MLOps.View on Udemy ↗: Machine Learning Engineer: From First Model to ML Engineer (opens in a new tab)

Related articles
Python Virtual Environments: One Project, One Toolbox

Why every Python project gets its own virtual environment: two projects that need different versions of requests, python -m venv .venv, activation, pip install and the PyCharm setting that activates it for you.

Git and GitHub Fundamentals: Commits, Branches, Push and Pull

The Git you use every day, on a tiny hello-ml project: commits as save points, the staging area, a branch merged with a fast-forward, then push, clone, pull and pull requests with a teammate.

Testing a FastAPI App with pytest: Three Small Tests

A tiny FastAPI app with a Hello World route and a name route that refuses numbers, three pytest tests that check it, and what happens when the validation is deleted by mistake.

Config and Logging Instead of Hard-Coded Values in ML Training

Take the hard-coded values out of a car price training script: one config.toml read with tomllib, logging with levels and a run id on every line, and secrets read from the environment. Same RMSE, 2195, before and after.

On this page
  • Servicing a car
  • Three triggers, three questions
  • The triggers in code
  • Wiring a trigger to the pipeline
  • Twelve weeks, side by side
  • Weeks 5 to 7: the light is on
  • Week 9: drift stays quiet
  • The gate still decides
  • Common mistakes
  • Recap
  • Try it yourself
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool
Go deeper with a course

Machine Learning Engineer: From First Model to ML Engineer

Learn machine learning in Python, then ship it: data analysis, regression, classification, tuning, deployment and MLOps.View on Udemy ↗: Machine Learning Engineer: From First Model to ML Engineer (opens in a new tab)

Single logo

Empowering Education, One Course at a Time

About
About usContact usFAQs
Legal
Terms of ServicePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.