AI Hints
Home›MLOps Tutorial›Capstone: Ship and Operate
MLOps · Lesson 63 of 80

Capstone: Operate

Monitor, drift, retrain.

⏱ 2 min read▶ Video at 2:35:09🎓 Free
Watch this lesson in the MLOps courseWatch on YouTube ↗Full MLOps course

Step six, and the most important. The model is live, and time passes. A week later, new data arrives, and the world has changed. Our job is to notice, automatically, to retrain, on fresh data, and let the gate decide. This closes the loop of the lifecycle, and it is the heart of M L Ops.

Capstone: Operate
From the video: Capstone: Operate
  • A week passes
  • Notice the change
  • Retrain, and let the gate decide

Detect drift, retrain, promote

This is the weekly check. We generate this week's data, and run the drift detector against the reference data. Tenure looks the same, but charges and calls have drifted, and the script exits with a failure code, which a scheduler treats as, retrain. So we retrain, as an experiment, with fresh, shifted data, by changing two parameters. The pipeline reruns the prepare, and train stages, and reports a new F one score. Then the gate compares it with the champion, and promotes it, as version two. In a real system, you would compare both models on the same fresh test set, to be fair. The loop is closed, automatically.

terminal
python src/incoming.py
wrote data/incoming.csv (this week's data)
python src/drift.py; echo "exit code: $?"
tenure   p-value 0.7094  ok
charges  p-value 0.0000  DRIFT
calls    p-value 0.0000  DRIFT
drift in ['charges', 'calls'] -> retrain
exit code: 1
dvc exp run -S prepare.seed=3 -S prepare.shifted=true 2>&1 | grep -E '^prepared|^f1'
prepared data/churn.csv, seed 3 shifted
f1 0.512
python src/promote.py 2>&1 | grep -E 'PROMOTED|REJECTED'
PROMOTED version 2: f1 0.512 beats 0.389
python -c "import mlflow; mlflow.set_tracking_uri('sqlite:///mlflow.db'); print('champion is version', mlflow.MlflowClient().get_model_version_by_alias('churn-model', 'champion').version)" 2>/dev/null
champion is version 2

What we built

Look back at what you built. A repository, with a clear layout. Versioned, validated data. A reproducible pipeline, with tracked experiments. Tests, and a registry with a quality gate. A container, an A P I, and Kubernetes manifests. A delivery pipeline. And a monitoring loop, that detects drift, retrains, and promotes. Every stage of the life cycle is there, and every stage is automated, and traceable. That is M L Ops, and you have now built it.

Data and pipelineversioned, validated, reproducible
Quality gatetests and the champion alias
Serving and deliverycontainer, Kubernetes, CI/CD
Monitoring loopdrift, retrain, promote

Summary

Congratulations. You built a complete M L Ops system, from data to monitoring. Every part was real, and every part is something you can reuse in your own projects. Next, a few quizzes to check what you remember, and your roadmap.

Key takeaways
  • Versioned data and pipeline
  • Tests and a quality gate
  • Serve, deliver, monitor, retrain
Next up: Quiz Time — test your knowledge