A confusion matrix compares what a test, a classifier or a model predicted with what really happened. It has four counts: true positives (correctly flagged), false positives (flagged by mistake), false negatives (missed) and true negatives (correctly cleared). Many quality measures are built from these four numbers. This calculator computes the main ones together, so you can see more than a single accuracy figure.
How the calculation works
- Accuracy = (TP + TN) ÷ total
- Precision = TP ÷ (TP + FP), recall = TP ÷ (TP + FN), specificity = TN ÷ (TN + FP)
- F1 = 2 × precision × recall ÷ (precision + recall)
- Balanced accuracy = (recall + specificity) ÷ 2
- Youden’s J = recall + specificity − 1
- MCC = (TP × TN − FP × FN) ÷ √((TP + FP)(TP + FN)(TN + FP)(TN + FN))
Example
A classifier finds 80 true positives and 90 true negatives, with 20 false positives and 10 false negatives, out of 200 cases. Accuracy is 85%, precision 80%, recall 88.9% and specificity 81.8%. The F1 score is 84.2%, the balanced accuracy 85.4%, Youden’s J 0.707 and the MCC 0.704, a strong agreement.
Choosing the right measure
When positives are rare, accuracy hides failures, so look at precision and recall. Precision matters when false alarms are costly, as with spam filters; recall matters when missing a case is costly, as with disease screening. F1 combines both for a single score, and the MCC is the most balanced, because it is high only if all four cells are good.
Cautions
These figures describe the data you counted. If the test cases are not representative, or if the prevalence differs in real use, precision and predictive values will change even if sensitivity and specificity stay the same. For a medical test, see how the predictive values depend on prevalence before using the result for decisions.