Confusion Matrix Metrics Calculator

JJ Ben-Joseph headshot JJ Ben-Joseph

A confusion matrix organizes a binary classifier’s predictions into true positives (TP), false positives (FP), true negatives (TN), and false negatives (FN). This confusion matrix metrics calculator converts those counts into accuracy, precision, recall, F1 score, specificity, and related rates so you can compare models without relying on a single headline number.

How to use this confusion matrix metrics calculator

  1. Choose which label you want to treat as the positive class for the confusion matrix, such as “spam”, “fraud”, or “disease present”.
  2. Enter TP: positives correctly predicted as positive.
  3. Enter FP: negatives incorrectly predicted as positive (false alarms).
  4. Enter TN: negatives correctly predicted as negative.
  5. Enter FN: positives incorrectly predicted as negative (misses).
  6. Click Calculate to compute the confusion matrix metrics.

Tip: These fields are counts (non‑negative integers). If you are entering a dataset summary, TP + FP + TN + FN should equal the total number of evaluated examples.

Confusion matrix structure used by this calculator

Predicted Positive Predicted Negative
Actual Positive TP FN
Actual Negative FP TN

Confusion matrix formulas

For this calculator, N is the total number of labeled examples: N = TP + FP + TN + FN.

Core confusion matrix metrics

MathML (precision in the confusion matrix):

Precision = TP TP + FP

Additional confusion matrix metrics used in practice

How to interpret confusion matrix results

Accuracy in the confusion matrix

Accuracy is the fraction of all predictions in the confusion matrix that are correct. It is most informative when the classes are reasonably balanced and the costs of different mistakes are similar. With heavy class imbalance, accuracy can look high even when the model is poor at identifying the minority class.

Precision in the confusion matrix

Precision answers: “When the model predicts positive, how often is it right?” Prioritize precision when false positives are costly, such as when a confusion matrix is being used to track false fraud alerts or needless review work.

Recall (sensitivity) in the confusion matrix

Recall answers: “Of all actual positives, how many did we catch?” Prioritize recall when false negatives are costly, such as when a confusion matrix is being used to monitor missed disease cases or overlooked risk signals.

F1 score in the confusion matrix

F1 balances precision and recall via the harmonic mean. It drops sharply if either precision or recall is low, so it is useful when you want a single number for confusion matrix quality and care about both types of positive-class error.

Specificity in the confusion matrix

Specificity measures how well the model avoids false alarms among actual negatives. It is especially relevant in screening settings where the negative class is large and you want to control false positives.

Worked example: a spam filter confusion matrix

Suppose you are evaluating a spam filter with a confusion matrix. Out of 95 actual spam messages, it correctly flags 90 and misses 5. Out of 200 legitimate emails, it incorrectly flags 15 as spam and correctly leaves 185 alone:

Total N = 90 + 5 + 15 + 185 = 295.

In this confusion matrix example, the filter catches most spam, which gives it high recall, but some positive predictions are false alarms, so precision is lower than recall. Whether that trade-off is acceptable depends on how costly a mistaken spam flag is for your users.

Metric comparison for confusion matrix metrics

Metric Best for Penalizes Can be misleading when…
Accuracy Confusion matrices with balanced classes and similar error costs All errors equally The classes are imbalanced
Precision (PPV) Reducing false positives False alarms (FP) Positive predictions are rare or the threshold changes a lot
Recall (Sensitivity) Reducing false negatives Misses (FN) You ignore the cost of false positives
F1 Balancing precision and recall Imbalance between precision and recall True negatives matter a lot, because F1 ignores TN directly
Specificity (TNR) Controlling false positives among negatives False positives (FP) You mainly care about catching positives instead
Balanced Accuracy Imbalanced confusion matrices Low TPR or low TNR Different error costs require weighting

Assumptions and limitations of confusion matrix metrics

FAQ about confusion matrix metrics

What is the positive class in a confusion matrix?

The positive class is the outcome you are trying to detect, such as spam, fraud, or disease present. Precision, recall, F1, and related metrics in this confusion matrix calculator are all defined with respect to that chosen class.

Introduction: Why accuracy can mislead in a confusion matrix

With imbalanced data, a model can predict the majority class most of the time and still achieve high accuracy while performing poorly on the minority, often more important, class. In a confusion matrix, that is the classic case where the headline number looks better than the underlying error pattern.

What if there are no predicted positives in the confusion matrix (TP + FP = 0)?

Precision is undefined because you are dividing by zero. In practice you may see N/A or 0, but the key takeaway from the confusion matrix is that the model never predicts the positive class at that threshold.

What’s the difference between recall and sensitivity in a confusion matrix?

They are the same concept in binary classification: TP / (TP + FN). “Sensitivity” is common in medicine; “recall” is common in information retrieval and machine learning, but the confusion matrix calculation is identical.

Is F1 always better than accuracy in a confusion matrix?

No. F1 focuses on the positive class and ignores true negatives directly. If true negatives matter a lot, such as when a confusion matrix is being used to avoid false alarms across a huge negative population, specificity, balanced accuracy, or PR/ROC analysis may be more appropriate.

Arcade Mini-Game: Confusion Matrix Metrics Calculator Threshold Drill

Use this quick arcade drill to practice spotting useful confusion matrix inputs and avoiding bad assumptions before you rely on the calculator output.

Score: 0 Timer: 30s Best: 0

Start the game, then use your pointer or arrow keys to catch useful confusion matrix counts and avoid bad assumptions.

Enter TP, FP, TN, and FN to calculate the confusion matrix metrics.