IT Vizag
← MLOps: Shipping ML Models
Loading video…

MLOps: Shipping ML Models · Lesson 2 of 14 · 2 min read · 5 min video

From notebook to project

Turn a messy notebook into a clean, testable Python project.

📄 Download slides (PDF)

Notebooks are great for exploring, but terrible for production. Hidden state, out-of-order cells and copy-pasted code make results impossible to trust. Step one is turning the notebook into a project.

A simple project layout

house-price/
├── data/               # raw and processed data (not in git)
├── src/
│   ├── data.py         # load and clean
│   ├── features.py     # build features
│   ├── train.py        # train and save the model
│   └── predict.py      # load the model and predict
├── tests/
├── params.yaml         # settings: paths, hyperparameters
├── requirements.txt
└── README.md

Move code into functions

Each notebook step becomes a function with clear inputs and outputs:

# src/features.py
import pandas as pd

def add_features(df: pd.DataFrame) -> pd.DataFrame:
    df = df.copy()
    df["age_years"] = 2026 - df["year_built"]
    df["price_per_sqft"] = df["price"] / df["sqft"]
    return df

Functions can be tested, reused by the training and serving code, and run in any order safely.

Settings out of the code

Put paths, the random seed and hyperparameters in params.yaml, not scattered through cells. Changing an experiment then means editing one file, and that file gets saved with the results.

Add a few tests

You don't need 100% coverage. Start with:

  • The feature function gives the expected columns for a tiny sample
  • Training runs end to end on 50 rows without crashing
  • Predictions stay within a sensible range

Keep notebooks for exploring

Keep using notebooks to explore, but have them import from src/, so there's only one copy of the real logic.

Tip: If you can't run the whole thing with one command, like python src/train.py, it isn't a project yet.

In one line

Turn notebooks into a project with functions in modules, settings in a config file, a few tests and one command that runs it all.

Saved on this device. Sign in to keep progress everywhere.

Share with a friend