Stage 5 track
Track B: ML Engineer & MLOps
Goal: Run models reliably in production: packaged, versioned, served, monitored, retrained. Builds on: Stage 2 (the churn pipeline becomes your capstone's model).
What you learn
- Packaging models — save the fitted pipeline with metadata (versions, features, metrics); treat model + metadata as one immutable, versioned artifact. Never load pickle/joblib files from untrusted sources — unpickling can execute code.
- Experiment tracking — MLflow or Weights & Biases: every run's parameters, metrics and artifacts recorded, so "which settings got 0.81?" always has an answer (Part 8's reproducibility, with tooling).
- Serving models — batch scoring (nightly lists) vs real-time APIs (Track A's FastAPI pattern); choose by how fresh predictions must be.
- Containers — Docker freezes the OS layer the venv can't; the same image runs on your laptop and the cluster.
- Monitoring — data drift, prediction drift, and (when labels arrive) performance decay. Alert on inputs, not just uptime.
- Retraining pipelines — schedules or drift triggers, with a validation gate: a new model ships only if it beats the incumbent on the held-out set.
- CI/CD for ML — test the data (schema, ranges), the code, and the model (minimum metrics) before deploy.
Executed examples
Both ran in this repo; outputs are from those runs.
Save a model with metadata, reload it, verify (examples-track-b/01):
files: ['meta.json', 'model.joblib']
metadata: {'version': 'v1', 'sklearn': '1.9.1', 'features': 64, 'train_accuracy': 1.0}
predictions identical: True
Detect data drift with a KS test and PSI (examples-track-b/02) — live charges shifted from mean 70 to 85:
no drift KS p-value=0.1996 PSI=0.007
shifted KS p-value=0.0000 PSI=0.388
A common rule of thumb treats PSI above 0.25 as a significant shift — the shifted stream screams, the healthy one stays quiet.
Capstone: Churn Model in Production
- Core — a versioned model served by an API in a Docker container.
- Stretch — drift monitoring with PSI and alerts.
- Production — a scheduled retraining pipeline with a validation gate that blocks worse models.
Read more: scikit-learn: common pitfalls