Evaluation: Metrics and plots in DVC

Introduction to Data Versioning with DVC

Ravi Bhadauria

Machine Learning Engineer

Metrics: changes in dvc.yaml

  • Configure DVC YAML file to track metrics across experiments
  • Change from outs
stages:
  train_and_evaluate:
    outs:
    - metrics.json
    - plots.png

$$ $$

  • To metrics
stages:
  train_and_evaluate:
    outs:
    - plots.png
    metrics:
      - metrics.json:
        cache: false
Introduction to Data Versioning with DVC

Printing DVC metrics

$ dvc metrics show
Path          accuracy    f1_score    precision    recall             
metrics.json  0.947       0.8656      0.988        0.7702
Introduction to Data Versioning with DVC

Compare metrics across runs

  • Change a hyperparameter and rerun dvc repro
$ dvc metrics diff
Path          Metric     HEAD    workspace    Change                  
metrics.json  accuracy   0.947   0.9995       0.0525
metrics.json  f1_score   0.8656  0.9989       0.1333
metrics.json  precision  0.988   0.9993       0.0113
metrics.json  recall     0.7702  0.9986       0.2284
Introduction to Data Versioning with DVC

Plots: changes in dvc.yaml

stages:
  train_and_evaluate:
    ...
    plots:
    - predictions.csv: # Name of file containing predictions
        template: confusion # Style of plot

x: predicted_label # X-axis column name in csv file y: true_label # Y-axis column name in csv file x_label: 'Predicted label' y_label: 'True label' title: Confusion matrix
cache: false # Save in Git
1 https://dvc.org/doc/user-guide/experiment-management/visualizing-plots#plot-templates-data-series-only
Introduction to Data Versioning with DVC

Printing DVC plots to file

$ dvc plots show predictions.csv
file:///path/to/index.html

Confusion matrix display plot generated by DVC

Introduction to Data Versioning with DVC

Comparing DVC plots

# comapre plot in predictions.csv against branch main
$ dvc plots diff --target predictions.csv <branch name or commit SHA>

Confusion matrix diff plot generated by DVC

Introduction to Data Versioning with DVC

Let's practice!

Introduction to Data Versioning with DVC

Preparing Video For Download...