Machine Learning (ML) · Advanced level

Advanced level · Module 4: Deploying Machine Learning Models · Lesson 1 of 4

Saving Models Reproducibly

Save trained pipelines and record everything needed to load and trust them later.

In this lesson you will

  • Save and load pipelines with joblib
  • Pin dependencies and record model metadata

Key concepts

joblibdependency pinningrandom seedsmodel metadata

The lesson

Save the whole pipeline, not just the model, so new data is processed identically: joblib.dump(pipeline, "price_model.joblib").

A saved model only loads reliably with compatible library versions. Record exact versions in requirements.txt or a lock file, and the Python version used.

Store metadata beside the model: training data version, date, metrics, features expected and the code commit. Without it, nobody can say which model is running or why it behaves as it does.

Step by step

  1. Save the trained pipeline with joblib.
  2. Write a pinned requirements file.
  3. Save a metadata JSON file next to the model.
  4. Load the model in a fresh environment and predict.

Practice activity

Package the price model with its requirements and metadata so a classmate can load it.

Expected result: A classmate loads the model in a new environment and gets identical predictions.

Check your understanding

  1. Why save the whole pipeline?

    Show answer

    So new data goes through exactly the same preprocessing as training data.

  2. Why pin library versions?

    Show answer

    Saved models may not load or may behave differently with other versions.

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.