Skip to content
Français

When "normal" moves

  • Lesson 37
  • 40 min
  • Module 9: Run a detector in production

Where we are

Our detection job runs every day with a fixed baseline. Then a product launch moves normal for good, and the job floods the team with alerts. In this lesson, we add scheduled drift checks, watch the alert rate, and decide when to retrain and who approves a new threshold.

Lesson 37 of 38 · Anomaly Detection: Find What Is UnusualWhen "normal" moves
Course overview

What you will be able to do

Notice when “normal” has moved, and respond without flooding the team. You run a drift check on a schedule and watch the alert pressure. Then you retrain on a new window, and the person who owns the alerts approves it.

Before you startWhat to know and to have readyAbout 40 minutes

What you need to know

What you need on your computer

The project folder detection-job from the last lesson, with its virtual environment active, its model and its October alerts. Tested on macOS with Python 3.12.13. The PowerShell commands were not run.

Think of a café owner. For years, she knows her customers: the same thirty faces every morning. A stranger stands out, and once a stranger took a bag from a chair. So she watches strangers. Then a large office opens next door. On Monday, eighty new faces come in. They are all honest, and they will come back every day. If she treats every new face as a danger, she spends her whole morning watching, and she misses the one real thief.

What should she do? She should notice that the change is real and lasting, and learn the new faces. And someone, the owner herself, decides when “new” becomes “normal”.

The problem: the app launch floods the job

Section titled “The problem: the app launch floods the job”

Larkfield launched its app on 15 October 2025. About 60% of customers started to pay in the app, on a phone that the shop had never seen for them. You saw this in Kinds of anomalies. On average, 3.89% of the payments were on a new device in the month before the launch. In the month after, it was 20.68%. Then it fell slowly, to about 5% at the end of November, as the app phones became known devices.

The job’s model learned normal from 2 August to 30 September, before the app. For that model, “a new device” was rare and a strong sign of a stolen card. After the launch, thousands of honest customers have a new device.

The job has two ways to choose its alerts. The setting DETECT_POLICY chooses one:

  • budget (the default): every day, the 50 most unusual alert groups.
  • fixed: every alert group above one fixed threshold: the score that gave 50 alerts a day in the training days. This is the threshold that many first jobs use, because it is simple.

We replayed October and November with both policies and the same model, learned to 30 September:

  • Fixed threshold, old model
  • Fixed threshold, retrained
  • Budget: top 50
With the fixed threshold, the alerts a day go from 45.4 on average before the launch to 108.6 in the month after it. The budget sends 50 every day. After retraining, the fixed threshold sends 44.5 a day.
Text description of the chart

A line chart with one point a day from 1 October to 30 November 2025, and alerts sent a day from 0 to 160. The budget line is flat at 50, except 49 on 14 October. The fixed-threshold line with the old model is between 25 and 58 alerts a day before the launch, 45.4 on average from 1 to 14 October. From 15 October, the day of the app launch, it climbs to between 70 and 151, with 108.6 on average from 15 October to 14 November. Its highest day is 2 November, with 151 alerts. It stays high to the end of November, between 55 and 129. A third line starts on 8 November: the fixed threshold with the model retrained to 7 November. It is between 29 and 58 alerts a day, 44.5 on average, except 101 on Black Friday, 28 November.

With the fixed threshold, the alerts more than double: from 45.4 a day before the launch to 108.6 a day after it. On the worst day, 151 alerts arrive. And the extra alerts are not fraud. The share of alerts that hold a planted fraud fell from 0.079 to 0.033.

The budget policy looks fine: 50 alerts every day. Its precision of alerts hardly moved, from 0.072 to 0.070. But the budget hides the change. It still sends 50, so nobody sees in the count that normal moved. The job needs a signal that shows the pressure behind the budget.

A detector learns normal from a training window: a fixed period of days, here 60. When normal moves, the window is out of date. The job cannot know this from the alerts alone. So it watches three signals:

Two groups lead to a verdict. Every day, after the run: the inputs, the PSI of each feature for the last 7 days against the training days; and the pressure, customers a day above the training threshold. They lead to a question, the verdict: pressure above twice the budget on 3 of 7 days? If no: keep the model, and look at any feature with PSI 0.25 or more. If yes: retrain on the last 60 days. Then a person approves: Sofia signs off the new model. Every week: the results, the share of reviewed alerts that are real, which also goes to the person who approves.
The job checks the inputs and the pressure every day and gives a verdict. A person approves a new model, with the reviewed results of the week.
Text description of the diagram

The diagram has two groups on the left. The first group happens every day, after the run. It holds two signals. The first is the inputs: the PSI of each feature over the last 7 days, against the training days. The second is the pressure: the number of customers a day with a payment above the training threshold. Both lead to the verdict, a question: was the pressure above twice the budget on 3 of the last 7 days? If not, keep the model, and look at any feature with a PSI of 0.25 or more. If yes, retrain on the last 60 days. After retraining, a person approves: Sofia signs off the new model. The second group happens every week. It holds the third signal, the results: the share of reviewed alerts that are real. It goes to the person who approves.

  1. The inputs. For each feature, the job compares the last 7 days with the training days. It uses PSI from Module 3, with its usual limits: below 0.1 is no real change, above 0.25 is a large change. These limits are conventions, not laws.
  2. The pressure. Each day, the job counts the customers with a payment above the training threshold. In the training days, this was about 50 a day, the budget. It is about the number of alerts that the fixed threshold would send. With the budget policy, it shows what the budget hides.
  3. The results. The share of reviewed alerts that are real. This needs reviews, so it comes weekly, in the next lesson’s report.

The job’s verdict uses the first two. Suppose the pressure is above twice the budget (100) on 3 or more of the last 7 days. Then normal has moved, and the job asks for retraining. If only a feature moved and the pressure is normal, it says “look at the change”. This is the flow from Drift in many features: input drift alone is a reason to look, and a change in the outputs is a reason to check the results. Here the budget hides the results, and the reviews come only once a week. So the job treats a lasting rise in the pressure as the result.

new_device is 1 for a payment on a device that is new for the customer, else 0. For a 0/1 feature, the job’s PSI compares two shares. Here is a constructed example with round numbers: 4% new devices in the training days, 25% in the last week.

Training days Last 7 days current − reference ln(current / reference) Term
New device (1) 0.04 0.25 +0.21 ln(6.25) = 1.833 0.385
Known device (0) 0.96 0.75 −0.21 ln(0.781) = −0.247 0.052
PSI 0.437

Each term is (current − reference) × ln(current / reference). Both terms are positive, so they add up: 0.437, far above 0.25. The real check on 31 October found 0.472. In the old training window, 3.64% of the daily payments were on a new device, on average. In the last 7 days of October, it was 25.42%.

You run it now. First the day before the launch, then the end of October.

  1. In your project folder, check 14 October, the day before the launch:

    Terminal window
    python -m detect drift --day 2025-10-14
    Model iforest-2025-08-02-2025-09-30. PSI of the last 7 days against the training days:
    feature psi
    log_amount_vs_usual 0.011
    new_country 0.006
    new_device 0.006
    log_minutes_since_last 0.019
    payments_last_hour 0.000
    device_payments_last_hour 0.000
    night 0.001
    is_business 0.002
    amount 0.007
    Customers above the training threshold per day: 52, 50, 44, 57, 91, 42, 137
    No drift that matters: keep the model.
  2. Check 31 October, after two weeks of the app:

    Terminal window
    python -m detect drift --day 2025-10-31
    Model iforest-2025-08-02-2025-09-30. PSI of the last 7 days against the training days:
    feature psi
    log_amount_vs_usual 0.012
    new_country 0.000
    new_device 0.472
    log_minutes_since_last 0.033
    ...
    Customers above the training threshold per day: 182, 156, 145, 125, 115, 118, 129
    Normal has moved: on 7 of the last 7 days, more than twice the budget scored above the training threshold. Drift (PSI 0.25 or more): new_device. Retrain on recent days, then ask the fraud lead to approve the new model.

On 14 October, every PSI is below 0.02. The pressure was 137 on that day, but only on one day of seven, so the verdict is “keep the model”. One busy day is not a moved normal. (On 14 October, a few large card tests filled the top 200 payments. So only 49 groups existed, and the budget sent 49.)

On 31 October, one feature moved: new_device, PSI 0.472. And the pressure was above 100 on all 7 days, from 115 to 182. The verdict asks for retraining, and names the feature. The other features did not move: the customers still pay the same amounts, at the same hours, from the same countries.

The PSI of new_device is 0.472 at the end of October, against the old training days. Against the retrained model's days, it is 0.002 in mid-November and 0.058 at the end of November.
Text description of the chart

A column chart with four columns on an axis from 0 to 0.5. On 14 October, with the old model, the PSI of new_device is 0.006. On 31 October, with the old model, it is 0.472, far above the large-change limit of 0.25. On 14 November, with the model retrained to 7 November, it is 0.002. On 30 November, with the same retrained model, it is 0.058, below the limit of 0.1.

The verdict asks for retraining, but the job does not retrain by itself. Two questions come first.

Which window? The new window must hold enough of the new normal. On 31 October, the last 60 days hold only 17 days of the app. Priya waits one more week. She trains on the 60 days from 9 September to 7 November, with 24 days of the app. On average, 11.44% of the daily payments in this window were on a new device. A window also must not hold an incident that you do not want the model to learn. Module 3’s Drift in many features showed that risk: fraud bursts can drift too.

Who approves? A retrained model changes what Sofia’s team sees every day. So Sofia, who owns the alerts, approves it. The verdict says “ask the fraud lead to approve”. Priya brings her three numbers: the pressure before and after, the alerts a day with the fixed threshold, and the share of real alerts. The MLOps course has the full release step, with tests and limits, in Evaluation gates. It shows how to choose between retraining and other fixes in Retrain or revise.

  1. Retrain on the 60 days up to 7 November:

    Terminal window
    python -m detect train --until 2025-11-07
    Trained iforest-2025-09-09-2025-11-07 on 106,654 payments (2025-09-09 to 2025-11-07). Saved to state/model.pkl.
  2. Rerun 15 October with the new model. The day was sent already:

    Terminal window
    python -m detect run --day 2025-10-15
    2025-10-15: 1,710 payments, 41 customers above the training threshold, 114 alert groups, 0 snoozed. Sent 9 new alerts to alerts/2025-10-15.jsonl; 41 already sent.
  3. Check the drift with the new model, and replay one week:

    Terminal window
    python -m detect drift --day 2025-11-14
    python -m detect replay --from 2025-11-08 --to 2025-11-14

    The drift check ends with No drift that matters: keep the model. The pressure is between 32 and 56 a day. The replay ends with Sent 350 alerts in 7 days (50.0 a day, budget 50, policy budget).

Step 2 shows the ledger at work. The new model put 41 of the same groups in its top 50, and the job did not send them again. It found 9 other groups and sent them. No alert was sent twice. 15 October now has 59 alerts, above the budget. So the Your-turn change of the last lesson matters here too. In practice, a team does not rerun old days with a new model, except to test it.

The fixed policy shows the effect most clearly. Run it in its own folders, so that its alerts do not mix with the budget’s. The settings DETECT_STATE and DETECT_ALERTS choose the folders:

Terminal window
export DETECT_POLICY=fixed DETECT_STATE=state-fixed DETECT_ALERTS=alerts-fixed
python -m detect train --until 2025-09-30
python -m detect replay --from 2025-10-01 --to 2025-10-31
python -m detect train --until 2025-11-07
python -m detect replay --from 2025-11-08 --to 2025-11-30
unset DETECT_POLICY DETECT_STATE DETECT_ALERTS

The last lines of the two replays:

Sent 2571 alerts in 31 days (82.9 a day, budget 50, policy fixed).
Sent 1024 alerts in 23 days (44.5 a day, budget 50, policy fixed).

In October, the old model with the fixed threshold sent 82.9 alerts a day on average. That is about 33 more than the 50 it was made for, and after the launch it sent more than 100 a day. From 8 November, the retrained model sent 44.5 a day, close to the 50 that the threshold was made for. The course’s measurement gives the same picture for the budget policy. From 8 to 30 November, the pressure was 100.2 customers a day with the old model and 52.3 with the retrained one. So the pressure signal means something again.

Did the alerts get better? A little, with the fixed threshold. From 8 to 30 November, the share of real alerts was 0.030 with the old model and 0.058 with the retrained one. With the budget, it hardly changed (0.050 and 0.051). The budget protected the team from the flood, and retraining made the threshold and the pressure true again. Both matter.

Look at Black Friday in the chart: even the retrained fixed threshold sent 101 alerts on 28 November, with 5,216 payments that day. A fixed threshold always grows with the traffic. That is one more reason to keep the budget for the team.

The app wave did not stay. The new-device share fell back to about 5% at the end of November, because each app phone is new only once. The retrained model learned a window with 11.44% new devices. In the last 7 days of November, the average was 6.49%.

The share of payments on a new device rises from about 4% to between 20% and 30% after the launch, then falls back to about 5% at the end of November.
Text description of the chart

A line chart with one point a day from 1 October to 30 November 2025, on an axis from 0 to 35%. From 1 to 13 October, the share of payments on a new device is between 1.8% and 5.5%. It is 7.6% on 14 October and 10.6% on 15 October, the day of the app launch. It stays between 19% and 30.3% from 16 October to the end of October, with its highest point, 30.3%, on 21 October. In November, it falls slowly: about 19% in the first week, 14% in the second and 11% in the third. In the last five days, it is between 4.7% and 6.2%.

So the drift check runs again on 30 November, now against the retrained model:

new_device 0.058
...
Customers above the training threshold per day: 81, 37, 42, 53, 100, 58, 52
No drift that matters: keep the model.

The PSI is 0.058: a small move back, below 0.1. The pressure is normal, except 100 on Black Friday. So the model stays. The window will move again with the next retraining. Many teams retrain on a calendar, for example once a month, and keep the drift check as the guard between two retrainings.

The launch is a change point: a day when normal moves to a new level and stays. You met change points in Change points. Some are planned, such as a launch, a new region or a new payment method. Others arrive without warning, such as a partner’s new app version.

For planned change points, do not wait for the drift check. Write them in a shared calendar of changes, as Larkfield’s product team could have done for 15 October. Then the people who own the job can plan a retraining date before the launch. For unplanned ones, the scheduled drift check is the net. The MLOps course has a full lesson on this, Data and concept drift.

Check 21 October, one week after the launch, with the old model. Your project folder has the retrained model now, so train the old one again in a third folder, state-old. Before you run the check, predict: will the verdict be “retrain”? Then answer: why might retraining on that day be too early?

Show the answer

On macOS or Linux, run DETECT_STATE=state-old python -m detect train --until 2025-09-30, then DETECT_STATE=state-old python -m detect drift --day 2025-10-21. In PowerShell, set $env:DETECT_STATE = "state-old" first, and remove it afterwards. The check ends:

Customers above the training threshold per day: 76, 159, 106, 158, 123, 146, 136
Normal has moved: on 6 of the last 7 days, more than twice the budget scored above the training threshold. Drift (PSI 0.25 or more): new_device. Retrain on recent days, then ask the fraud lead to approve the new model.

The PSI of new_device is already 0.393, and the verdict is “retrain”. But a 60-day window up to 21 October holds only 7 days of the app. The model would learn the new normal from one week, during the wave’s fastest rise. Wait until the window holds a few weeks of the new behaviour, or train on a shorter window. Tell Sofia which one you chose and why.

Common mistake

The budget hides a moved normal

Symptom: after the launch, the job sends 50 alerts every day, as planned. Sofia notices nothing in the count. But her team finds fewer frauds among the alerts each week, and more honest customers with a new phone.

Cause: the budget always fills 50 places. When normal moves, honest payments push into the top 50, and the count stays the same. The pressure behind the budget rose from 54.9 to 119.6 customers a day above the training threshold. Nobody watched it.

Fix: run the drift check every day after the run, and report the pressure next to the alerts. When the verdict says “retrain”, retrain on a window with enough of the new normal, and let the alerts’ owner approve the new model.

Consequence in AI work: a steady alert count looks like a healthy detector. Without a signal behind the budget, a moved normal can stay hidden for weeks, while the alerts get worse.

Check your understanding

After the app launch, the fixed threshold sent 108.6 alerts a day and the budget sent 50. Which policy is better for Sofia's team, and what does the better one hide?

Show the answer

The budget is better for the team. It keeps the work at 50 alerts a day, while the fixed threshold sent up to 151 on one day. But the budget hides that normal moved. Its alert count stayed at 50, while the pressure behind it rose from 54.9 to 119.6 customers a day above the training threshold. So the job must report the pressure and run a drift check, or nobody sees the change.

Check your understanding

Compute the PSI of a 0/1 feature that is 1 for 5% of the training payments and for 20% of the last week's payments. Is it a large change?

Show the answer

The ones: (0.20 − 0.05) × ln(0.20 / 0.05) = 0.15 × ln(4) = 0.15 × 1.386 = 0.208. The zeros: (0.80 − 0.95) × ln(0.80 / 0.95) = −0.15 × (−0.172) = 0.026. PSI = 0.208 + 0.026 = 0.234. It is just below 0.25, a moderate change by the usual convention. Those limits are conventions: what matters is also the pressure, the second signal.

Check your understanding

On 31 October the drift check says “retrain”. Tomás wants a job that retrains itself every time this happens, with no person in the loop. Give two reasons against it.

Show the answer

First, the window matters. On 31 October, the last 60 days hold only 17 days of the app. A window can also hold a fraud burst that the model must not learn. A person chooses the window. Second, a new model changes what Sofia’s team sees every day. So the owner of the alerts must approve it. She compares the pressure, the alerts a day and the share of real alerts, before and after. A retrained model also needs a check before it goes live, as in the MLOps course’s evaluation gates.

Recap

  • After the app launch, the fixed threshold went from 45.4 to 108.6 alerts a day. The budget stayed at 50 and hid the change.
  • The job checks three signals: the inputs (PSI per feature) and the pressure (customers above the training threshold). Weekly, it adds the results (reviewed alerts that are real).
  • On 31 October, new_device had PSI 0.472 and the pressure was 115 to 182 a day: the verdict was “retrain”. The 60 days up to 7 November brought the pressure back to 52.3 and the fixed threshold to 44.5 alerts a day.
  • A person chooses the window and approves the new model. Planned change points go in a calendar; the drift check catches the others. Normal keeps moving: the new-device share fell back to about 5% at the end of November.

The job now keeps the budget and notices a moved normal. But 50 alerts a day can still be too many to read with care. Next, you look at alert fatigue: rate limits, snooze rules, a runbook and the weekly review.

Next: Alert fatigue and ownership