Files never leave your device

Confusion matrix calculator

Calculate accuracy, precision, recall, specificity and F1 for binary classification. Your inputs stay on your device.

Set up your task

Ready. Processing stays in this browser.

How to use Confusion matrix calculator

Calculate accuracy, precision, recall, specificity and F1 for binary classification. The pre-filled problem gives you a worked starting point. Compare the response with your own working before trying the self-check below.

  1. Check the example inputs: True positives, False positives, False negatives, True negatives.
  2. Change the inputs for your problem. Results update as you type, so finish entering the values before copying an answer.
  3. Use the working to check an intermediate value or assumption. Then change the example as suggested in the self-check and compare the result.

Supported inputs and limits

Use non-negative integer counts for the positive and negative outcomes. A metric with a denominator of zero is labelled undefined.

How it works

A binary confusion matrix separates predictions into true positives, false positives, false negatives and true negatives. Accuracy describes correct predictions overall. Precision asks how many predicted positives were real. Recall asks how many actual positives were detected. Specificity asks how many actual negatives were correctly rejected.

F1 is the harmonic balance of precision and recall, expressed from the raw counts. The scores answer different questions, especially when one class is rare. For example, accuracy can look high when the model mostly predicts a common negative class, even though it misses most positives.

Example

Run the pre-filled example. Its first result is “Accuracy: 0.85”.

True positives
30
False positives
10
False negatives
5
True negatives
55
Accuracy: 0.85
Precision: 0.75 · Recall: 0.857142857
Specificity: 0.846153846 · F1: 0.8
Precision conditions on predicted positives. Recall conditions on actual positives.

Questions about Confusion matrix calculator

Which class counts as positive?

Use whichever class the problem identifies as the target. Changing that designation swaps how precision, recall and specificity should be interpreted.

What if there are no predicted positives?

Precision is undefined because its denominator is zero. Recall is still defined when actual positive examples exist.

Set TP and FP to zero, FN to 5 and TN to 95.

Accuracy is 0.95 and recall is zero. The model is accurate overall because the negatives dominate this example.

Related tools

Year 3: Advanced and applied maths

Last updated