9. Model Registry
Duration45minLearning Objectives
Apply:
[BC07] multiple model versions managed so that production code always points reliably at the current one, without hardcoding which version that is
[BC04] test-driven development to build a reusable model-registration tool
Analyze:
[BC07] comparing two candidate models on the same evidence to decide which one deserves to be promoted
Prerequisites
Introduction
Modules 6 and 7 gave you logged runs and a real Pipeline worth reusing — but neither tells calling code which logged version to actually use. Today that would mean hardcoding a run ID or a version number, and changing it by hand every time a better model comes along. This module adds the missing piece: a name calling code can always ask for (“give me the current model”), that you can repoint to a different version whenever you want, without touching any code that loads it.
Notebook
Files: notebooks/session3/09_model_registry.ipynb
Open it and select the same .venv kernel as your other notebooks. It is short and entirely self-contained — two unrelated toy models, no air_quality code needed until the “Now do it for real” section. Work through the cells in order:
- Register two toy models as two versions of the same registered model name
- See why MLflow’s old stage system is deprecated, and what replaces it: an alias
- Set an alias on one version, then load a model purely by name and alias — no run ID, no version number
- Move the alias to the other version, reload with the exact same call, and confirm the loaded model changed
- Once
scripts/register_champion.pyhas been run (see Implementation below), load the champion it promoted withair_quality.registry.load_champion("air_quality_model")
Implementation
Files: src/air_quality/registry.py, scripts/register_champion.py
- Open
src/air_quality/registry.py—register_pipeline,promote_to_championandload_championare already scaffolded, each wrapping exactly the calls you just made by hand in the notebook. Runuv run pytest tests/test_registry.py -vuntil it passes. - Complete the TODO in
scripts/register_champion.py: rebuild Module 7’s chainedPipeline(AirQualityCleaner+RFE+ a model) twice — once withLinearRegression, once withRidge— register both as versions ofair_quality_model, and promote whichever scores better oncross_val_scoretochampion. Run it withuv run python scripts/register_champion.py.
Reflection
Files: reflection/session_3/module_9.md
Details
Question:
- Which model ended up as
championin your own run,LinearRegressionorRidge? Does that match what you found in Module 7’s own reflection question? - If the code that loads this model for predictions hardcoded
models:/air_quality_model/2— a fixed version number — instead ofmodels:/air_quality_model@champion, what would break the next time a better model is registered? What does the alias indirection buy you that a version number alone does not?