AI Academy

Structured tracks from the basics to generative AI and agents, with sequential lessons and quizzes.

201lessons

MLOps: Deploying and Operating ML Models Beginner 13 minutes

Data Versioning and Validation

Git for code, DVC for large data, and validation schemas that stop corrupt data from reaching the model.

Your progress in the track0%

DVC in brief

pip install dvc
git init && dvc init
dvc add data/raw/images.zip          # creates data/raw/images.zip.dvc
git add data/raw/images.zip.dvc data/raw/.gitignore
git commit -m "Add raw images v1"
dvc remote add -d storage /path/to/remote/storage
dvc push

To go back to a previous version: git checkout <commit> then dvc checkout.

Validation with a schema

import pandas as pd
import pandera.pandas as pa      # in older versions: import pandera as pa
schema = pa.DataFrameSchema({
    "age": pa.Column(int, pa.Check.in_range(0, 120)),
    "sex": pa.Column(str, pa.Check.isin(["F", "M"])),
    "glucose": pa.Column(float, pa.Check.ge(0), nullable=True),
    "label": pa.Column(int, pa.Check.isin([0, 1]), nullable=False),
})
df = pd.read_csv("patients.csv")
schema.validate(df, lazy=True)      # collects all violations, then raises an exception

What must be checked

CategoryExamples
The architectureThe columns and types exist
ValuesThe range, and the allowed categories
CompletenessThe proportion missing is within acceptable limits
DistributionThe mean and variance are close to the reference
RepetitionNo duplicate rows, and no overlap between training and test

Documenting data

A short datasheet for each dataset: who collected it? When? How was it labelled? Which groups are under-represented? What uses are inappropriate?

Lesson terms

The data version
Saving specific, retrievable snapshots of datasets and linking them to the experiments that used them.
Data validation
Automated checking of data against explicit expectations about its structure and values before it is used.
Datasheet
A document describing the motivation for creating the dataset, its composition, how it was collected, its recommended uses and its limits.

Abstract

Data changes: corrected labels, added batches, or a modified source. Data versioning keeps a retrievable snapshot of every dataset that was used. DVC stores large data outside Git and keeps small files in Git that point to it by hash. Data validation enforces an expected schema (types, ranges, missing values and categories) and fails early on violations. Documenting data in datasheets records its source and limitations.

Review questions

  1. Why don't we put large data files directly in Git?

    Because Git is not designed for large binary files, so the repository grows and slows down, while DVC stores them in an external store with pointers in Git.

  2. What is an example of a useful validation rule?

    Age between 0 and 120, no missing values in the label column, and categories within a known set.

Sources and references

  1. DVC Documentation
  2. Pandera Documentation
  3. Gebru et al. — Datasheets for Datasets

Complete the lesson