Confusion Matrix

Build a confusion matrix and accuracy from labels.

FreeNo accountOn your device

Runs in your browser. How to verify

Loading tool…

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

1
Step 1
Paste y_true, one label per line.
2
Step 2
Paste y_pred in the same order.
3
Step 3
Press Calculate.

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?
Paste the true and predicted labels, one per line, and press Calculate.
Are rows true labels or predictions?
Rows are the true labels; columns are the predicted labels.
Does it work with more than two classes?
Yes, any number of classes.
Why do I get a length mismatch?
The two label lists must have the same number of items.

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 YouTube
  • Machine Learning for Everybody

    freeCodeCamp.org

    Accessible ML survey for AI calculator and metric tools.

    Watch on YouTube