How to get a Confusion Matrix
See original GitHub issue❓ Questions and Help
I made an image classifier with Lightning Flash and now I would like to see the confusion matrix of my classes. I am struggling to get this properly working.
I tried to add the metric to the ImageClassifier but as described in the documentation, only scalars as metrics are allowed - so this attempt failed.
model = ImageClassifier(
num_classes=datamodule.num_classes,
metrics=torchmetrics.ConfusionMatrix(datamodule.num_classes, compute_on_step=False),
)
Is there a proper way to get a confusion matrix?
If not, I would highly appreciate if there would be way to get the raw data from trainer.validate and trainer.test so that one can easily calculate their own metric.
# suggestion
val_res = trainer.validate(model, datamodule=datamodule, raw_results=True)
# >>> ({metric=99, ...}, ['class1, 'class2', ...], ['class2', 'class2', ...])
cheers and thanks for the library!
- OS: [macOS, Linux]
- Packaging [pip]
- Version [e.g. 0.5.0]
Issue Analytics
- State:
- Created 2 years ago
- Comments:7
Top Results From Across the Web
What is a Confusion Matrix in Machine Learning
A confusion matrix is a summary of prediction results on a classification problem. The number of correct and incorrect predictions are ...
Read more >A simple guide to building a confusion matrix - Oracle Blogs
A confusion matrix is a way of assessing the performance of a classification model. It is a comparison between the ground truth (actual...
Read more >How to Calculate Confusion Matrix Manually. | Analytics Vidhya
Calculate Accuracy · Calculate Precision · Calculate Recall | Sensitivity | True Positive Rate — TPR · Calculate the F1 Score · Calculate...
Read more >sklearn.metrics.confusion_matrix
Compute confusion matrix to evaluate the accuracy of a classification. By definition a confusion matrix C is such that ...
Read more >Python Machine Learning - Confusion Matrix - W3Schools
Creating a Confusion Matrix ... Confusion matrixes can be created by predictions made from a logistic regression. ... Next we will need to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

adding a minimal working example that reproduces the error I suspect Michl enocuntered:
Produces the following error:
We switched to pytorch lightning, where we handled the metrics on our own.