Log confusion matrices¶
Comet's confusion matrices allow you to log and visualize the confusion matrix for your Experiment, and optionally associate image samples, text, and URLs for each matrix cell.
You can interact with a logged confusion matrix from the Comet UI to seamlessly gauge the performance of your model with respect to true positives, false positives, true negatives, and false negatives.
The following method can be used to log confusion matrices:
The confusion matrices logged to an Experiment can be viewed in the following Single Experiment Tabs:
- Confusion Matrix Tab.
- Assets & Artifacts Tab:
confusion-matrices
folder.
Discover more in our Debugging Classifiers with Confusion Matrices blog post.
For example, you could...
Examine misclassification patterns, such as instances where one class is frequently mistaken for another, to guide targeted data collection or feature engineering efforts.
Log from true and predicted labels¶
The example below logs the confusion matrix for a mock binary classifier of cat and dog with a test set of 4 examples. The true and predicted labels are required as integers, and thus need to be one-hot encoded (cat -> 0, dog -> 1).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
The log_confusion_matrix()
method allows you to specify a variety of attributes for the confusion matrix; for example, you could use the title
argument to update the plot tile (default is Confusion Matrix) or the max_examples_per_cell
argument to change the maximum number of examples per cell (default is 25). Please refer to the method definition for a full list of arguments.
Log from existing confusion matrix¶
The example below logs a confusion matrix created with sklearn.metrics.confusion_matrix()
for a mock binary classifier of cat and dog with a test set of 4 examples.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
The matrix
argument excepts an ndarray, or list, of shape (n_classes, n_classes).
Log with sample images¶
For computer vision experiments, you can optionally log the image associated with each (y_true, y_predicted) entry. The example below logs images for a mock binary classifier of cat and dog with a test set of 4 examples, with example images loaded with PIL.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
The images
argument supports images in PIL, TF tensor, Pytorch tensor and numpy array format.
Warning
It may take a while for all images to be uploaded to the Comet platform when many images are passed.