评估:DVC 的指标与图表

DVC 数据版本管理入门

Ravi Bhadauria

Machine Learning Engineer

指标:dvc.yaml 的更改

  • 在 DVC YAML 中配置:跨实验跟踪指标
  • outs 更改为
stages:
  train_and_evaluate:
    outs:
    - metrics.json
    - plots.png

$$ $$

  • 改为 metrics
stages:
  train_and_evaluate:
    outs:
    - plots.png
    metrics:
      - metrics.json:
        cache: false
DVC 数据版本管理入门

打印 DVC 指标

$ dvc metrics show
Path          accuracy    f1_score    precision    recall             
metrics.json  0.947       0.8656      0.988        0.7702
DVC 数据版本管理入门

跨运行比较指标

  • 修改超参数并运行 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
DVC 数据版本管理入门

图表:dvc.yaml 的更改

stages:
  train_and_evaluate:
    ...
    plots:
    - predictions.csv: # 预测结果文件名
        template: confusion # 图表样式

x: predicted_label # csv 中的 X 轴列名 y: true_label # csv 中的 Y 轴列名 x_label: 'Predicted label' y_label: 'True label' title: Confusion matrix
cache: false # 保存到 Git
1 https://dvc.org/doc/user-guide/experiment-management/visualizing-plots#plot-templates-data-series-only
DVC 数据版本管理入门

将 DVC 图表输出到文件

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

由 DVC 生成的混淆矩阵图

DVC 数据版本管理入门

比较 DVC 图表

# 将 predictions.csv 的图与分支 main 比较
$ dvc plots diff --target predictions.csv <branch name or commit SHA>

由 DVC 生成的混淆矩阵差异图

DVC 数据版本管理入门

Passons à la pratique !

DVC 数据版本管理入门

Preparing Video For Download...