面向机器学习的 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: 运行 DVC 流水线 run: dvc repro
- name: 写入 CML 报告 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: '预测标签' y_label: '真实标签' title: 混淆矩阵cache: 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: '假阳性率'
y_label: '真阳性率'
title: ROC 曲线
cache: false

面向机器学习的 CI/CD