評估: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 進行資料版本控管入門

一起來練習吧!

使用 DVC 進行資料版本控管入門

Preparing Video For Download...