Overview
A confusion matrix compares a classifier's predictions with the truth. From its four counts, this works out the six most used metrics in one go.
Enter true positives, false positives, true negatives and false negatives.
Worked examples
| Inputs | Result |
|---|---|
| True Positives88False Positives12True Negatives170False Negatives20 | Accuracy: 88.97%Precision: 88%Recall: 81.48%Specificity: 93.41%F1: 84.62%MCC: 0.76 |
Show 2 more examples
| True Positives45False Positives5True Negatives40False Negatives10 | Accuracy: 85%Precision: 90%Recall: 81.82%Specificity: 88.89%F1: 85.71%MCC: 0.7 |
| True Positives10False Positives90True Negatives880False Negatives20 | Accuracy: 89%Precision: 10%Recall: 33.33%Specificity: 90.72%F1: 15.38%MCC: 0.14 |
Accuracy by true negatives
With the calculator's starting values, the accuracy is 88.97%. The table shows how it changes with the true negatives.
| True Negatives | Accuracy |
|---|---|
| 100 | 85.45% |
| 125 | 86.94% |
| 150 | 88.15% |
| 170starting value | 88.97% |
| 175 | 89.15% |
| 200 | 90% |
| 225 | 90.72% |
| 250 | 91.35% |
Other inputs: True Positives: 88 · False Positives: 12 · False Negatives: 20. Change them in the calculator above for your own numbers.
How it works
Accuracy is the share of all predictions that were right. Precision is the share of positive predictions that were real, and recall the share of real positives that were found. Specificity is the share of real negatives correctly cleared. F1 balances precision and recall, and MCC summarizes all four cells in one score from −1 to 1.
The formula
| TP, FP, TN, FN | True positives, false positives, true negatives, false negatives |
Practical tips
- 88 TP, 12 FP, 170 TN and 20 FN give 88.97% accuracy, 88% precision, 81.48% recall and an MCC of 0.76.
- With imbalanced classes, look at MCC or F1 rather than accuracy.
- Moving a model's threshold trades precision against recall.
Frequently asked questions
What's a good F1 score?
It depends on the problem. Compare it against a simple baseline model.
What's the difference between recall and specificity?
Recall is about the positive class, specificity about the negative class.
Why use MCC?
It's high only when the model does well on both classes.