Confusion Matrix
Build a confusion matrix and accuracy from labels.
About this tool
Paste the true labels and the predicted labels, one per line, and get a confusion matrix with accuracy. Class names can be any text, such as cat and dog, or 1 and 0. Rows are the true class and columns are the predicted class.
How to use
How it works
Each cell counts how often a true class (row) was predicted as a class (column). The diagonal holds the correct predictions. Accuracy is the diagonal sum divided by the number of samples. Both lists must be the same length; otherwise you get a length mismatch error.
accuracy = (Σ diagonal) / n
Worked example
Cats and dogs
- Input
- y_true: cat, cat, dog, dog, dog y_pred: cat, dog, dog, dog, cat
- Output
- Labels: cat, dog Row cat: 1, 1 Row dog: 1, 2 Accuracy 0.6
- Walkthrough
- Of 2 true cats, 1 was predicted cat and 1 dog. Of 3 true dogs, 2 were predicted dog and 1 cat. (1 + 2) / 5 = 0.6.
Limitations
- Printed as text rows, not a coloured grid.
- No per-class precision and recall here; use the precision, recall and F1 tool.
- Labels are matched exactly, so Cat and cat count as different classes.
Questions
How do I make a confusion matrix?
Are rows true labels or predictions?
Does it work with more than two classes?
Why do I get a length mismatch?
Features
- Any number of classes
- Accuracy included
- Runs in your browser
Related resources
Guides and videos from around the web—opens on YouTube or the publisher’s site.
Finding mean, median, and mode
Khan Academy
Baseline stats for accuracy and evaluation helpers.
Watch on YouTubeMachine Learning for Everybody
freeCodeCamp.org
Accessible ML survey for AI calculator and metric tools.
Watch on YouTube
- Machine Learning Crash Course
Google Developers
Official ML crash course pairing with metric calculators.
- Metrics and scoring
scikit-learn
Precision, recall, F1 definitions used by AI metric tools.