การเปรียบเทียบ metrics และกราฟใน DVC

CI/CD สำหรับ Machine Learning

Ravi Bhadauria

Machine Learning Engineer

การตั้งค่าไฟล์ DVC YAML

  • ตั้งค่าไฟล์ DVC YAML เพื่อติดตาม metrics ระหว่าง experiments
  • เปลี่ยนจาก outs
stages:
  preprocess:
    ...
  train:
    ...
    outs:
    - metrics.json
    - confusion_matrix.png
  • เป็น metrics
stages:
  preprocess:
    ...
  train:
    ...
    outs:
    - confusion_matrix.png

metrics: - metrics.json: cache: false
CI/CD สำหรับ Machine Learning

การดูและเปรียบเทียบ DVC metrics

-> dvc metrics show

Path accuracy f1_score precision recall metrics.json 0.947 0.8656 0.988 0.7702

เปลี่ยน hyperparameter แล้วรัน 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
1 https://dvc.org/doc/command-reference/metrics
CI/CD สำหรับ Machine Learning

การตั้งค่า DVC GitHub Action

  • เพิ่ม setup-dvc GitHub Action
  • แทนที่การรัน Python scripts ด้วย DVC pipeline
steps:
  ...
  - name: Setup DVC
    uses: iterative/setup-dvc@v1

- name: Run DVC pipeline run: dvc repro
CI/CD สำหรับ Machine Learning

การตั้งค่า DVC GitHub Action

- name: Write CML report
  env:
    REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  run: |
    # Print metrics of current branch
    dvc metrics show --md >> report.md

# Compare metrics with main branch git fetch --prune dvc metrics diff --md main >> report.md
# Create CML report cml comment create report.md
CI/CD สำหรับ Machine Learning

Pipeline ในการใช้งานจริง

ภาพหน้าจอของ comment ใน pull request ที่แสดง metrics diff เทียบกับ main branch

CI/CD สำหรับ Machine Learning

ประเภทกราฟใน DVC

  • scatter - scatter plot
  • linear - linear plot แบบโต้ตอบได้
  • simple - linear plot แบบกำหนดเองที่ไม่โต้ตอบ
  • smooth - linear plot พร้อม smoothing
  • confusion - confusion matrix
  • confusion_normalized - confusion matrix ที่ normalize ค่าให้อยู่ในช่วง <0, 1>
  • bar_horizontal - horizontal bar plot
  • bar_horizontal_sorted - horizontal bar plot เรียงตามขนาด bar
1 https://dvc.org/doc/user-guide/experiment-management/visualizing-plots#plot-templates-data-series-only
CI/CD สำหรับ Machine Learning

การตั้งค่า DVC YAML สำหรับกราฟ

stages:
  train:
    ...
    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
CI/CD สำหรับ Machine Learning

การพล็อต Confusion Matrix

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

กราฟ confusion matrix ที่สร้างโดย DVC

CI/CD สำหรับ Machine Learning

การเปรียบเทียบ Confusion Matrix

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

กราฟ diff ของ confusion matrix ที่สร้างโดย DVC

CI/CD สำหรับ Machine Learning

การเปรียบเทียบ ROC Curves

# Changes in Python
y_proba = model.predict_proba(X_test)
fpr, tpr, _ = roc_curve(y_test, 
                        y_proba[:, 1])
# Changes in 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

กราฟ diff ของ ROC curve ที่สร้างโดย DVC

CI/CD สำหรับ Machine Learning

มาฝึกกันเถอะ!

CI/CD สำหรับ Machine Learning

Preparing Video For Download...