Skip to content
MoneyDeck

Confusion Matrix Calculator

Score a classifier: accuracy, precision, recall, F1, MCC and kappa

Updated · Free, no signup

Actual positive, predicted positive.

Actual negative, predicted positive (Type I error).

Actual positive, predicted negative (Type II error).

Actual negative, predicted negative.

Accuracy

87.5%

Precision (PPV)

85%

Recall / sensitivity (TPR)

89.47%

Specificity (TNR)

85.71%

F1 score

0.8718

Matthews correlation coefficient (MCC)

0.7509

Cohen’s kappa

0.75

Balanced accuracy

87.59%

Negative predictive value (NPV)

90%

False positive rate

14.29%

False negative rate

10.53%

Prevalence (actual positives)

47.5%

Total cases

200

  • Recall (89.47%) is at least as high as precision (85%): the model catches most positives but raises 15 false alarms.

Classifier metrics (%)

Confusion matrix with totals

Predicted positivePredicted negativeTotal
Actual positive851095
Actual negative1590105
Total100100200

About the Confusion Matrix Calculator

This confusion matrix calculator turns the four cells of a binary classification result — true positives, false positives, false negatives and true negatives — into every standard performance metric. You get accuracy, precision (positive predictive value), recall (sensitivity or true positive rate), specificity, negative predictive value, the F1 score, the Matthews correlation coefficient (MCC), Cohen’s kappa, balanced accuracy, prevalence and the false positive and false negative rates.

It is designed for data scientists and machine-learning students evaluating a model, analysts comparing fraud or spam filters, and anyone reading a diagnostic accuracy table. A bar chart compares the metrics side by side, and the notes flag the classic trap of an imbalanced data set, where a model can score high accuracy while missing most of the positive cases.

All metrics follow the conventional definitions used by scikit-learn and the statistics literature. When a metric’s denominator is zero (for example precision when the model never predicts positive), it is shown as “Undefined” rather than a misleading 0, and a note explains why.

With the default inputs, the accuracy is 87.5%. Change any value above to recalculate instantly.

How to use the confusion matrix calculator

  1. 1Count the true positives, false positives, false negatives and true negatives from your model or test.
  2. 2Enter the four counts.
  3. 3Read accuracy, then check precision, recall and F1 for the positive class.
  4. 4Use MCC, kappa or balanced accuracy when one class is much larger than the other.

Formula and method

Accuracy = (TP + TN) ÷ N Precision = TP ÷ (TP + FP) Recall = TP ÷ (TP + FN) F1 = 2TP ÷ (2TP + FP + FN) MCC = (TP·TN − FP·FN) ÷ √((TP+FP)(TP+FN)(TN+FP)(TN+FN))

Accuracy is the share of all cases classified correctly. Precision asks “of everything flagged positive, how much was right?”, while recall (sensitivity) asks “of all real positives, how many were caught?”. Specificity is the recall of the negative class. The F1 score is the harmonic mean of precision and recall, so it is high only when both are high.

MCC is the correlation between predicted and actual labels, ranging from −1 (always wrong) through 0 (no better than chance) to +1 (perfect); it uses all four cells and stays honest on imbalanced data. Cohen’s kappa compares observed accuracy with the agreement expected by chance, pₑ = [(TP+FP)(TP+FN) + (FN+TN)(FP+TN)] ÷ N². Balanced accuracy is the average of recall and specificity.

TP / TN
True positives / true negatives (correct predictions)
FP
False positives — negatives wrongly flagged (Type I errors)
FN
False negatives — positives missed (Type II errors)
N
Total cases, TP + FP + FN + TN

Worked examples

Balanced test set: 85 TP, 15 FP, 10 FN, 90 TN

175 of 200 cases are correct, so accuracy is 87.5%. Precision is 85 ÷ 100 = 85% and recall is 85 ÷ 95 ≈ 89.47%, giving F1 = 170 ÷ 195 ≈ 0.872. MCC = (85·90 − 15·10) ÷ √(100·95·105·100) ≈ 0.751.

Imbalanced fraud data: 40 TP, 60 FP, 10 FN, 890 TN

Accuracy looks strong at 93%, but only 5% of cases are positive, so predicting “not fraud” every time would score 95%. Precision is just 40% (40 of 100 alerts are real) and F1 = 80 ÷ 150 ≈ 0.533, a much more realistic picture.

Overly cautious model: 5 TP, 0 FP, 45 FN, 950 TN

Every positive prediction is correct (precision 100%), yet the model catches only 5 of 50 positives (recall 10%). F1 = 10 ÷ 55 ≈ 0.18 and kappa ≈ 0.17 reveal that the 95.5% accuracy is mostly the majority class.

Frequently asked questions

What is the difference between precision and recall?+

Precision is the share of positive predictions that are correct, TP ÷ (TP + FP). Recall is the share of actual positives the model finds, TP ÷ (TP + FN). Raising the decision threshold usually increases precision and lowers recall.

How is the F1 score calculated?+

F1 is the harmonic mean of precision and recall: 2 × precision × recall ÷ (precision + recall), which simplifies to 2TP ÷ (2TP + FP + FN). It ignores true negatives, so it focuses on the positive class.

Why is accuracy misleading on imbalanced data?+

If 95% of cases are negative, a model that always predicts negative scores 95% accuracy while finding no positives at all. F1, MCC, balanced accuracy and kappa account for this and expose a useless model.

What is a good MCC value?+

MCC runs from −1 to +1. Zero means the predictions are no better than random, values above about 0.5 indicate a useful classifier and +1 is perfect. Because it uses all four cells, it is often preferred over F1 for imbalanced problems.

Is recall the same as sensitivity?+

Yes. Recall, sensitivity, hit rate and true positive rate are all TP ÷ (TP + FN). Specificity is the equivalent for the negative class, TN ÷ (TN + FP), and the false positive rate equals 1 − specificity.

Related tools