Sub topic 2
The machine learning lifecycle at a glance
Prerequisites and scope
This chapter assumes you can train and evaluate a supervised model in Python and use Git and the command line. It also assumes you know roughly how a web service is deployed. It gives you a map of the whole lifecycle. Later chapters cover each stage in detail, so here the goal is to name the stages, say what each one produces, and show how they connect.
Why a lifecycle view helps
A notebook that trains a model is one step in a longer chain. Before training, someone must decide what to predict and collect data. After training, someone must release the model, serve it and watch it. The model's quality can change after release even though no code changed. This is why teams describe machine learning work as a loop, not a straight line.
The lifecycle is a shared vocabulary. When a team says "the problem is in the data stage" or "this belongs to deployment", everyone knows which artifacts and checks are involved.
The stages and their artifacts
Each stage takes inputs and produces artifacts. An artifact is a stored output that later stages depend on, such as a dataset snapshot or a trained model file.
| Stage | Main question | Typical artifacts |
|---|---|---|
| Problem framing | What decision are we improving, and how will we measure success? | Problem statement, success metrics, baseline |
| Data management | Do we have data we can trust and re-obtain? | Versioned datasets, validation reports, schemas |
| Feature engineering | How do raw values become model inputs? | Feature definitions, transformation code |
| Training and tracking | Which configuration gives the best model? | Run records with parameters, metrics, model files |
| Evaluation | Is the model good enough to release? | Evaluation report, release decision |
| Registry and release | Which exact model version is approved? | Registered model version, stage label |
| Deployment and serving | How do predictions reach users or systems? | Service, batch job, rollout configuration |
| Monitoring | Is the model still working in production? | Dashboards, alerts, logged predictions |
| Retraining | When and how do we replace the model? | New candidate model, trigger rules |
Governance and team roles apply to every row. They are not separate stages. Governance covers lineage (which data and code produced which model) and compliance. Team roles describe who owns each handoff.
The lifecycle as a loop
The stages form two nested loops. The inner loop is experimentation: change features or settings, train, evaluate, repeat. It runs many times per day and happens mostly before release. The outer loop is operational: release, monitor, detect a problem, retrain, release again. It runs over weeks or months and continues for as long as the model is in use.
Two details matter here. First, evaluation has two exits: back to feature work, or forward to the registry. The release criteria decide which. Second, monitoring does not end the process. Its findings feed retraining, which re-enters the pipeline at the data stage.
Following one run through the stages
Suppose a team builds a model that predicts which support tickets need urgent handling.
- Framing. The team decides success means catching urgent tickets without flooding agents with false alarms. They pick recall at a fixed precision as the metric and set a baseline from the current keyword rules.
- Data. They export the last 12 months of tickets, check the schema and label rates, and save a dated snapshot.
- Features. They turn ticket text and metadata into numeric inputs. The same transformation code must run later in production.
- Training. They run many experiments and record each configuration and score.
- Evaluation. They compare the best candidate with the baseline on held-out data.
- Registry. They register the winner as a new model version.
- Deployment. They serve it behind an API, first to a small share of traffic.
- Monitoring. They track input distributions, prediction rates and, when labels arrive, accuracy.
- Retraining. When the input mix shifts after a product launch, a trigger starts a new training run.
Every step produced something the next step needed. If step 2 saved no snapshot, step 4 could not be repeated exactly. That dependency is the reason the stages are listed with artifacts.
What one tracked run looks like
The training stage is where the lifecycle first becomes concrete in code. The example below records the parameters, the random seed and the test accuracy of one run. The record lets someone compare this run with others and repeat it later.
import mlflow
from sklearn.datasets import load_iris
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
SEED = 42
C = 1.0
X, y = load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=SEED
)
with mlflow.start_run():
model = LogisticRegression(C=C, max_iter=200).fit(X_train, y_train)
accuracy = accuracy_score(y_test, model.predict(X_test))
mlflow.log_param("C", C)
mlflow.log_param("seed", SEED)
mlflow.log_metric("accuracy", accuracy)This script covers only part of the lifecycle. It does not version the data, store the model, or say whether the accuracy is good enough to release. Those gaps map to the data, registry and evaluation stages.
How the lifecycle differs from a software lifecycle
Ordinary software changes only when its code changes. A machine learning system has three inputs that can change: code, data and the model that results from them. A fourth factor, the world the data describes, can also change without any action by your team.
- Data is an input to the build. A new data snapshot can change model behavior with identical code.
- Quality is statistical. Tests pass or fail, but model quality is a number that moves within a range. You need thresholds, not only assertions.
- Failure can be silent. A model that drifts still returns predictions with no error. Only monitoring reveals the decay.
- Stages are coupled. A change in feature code affects training, evaluation and serving at once.
Common errors when mapping work to the lifecycle
- Treating deployment as the end. Teams budget for training and release and nothing for monitoring or retraining. The model then decays unnoticed.
- Skipping framing. Without a business metric and a baseline, a model can improve its offline score and still not help anyone.
- Keeping artifacts only in notebooks. If the dataset, feature code and parameters are not stored, the run cannot be reproduced.
- Different feature code in training and serving. The model receives inputs in production that differ from those it learned on. This is a frequent cause of poor live performance.
- Evaluating on data the model has seen. Leakage between training and test sets makes the release decision meaningless.
- Treating the loop as linear. Real projects return to earlier stages often. Plan for it.
Where this chapter leads
The remaining chapters take each stage in turn. Data versioning and reproducibility come first, because everything later depends on them. Tracking, evaluation and the registry follow. Then come pipelines, CI/CD, deployment, monitoring, drift and retraining. The final chapters cover governance, roles and maturity levels.
Exercise
A team deploys a fraud model and sees accuracy fall over four months, though nobody changed the code. Which two lifecycle stages should have caught or handled this, and what artifact or trigger does each need?
Show answer
Monitoring should have caught it. It needs logged predictions, input-distribution tracking and, once labels arrive, a live accuracy metric with an alert threshold. Retraining should have handled it. It needs a trigger rule, such as a drift alert or a metric drop, plus versioned data and a pipeline that can produce and evaluate a new candidate model for release through the registry.
Exercise
In the tracked-run example, name one lifecycle stage the script does not cover, and say what you would add to cover it.
Show answer
It does not version the data. The example loads a built-in dataset, so this is hidden, but with real data you would store a dataset snapshot or hash and log its identifier as a parameter. Other acceptable answers: no release criteria are applied (add a threshold check on accuracy against a baseline), or the model is not saved (log the model and register it).