Skip to content
Edit on GitHub

Live.log_plot()

Generates a scikit learn plot and saves the data in {path}/plots/{name}.json.

def log_plot(self, name: str, labels, predictions, **kwargs):

Usage:

from dvclive import Live

live = Live()

y_true = [0, 0, 1, 1]
y_pred = [1, 0, 1, 0]
y_score = [0.1, 0.4, 0.35, 0.8]]
live.log_plot("roc", y_true, y_score)
live.log_plot("confusion_matrix", y_true, y_pred)

Description

Uses name to determine which plot should be generated. See supported plots.

The generated {path}/plots/{name}.json can be visualized with dvc plots.

Step updates

Live.log_plot() can be currently only used when step is None.

If you perform step updates in your code, you can later use Live.set_step(None) in order to be able to use Live.log_plot().

for epoch in range(NUM_EPOCHS):
    live.log(metric_name, value)
    live.next_step()

live.set_step(None)
live.log_plot("roc", y_true, y_score)

Supported plots

name must be one of the supported plots:

Generates a calibration curve plot.

Calls sklearn.calibration.calibration_curve and stores the data at {path}/plots/calibratrion.json in a format compatible with dvc plots.

y_true = [0, 0, 1, 1]
y_score = [0.1, 0.4, 0.35, 0.8]
live.log_plot("calibration", y_true, y_score)

Example usage with dvc plots:

$ dvc plots show 'dvclive/plots/calibration.json' \
-x prob_pred -y prob_true \
--x-label 'Mean Predicted Probability' \
--y-label 'Fraction of Positives' \
--title 'Calibration Curve'

dvclive calibration

Generates a confusion matrix plot.

Stores the abels and predictions in {path}/plots/confusion_matrix.json, with the format expected by the confusion matrix template of dvc plots.

y_true = [1, 1, 2, 2]
y_pred = [2, 1, 1, 2]
live.log_plot("confusion_matrix", y_true, y_pred)

Example usage with dvc plots:

$ dvc plots show 'dvclive/plots/confusion_matrix.json' \
-x actual -y predicted \
--template confusion

dvclive confusion matrix

Generates a detection error tradeoff (DET) plot.

Calls sklearn.metrics.det_curve and stores the data at {path}/plots/det.json in a format compatible with dvc plots.

y_true = [1, 1, 2, 2]
y_score = [0.1, 0.4, 0.35, 0.8]
live.log_plot("det", y_true, y_score)

Example usage with dvc plots:

$ dvc plots show 'dvclive/plots/det.json' \
-x fpr -y fnr \
--title 'DET Curve'

dvclive det

Generates a precision-recall curve plot.

Calls sklearn.metrics.precision_recall_curve and stores the data at {path}/plots/precision_recall.json in a format compatible with dvc plots.

y_true = [1, 1, 2, 2]
y_score = [0.1, 0.4, 0.35, 0.8]
live.log_plot("precision_recall", y_true, y_score)

Example usage with dvc plots:

$ dvc plots show 'dvclive/plots/precision_recall.json' \
-x recall -y precision \
--title 'Precision Recall Curve'

dvclive precision recall

Generates a receiver operating characteristic (ROC) curve plot.

Calls sklearn.metrics.roc_curve and stores the data at {path}/plots/roc.json in a format compatible with dvc plots.

y_true = [1, 1, 2, 2]
y_score = [0.1, 0.4, 0.35, 0.8]
live.log_plot("roc", y_true, y_score)

Example usage with dvc plots:

$ dvc plots show 'dvclive/plots/roc.json' \
-x fpr -y tpr \
--title 'ROC Curve'

dvclive roc

Parameters

  • name - a supported plot type

  • labels - array of ground truth labels

  • predictions - array of predicted labels (for confusion_matrix) or predicted probabilities (for other plots)

  • **kwargs - additional arguments to be passed to the internal scikit-learn function being called

Exceptions

  • dvclive.error.InvalidPlotTypeError - thrown if the provided name does not correspond to any of the supported plots.

  • RuntimeError - thrown if Live.log_plot() is used and step is not None.

Content

🐛 Found an issue? Let us know! Or fix it:

Edit on GitHub

Have a question? Join our chat, we will help you:

Discord Chat