Skip to main content

function confusion_matrix

Constructs a confusion matrix from a sequence of probabilities or predictions. Args:
  • probs: A sequence of predicted probabilities for each class. The sequence shape should be (N, K) where N is the number of samples and K is the number of classes. If provided, preds should not be provided.
  • y_true: A sequence of true labels.
  • preds: A sequence of predicted class labels. If provided, probs should not be provided.
  • class_names: Sequence of class names. If not provided, class names will be defined as “Class_1”, “Class_2”, etc.
  • title: Title of the confusion matrix chart.
  • split_table: Whether the table should be split into a separate section in the W&B UI. If True, the table will be displayed in a section named “Custom Chart Tables”. Default is False.
Returns:
  • CustomChart: A custom chart object that can be logged to W&B. To log the chart, pass it to wandb.log().
Raises:
  • ValueError: If both probs and preds are provided or if the number of predictions and true labels are not equal. If the number of unique predicted classes exceeds the number of class names or if the number of unique true labels exceeds the number of class names.
  • wandb.Error: If numpy is not installed.
Examples: Logging a confusion matrix with random probabilities for wildlife classification:
In this example, random probabilities are used to generate a confusion matrix. Logging a confusion matrix with simulated model predictions and 85% accuracy:
In this example, predictions are simulated with 85% accuracy to generate a confusion matrix.