Metric en plots vergelijken in DVC

CI/CD voor Machine Learning

Ravi Bhadauria

Machine Learning Engineer

DVC YAML-bestand configureren

  • Configureer het DVC YAML-bestand om metrics over experimenten te volgen
  • Wijzig van outs
stages:
  preprocess:
    ...
  train:
    ...
    outs:
    - metrics.json
    - confusion_matrix.png
  • Naar metrics
stages:
  preprocess:
    ...
  train:
    ...
    outs:
    - confusion_matrix.png

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

DVC-metrics opvragen en vergelijken

-> dvc metrics show

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

Wijzig een hyperparameter en voer dvc repro opnieuw uit

-> 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 voor Machine Learning

DVC GitHub Action instellen

  • Voeg de setup-dvc GitHub Action toe
  • Vervang losse Python-scripts door de DVC-pipeline
steps:
  ...
  - name: Setup DVC
    uses: iterative/setup-dvc@v1

- name: Run DVC pipeline run: dvc repro
CI/CD voor Machine Learning

DVC GitHub Action instellen

- 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 voor Machine Learning

Pipeline in actie

Schermafbeelding van een pull request-opmerking met metrics-diff t.o.v. de main-branch

CI/CD voor Machine Learning

Plottypes in DVC

  • scatter - spreidingsdiagram
  • linear - interactieve lijngrafiek
  • simple - niet-interactieve, aanpasbare lijngrafiek
  • smooth - lijngrafiek met smoothing
  • confusion - verwarringsmatrix
  • confusion_normalized - verwarringsmatrix met waarden genormaliseerd tot bereik <0, 1>
  • bar_horizontal - horizontale staafdiagram
  • bar_horizontal_sorted - horizontale staafdiagram gesorteerd op staafgrootte
1 https://dvc.org/doc/user-guide/experiment-management/visualizing-plots#plot-templates-data-series-only
CI/CD voor Machine Learning

DVC YAML voor plots configureren

stages:
  train:
    ...
    plots:
    - predictions.csv: # Naam van bestand met voorspellingen
        template: confusion # Plotstijl

x: predicted_label # X-as kolomnaam in csv-bestand y: true_label # Y-as kolomnaam in csv-bestand x_label: 'Predicted label' y_label: 'True label' title: Confusion matrix
cache: false # In Git opslaan
CI/CD voor Machine Learning

Verwarringsmatrix plotten

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

Weergave van verwarringsmatrix-plot gegenereerd door DVC

CI/CD voor Machine Learning

Verwarringsmatrix vergelijken

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

DVC-plot met verschil van verwarringsmatrix

CI/CD voor Machine Learning

ROC-curves vergelijken

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

DVC-plot met verschil in ROC-curves

CI/CD voor Machine Learning

Laten we oefenen!

CI/CD voor Machine Learning

Preparing Video For Download...