Home Back

Confusion Matrix Calculator

Confusion Matrix:

\[ \begin{bmatrix} \text{True Positive (TP)} & \text{False Positive (FP)} \\ \text{False Negative (FN)} & \text{True Negative (TN)} \end{bmatrix} \]

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

Unit Converter ▲

Unit Converter ▼

From: To:

1. What is a Confusion Matrix?

A confusion matrix is a table that summarizes the performance of a classification algorithm by comparing predicted classes against actual classes. It's a fundamental tool for evaluating machine learning models in binary classification problems.

2. How To Calculate Confusion Matrix

The confusion matrix is constructed by counting:

\[ \begin{bmatrix} \text{TP} & \text{FP} \\ \text{FN} & \text{TN} \end{bmatrix} \]

Where:

3. Understanding the Metrics

Accuracy: Overall correctness of the model (TP+TN)/(TP+FP+FN+TN)
Precision: When it predicts positive, how often is it correct? TP/(TP+FP)
Recall (Sensitivity): How many actual positives were correctly predicted? TP/(TP+FN)
F1 Score: Harmonic mean of precision and recall (2*Precision*Recall)/(Precision+Recall)

4. Using the Calculator

Instructions: Enter the counts for each category (TP, FP, FN, TN) from your classification results. The calculator will compute all relevant performance metrics.

5. Frequently Asked Questions (FAQ)

Q1: What's better - high precision or high recall?
A: Depends on your use case. For spam detection, you want high precision. For disease screening, you want high recall.

Q2: What does an F1 score of 1 mean?
A: A perfect score of 1 means both precision and recall are 1 (perfect classification).

Q3: Can I use this for multi-class problems?
A: This calculator is for binary classification. For multi-class, you'd need one matrix per class.

Q4: What if my confusion matrix has zeros?
A: Some metrics become undefined (like precision when TP+FP=0). The calculator handles these cases.

Q5: How do I get these values from my model?
A: Most ML libraries (scikit-learn, TensorFlow) provide functions to compute the confusion matrix.

Confusion Matrix Calculator© - All Rights Reserved 2025