Skip to content
Tutorials Center
My learning

Topics

Lesson 5 of 41 ยท ML Lifecycle and Pipelines

The Machine Learning Lifecycle

Walk through every stage of the machine learning lifecycle (framing, data, training, evaluation, deployment, monitoring) and see how each stage produces versioned artifacts.

Every machine learning project moves through the same stages, whether it is a spam filter or a demand forecast. The stages are not a straight line: findings in one stage send you back to an earlier one. Naming them helps a team agree where a project is, what each stage must produce, and what can go wrong.

The key MLOps idea is that every stage should leave behind a versioned artifact: a dataset snapshot, a feature definition, a trained model, an evaluation report. If a stage leaves only a memory in someone's head, it cannot be repeated or audited.

The stages

Frame Define the problem and success.
Data Collect, label, validate.
Train Features, models, tuning.
Evaluate Test on held-out data.

Each stage outputs an artifact.

1 / 2

Stage 1: frame the problem

Before touching data, write down:

  • the business goal ("reduce late deliveries"),
  • the prediction task ("will this order be late, yes or no?"),
  • the metric that matches the goal ("recall of late orders at 90 percent precision"),
  • the baseline to beat (today's manual rule),
  • the constraints (latency, cost, fairness, privacy).

A baseline is cheap and powerful. If a one-line rule gets 91 percent and your model gets 92, the model may not be worth operating.

Stage 2: data

Collect data, label it, split it, and check its quality. The artifact is a versioned dataset with a schema. See data versioning and data validation.

Stage 3: training and tuning

Build features, try models, tune settings. The artifact is a trained model plus a run record (code version, data version, parameters, metrics). See experiment tracking.

Stage 4: evaluation

Evaluate on data the model never saw, and compare with the baseline and with the current production model. Evaluation is a gate: only a model that passes moves on.

Stage 5 to 7: package, deploy, monitor

Package the model with its environment (packaging), put it in a registry, deploy as batch or online service, and monitor quality, latency and drift. The next stage is often retraining, which restarts the loop.

A lifecycle as code

The stand-in below runs a miniature lifecycle. Each function is one stage, and each returns an artifact that the next one consumes. Notice the gate between evaluation and deployment.

Python A miniature lifecycle

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Batch versus online

How predictions are produced shapes every later decision.

Batch Online
When Scheduled (hourly, nightly) Per request
Latency Minutes to hours Milliseconds
Example Weekly churn scores Fraud check at checkout
Hard part Orchestration, big data Low-latency serving, scaling
Cost shape Spiky, cheap per row Always on

Choose batch whenever the business can wait; it is simpler to run and monitor.

Where iteration happens

flowchart TD
  F["Frame problem"] --> D["Prepare data"]
  D --> T["Train"]
  T --> E{"Passes gate?"}
  E -->|"no"| D
  E -->|"yes"| P["Package and deploy"]
  P --> M["Monitor"]
  M -->|"quality drops"| D

Failed gates and monitoring both send work back to the data stage.

Recording the artifacts

This example collects a small manifest of what each stage produced. Real systems store the same facts in a tracker and a registry.

Python A lifecycle manifest

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Write the baseline and the success metric down before training. It prevents moving the goalposts after you see the results.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What should each lifecycle stage leave behind?

    Artifacts make stages repeatable and auditable.
  2. 2. Why define a baseline early?

    If a simple rule performs nearly as well, a complex model may not justify its cost.
  3. 3. In the lifecycle, what is the evaluation gate?

    Only models that pass defined criteria are promoted.
  4. 4. When is batch prediction usually the better choice?

    Batch is simpler and cheaper to run when latency is not critical.

Summary

  • The lifecycle: frame, data, train, evaluate, package, deploy, monitor, retrain.
  • Each stage should output a versioned artifact.
  • Define the goal, metric and baseline before modeling.
  • Evaluation is a gate; failures and monitoring send you back to the data stage.
  • Prefer batch prediction unless the use case needs low latency.

Next: A Reproducible Training Script