Confusion Matrix Metrics Calculator
| Predicted positive | Predicted negative | |
|---|---|---|
| Actually positive | correctly flagged | missed |
| Actually negative | false alarm | correctly cleared |
Try an example
Headline metrics
- Accuracy
- 97.50%
- Precision
- 85.00%
- Recall
- 89.47%
- F1 score
- 87.18%
1,000 cases, 9.50% of them actually positive. With classes this unbalanced, a model that always predicts the majority class would score 90.50% accuracy, so judge it on precision, recall, F1 or MCC instead.
All metrics
| AccuracyShare of all predictions that are right. Misleading when one class is rare. | (TP + TN) / total | 97.50% |
|---|---|---|
| Precision (PPV)Of the cases flagged positive, how many really are. | TP / (TP + FP) | 85.00% |
| Recall (sensitivity, TPR)Of the real positives, how many were caught. | TP / (TP + FN) | 89.47% |
| Specificity (TNR)Of the real negatives, how many were correctly cleared. | TN / (TN + FP) | 98.34% |
| F1 scoreHarmonic mean of precision and recall. | 2TP / (2TP + FP + FN) | 87.18% |
| Negative predictive valueOf the cases flagged negative, how many really are. | TN / (TN + FN) | 98.89% |
| Balanced accuracyAccuracy that weights both classes equally. | (TPR + TNR) / 2 | 93.91% |
| False positive rateFall-out: real negatives wrongly flagged. | FP / (FP + TN) | 1.66% |
| False negative rateMiss rate: real positives not caught. | FN / (FN + TP) | 10.53% |
| Matthews correlation (MCC)−1 to +1; 0 is no better than chance. Robust to class imbalance. | (TP·TN − FP·FN) / √(…) | 0.8583 |
| Cohen's kappaAgreement beyond what chance would give. | (p₀ − pₑ) / (1 − pₑ) | 0.8580 |
"Undefined" means the denominator is 0. For example, precision has no value when the model never predicts positive.
Enter the four cells of a confusion matrix (true and false positives and negatives) to get accuracy, precision, recall, specificity, F1, negative predictive value, balanced accuracy, Matthews correlation and Cohen's kappa, with a warning when unbalanced classes make accuracy misleading.
Formula
Worked Example
Only 95 of the 1,000 cases are positive, so a model that always answered negative would already score 90.5% accuracy. Precision and recall show what the 97.5% hides: 15 of the 100 flagged cases are false alarms and 10 of the 95 real positives are missed.
Frequently Asked Questions
What is the difference between precision and recall?
Precision asks how many of the cases the model flagged are really positive; recall asks how many of the real positives it caught. A spam filter needs high precision so real mail isn't lost, while a disease screen needs high recall so few cases are missed.
Why is accuracy misleading with imbalanced data?
When one class is rare, predicting the common class every time scores high accuracy while finding nothing. With 1% fraud, a model that never flags fraud is 99% accurate. Use precision, recall, F1, balanced accuracy or the Matthews correlation instead.
What is a good F1 score?
It depends on the task and on what a simple baseline achieves. F1 is the harmonic mean of precision and recall, so it is high only when both are; compare it with the F1 of a trivial model and look at precision and recall separately to see which errors dominate.