Stop 12 · Model Deployment & MLOpsTopics · 4/8

Model Versioning

Part of the Data Science Roadmap

In short

Last month's model was better and nobody knows which data or settings made it. Versioning models, data and metrics together means you can always explain, compare and roll back.

Tracking which model version is deployed, what data and code produced it, and being able to roll back to a previous version — essential once models are updated regularly in production.

The mascot pulls an older folder out of a neat row of colour-coded folders on a shelf.

Think of it like this

Project report drafts

Everyone has a folder with report_final, report_final2 and report_REALLY_final. Nobody knows which one the teacher saw. Proper versioning is a neat shelf of numbered folders, each with a note on what changed, so you can pull out any old draft in seconds.

Watch it happen

What a model registry keeps

Model registry
churn-model
v1 (archived)
v2 (production)
v3 (staging)
Git commit
Data version
Params
Metrics

1/4A registry stores every trained version of each model under one name.

The big ideas

What you need to know

Code in Git

Training code and configs live in Git. Every model should point to the commit that trained it.

Data versions too

Same code with different data gives a different model. Tools like DVC version large data files.

Track experiments

MLflow and similar tools log parameters, metrics and the model file for every run.

Rollback ready

Keep older production versions available so you can switch back quickly if something breaks.

See it in code

Walk through the code

python
1import mlflow2import mlflow.sklearn3from sklearn.datasets import load_iris4from sklearn.linear_model import LogisticRegression5 6X, y = load_iris(return_X_y=True)7mlflow.set_experiment("iris")8 9with mlflow.start_run():10    model = LogisticRegression(C=0.5, max_iter=500).fit(X, y)11    mlflow.log_param("C", 0.5)12    mlflow.log_metric("train_acc", model.score(X, y))13    mlflow.sklearn.log_model(model, "model")

1/4Group runs under a named experiment.

Each run records its settings, score and model file. Run mlflow ui to browse and compare runs in your browser.

Save yourself the pain

Common mistakes

Oops

Naming files model_new.pkl and model_latest.pkl.

Do this instead

Use a tracking tool or a clear scheme with version, date and the Git commit.

Oops

Versioning the model but not the training data.

Do this instead

Record which data snapshot was used, so any version can be rebuilt and explained.

Your mission

Track five runs

~25 min

Quick check

A new model version performs badly in production. What does good versioning let you do?

Go deeper

  1. 1Explore a model versioning tool (e.g. MLflow) at a basic level.
  2. 2Learn what metadata is worth tracking alongside a model (training data version, hyperparameters, metrics).
  3. 3Practice a simple naming/tagging convention for your own project's model versions.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge