
A machine-learning workflow is usually a sequence of steps: prepare data, train a model, and evaluate it. DVC pipelines describe those steps and their relationships.
Define a stage
A stage in dvc.yaml might look like this:
stages:
train:
cmd: python src/models/train.py
deps:
- data/processed/train.csv
- src/models/train.py
params:
- n_estimators
- max_depth
outs:
- models/model.pkl
metrics:
- metrics.json
This tells DVC:
cmd: the command to execute.deps: files the stage depends on.params: configuration values that affect the stage.outs: generated outputs.metrics: generated metric files that DVC can compare.
Notice that the training script is explicitly listed under deps. DVC does not infer every file dependency merely by inspecting the command.
Keep configuration outside the code
A params.yaml file can hold experiment settings:
n_estimators: 100
max_depth: 5
test_size: 0.2
Python can read them:
import yaml
with open("params.yaml") as f:
params = yaml.safe_load(f)
max_depth = params["max_depth"]
This makes it easier to change experiment settings without editing the training script.
Reproduce the pipeline
Run:
dvc repro
DVC checks whether dependencies, parameters, or relevant stage definitions have changed. It runs the stages that need to be reproduced.
The output files do not necessarily need to exist before the first run. The stage command is responsible for creating declared outputs.
Takeaway: dvc.yaml describes how the workflow runs, while params.yaml describes the values that configure it.
Comments
Join the discussionNo comments yet. Be the first to comment.




