Machine Learning 的 CI/CD
Ravi Bhadauria
Machine Learning Engineer
outs 變更為stages:
preprocess:
...
train:
...
outs:
- metrics.json
- confusion_matrix.png
metricsstages: preprocess: ... train: ... outs: - confusion_matrix.pngmetrics: - metrics.json: cache: false
-> dvc metrics showPath accuracy f1_score precision recall metrics.json 0.947 0.8656 0.988 0.7702
調整超參數並重新執行 dvc repro
-> dvc metrics diffPath 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
setup-dvc GitHub Actionsteps: ... - name: Setup DVC uses: iterative/setup-dvc@v1- name: Run DVC pipeline run: dvc repro
- name: Write CML report env: REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | # 印出目前分支的指標 dvc metrics show --md >> report.md# 與 main 分支比較指標 git fetch --prune dvc metrics diff --md main >> report.md# 建立 CML 報告 cml comment create report.md

scatter - 散佈圖linear - 互動式線圖simple - 非互動、可自訂線圖smooth - 平滑線圖confusion - 混淆矩陣confusion_normalized - 正規化至 <0, 1> 的混淆矩陣bar_horizontal - 水平長條圖bar_horizontal_sorted - 依長條大小排序的水平長條圖stages: train: ... 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 matrixcache: false # 儲存在 Git
-> dvc plots show predictions.csv
file:///path/to/index.html

-> dvc plots diff --target predictions.csv main
file:///path/to/index.html

# Python 變更
y_proba = model.predict_proba(X_test)
fpr, tpr, _ = roc_curve(y_test,
y_proba[:, 1])
# dvc.yaml 變更
plots:
- roc_curve.csv:
template: simple
x: fpr
y: tpr
x_label: 'False Positive Rate'
y_label: 'True Positive Rate'
title: ROC curve
cache: false

Machine Learning 的 CI/CD