Learning path: Monitor and Improve a Model in Production · Step 5 of 8
When Labels Arrive Weeks Late: What to Watch Before You Can Grade the Model
The drift alarm rings in week 3, and 0 of 200 tickets have an answer yet. How to join only the labels that have arrived, what to watch while you wait, and a short plan for grading late.
What you will learn
- Explain why many models can't be graded until weeks after they predict
- Join only the labels that had arrived by a given day, so you never grade the past with future answers
- Name what to watch meanwhile: drift, fast hints from people, and a small rollout
- Plan late grading: know the wait, log every prediction with an ID, mark part-filled weeks
Before you start
- Drift Detection in Code
- Joining tables with pandas merge
This one is short, and it has one point. You can't grade a model until the answers arrive, and for a lot of models those answers come weeks later.
Think about planting a fruit tree. This month all you can see is the leaves: are they green, are there enough of them? The fruit, the thing you planted it for, shows up much later. Models are the same. Was that payment fraud? Will this customer leave? Will this loan be repaid? The truth takes weeks, or longer. So you judge by the leaves for now, and you grade on the fruit.
The week of the alarm: 0 of 200
Back to our ticket priority project, with six weeks of synthetic tickets, 200 a week. The true answer is the priority the support agent finally chose, and it arrives one to three weeks after the ticket. Each row in labels.csv carries a label_week: the week that answer arrived.
In week 3 our drift alarm rings (Drift Detection in Code), so naturally you ask: how's the model doing? We run 02_late_labels.py with today set to week 3.
week 3 alert, labelled: 0 of 200
On that day, week 1 has 145 answers and week 2 has 48. Week 3, the week we care about, has zero of 200. So the only honest answer is: we don't know yet.
Only join what has arrived
How do we keep ourselves honest in code? Here's known_by in monitor.py:
def known_by(log, labels, today):
arrived = labels[labels.label_week <= today]
joined = log.merge(arrived, on="ticket_id")
high = joined.priority == "high"
joined["true"] = high.astype(int)
return joined
The first line keeps only the labels whose label_week is today or earlier. Answers from the future are dropped. Then merge joins what's left to the prediction log by ticket_id.
So if the code pretends it's week 3, it can only see what you'd have had in week 3. That stops you from grading the past with answers you didn't have yet, the same idea as point-in-time joins for features (Point-in-Time Correctness).
Here is the whole of 02_late_labels.py. It asks the week 3 question, then asks again from week 6 with a standard error per week:
import numpy as np
import pandas as pd
from monitor import DATA, known_by, load_log
log = load_log()
labels = pd.read_csv(DATA / "labels.csv")
alert = known_by(log, labels, today=3)
got = int((alert.week == 3).sum())
print("week 3 alert, labelled:", got,
"of", int((log.week == 3).sum()))
done = known_by(log, labels, today=6)
done["hit"] = (done.pred == done.true).astype(int)
print("week labelled accuracy se")
for week in range(1, 7):
g = done[done.week == week]
if len(g) == 0:
print(week, "0 of 200 - no answers yet")
continue
acc = g.hit.mean()
se = np.sqrt(acc * (1 - acc) / len(g))
print(week, f"{len(g):>3}",
round(acc, 3), round(se, 3))
before = done[done.week <= 2].hit
after = done[done.week >= 3].hit
print("weeks 1-2:", round(before.mean(), 3),
"weeks 3-6:", round(after.mean(), 3))
week 3 alert, labelled: 0 of 200
week labelled accuracy se
1 200 0.625 0.034
2 200 0.58 0.035
3 200 0.6 0.035
4 146 0.637 0.04
5 78 0.667 0.053
6 0 of 200 - no answers yet
weeks 1-2: 0.602 weeks 3-6: 0.625
Meanwhile, watch the leaves
So what do you watch while you wait?
- The inputs and the scores. They need no answers at all. Our drift column told us about week 3 in week 3.
- A faster hint from people.
03_feedback.pysimulates agent thumbs. Only 40% of tickets get rated, and the thumbs-up share comes to 0.639 next to a true accuracy of 0.625. Close here, but we simulated these, so don't take that as a promise. Why it can mislead is in The User Feedback Loop. - Limit the damage. A small rollout means fewer people depend on a model you can't grade yet (Shadow, Canary and Rollback).
These are all leaves. They tell you where to look. They don't give you the grade.
A plan for grading late
- Know your wait. For us, three weeks until a week is complete.
- Log every prediction with its ID, and write "unknown" until the answer comes.
- Mark part-filled weeks. At week 6, weeks 1-3 are full, week 4 has 146, week 5 has 78 and week 6 has none. Part-filled weeks may not be a fair sample, so don't compare them as if they were. Notice how the standard error grows as the count shrinks: 0.034 at 200 answers, 0.053 at 78.
- Then compare. Weeks 1-2: 0.602. Weeks 3-6: 0.625. No drop, and it took until week 6 to say so.
Common mistakes
- Joining all labels, whenever they arrived. You then grade the past with answers you didn't have on that day.
- Reading a part-filled week as a full one. The 78 labels of week 5 are only the ones that came back first, so they may not be a fair sample of that week.
- Calling a hint a grade. Drift and thumbs say where to look. Only arrived labels grade the model.
Recap
| Idea | On our tickets |
|---|---|
| The fruit (the grade) | Needs answers; week 3 had 0 of 200 when the alarm rang |
| The leaves (meanwhile) | Drift, simulated thumbs, a small rollout |
| Honest join | known_by keeps label_week <= today |
| Late grade | Weeks 1-2: 0.602, weeks 3-6: 0.625, no drop |
Try it yourself
In 02_late_labels.py, change today=6 to today=4 for the second check, and see what you could have said back then.
Built this? Share your solution in the StudyEasy AI Community.
Join free on Skool →A/B Tests for Models: Did the New Model Make Things Better for People?
Next →Retraining Triggers: Schedule, Drift and Performance, Wired to One Retrain Pipeline
StudyEasy AI Community
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
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.