Membandingkan metrik dan plot di DVC

CI/CD untuk Machine Learning

Ravi Bhadauria

Machine Learning Engineer

Mengonfigurasi file DVC YAML

  • Konfigurasikan file DVC YAML untuk melacak metrik lintas eksperimen
  • Ubah dari outs
stages:
  preprocess:
    ...
  train:
    ...
    outs:
    - metrics.json
    - confusion_matrix.png
  • Ke metrics
stages:
  preprocess:
    ...
  train:
    ...
    outs:
    - confusion_matrix.png

metrics: - metrics.json: cache: false
CI/CD untuk Machine Learning

Mengkueri dan membandingkan metrik DVC

-> dvc metrics show

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

Ubah satu hiperparameter dan jalankan ulang 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 untuk Machine Learning

Menyiapkan DVC GitHub Action

  • Tambahkan GitHub Action setup-dvc
  • Ganti eksekusi skrip Python dengan pipeline DVC
steps:
  ...
  - name: Setup DVC
    uses: iterative/setup-dvc@v1

- name: Jalankan pipeline DVC run: dvc repro
CI/CD untuk Machine Learning

Menyiapkan DVC GitHub Action

- name: Tulis laporan CML
  env:
    REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  run: |
    # Cetak metrik cabang saat ini
    dvc metrics show --md >> report.md

# Bandingkan metrik dengan cabang main git fetch --prune dvc metrics diff --md main >> report.md
# Buat laporan CML cml comment create report.md
CI/CD untuk Machine Learning

Pipeline berjalan

Tangkapan layar komentar pull request yang menampilkan perbedaan metrik terhadap cabang main

CI/CD untuk Machine Learning

Jenis plot di DVC

  • scatter - plot sebar
  • linear - plot linear interaktif
  • simple - plot linear kustom non-interaktif
  • smooth - plot linear dengan pemulusan
  • confusion - matriks kebingungan
  • confusion_normalized - matriks kebingungan dengan nilai dinormalisasi ke rentang <0, 1>
  • bar_horizontal - plot batang horizontal
  • bar_horizontal_sorted - plot batang horizontal diurutkan menurut ukuran batang
1 https://dvc.org/doc/user-guide/experiment-management/visualizing-plots#plot-templates-data-series-only
CI/CD untuk Machine Learning

Mengonfigurasi DVC YAML untuk plot

stages:
  train:
    ...
    plots:
    - predictions.csv: # Nama file yang memuat prediksi
        template: confusion # Gaya plot

x: predicted_label # Nama kolom sumbu X di file csv y: true_label # Nama kolom sumbu Y di file csv x_label: 'Predicted label' y_label: 'True label' title: Confusion matrix
cache: false # Simpan di Git
CI/CD untuk Machine Learning

Plotting Confusion Matrix

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

Plot tampilan matriks kebingungan yang dihasilkan DVC

CI/CD untuk Machine Learning

Membandingkan Confusion Matrix

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

Plot perbandingan matriks kebingungan yang dihasilkan DVC

CI/CD untuk Machine Learning

Membandingkan Kurva ROC

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

Plot perbandingan kurva ROC yang dihasilkan DVC

CI/CD untuk Machine Learning

Ayo berlatih!

CI/CD untuk Machine Learning

Preparing Video For Download...