Confusion Matrix Calculator

Interactive calculator for evaluating classification model performance. Calculate accuracy, precision, recall, and F1-score from confusion matrix values.

Confusion Matrix Formulas

Classification metrics derived from confusion matrix values:

\[\text{Accuracy} = \frac{\text{TP} + \text{TN}}{\text{TP} + \text{TN} + \text{FP} + \text{FN}}\]

Where:

  • TP: True Positives
  • TN: True Negatives
  • FP: False Positives
  • FN: False Negatives

Confusion Matrix Inputs

Accuracy

0.00%

+0.0%

Precision

0.00%

+0.0%

Recall

0.00%

+0.0%

F1-Score

0.00%

+0.0%

Status: Ready

Confusion Matrix Visualization

Predicted Positive
Predicted Negative
Actual Positive
TP: 85
FN: 10
Actual Negative
FP: 5
TN: 90
True Positive (TP)
Correctly predicted positive cases
True Negative (TN)
Correctly predicted negative cases
False Positive (FP)
Incorrectly predicted as positive
False Negative (FN)
Incorrectly predicted as negative
Performance Metrics

Detailed Metrics

Metric Progress Bars
Accuracy: 0.00%
Precision: 0.00%
Recall: 0.00%
F1-Score: 0.00%
Additional Metrics

Analysis & Recommendations

Current model performance: Needs Improvement. Adjust model parameters to improve metrics.

  • Accuracy above 90% is considered excellent for most applications
  • Balance precision and recall based on your use case requirements
  • Consider adjusting classification threshold if needed
  • Collect more data if metrics are consistently low

Understanding Confusion Matrix

What is a Confusion Matrix?

A confusion matrix is a table used to evaluate the performance of classification models. It shows the counts of correct and incorrect predictions broken down by each class, allowing for detailed analysis of classification performance.

Key Classification Metrics

Important metrics derived from the confusion matrix:

  • Accuracy: Overall correctness (TP+TN)/(TP+TN+FP+FN)
  • Precision: Positive predictions correctness TP/(TP+FP)
  • Recall (Sensitivity): Positive detection rate TP/(TP+FN)
  • F1-Score: Harmonic mean of precision and recall
When to Use Each Metric

Choose metrics based on your application:

  • Accuracy: Balanced datasets with equal class importance
  • Precision: Minimizing false positives (spam detection)
  • Recall: Minimizing false negatives (medical diagnosis)
  • F1-Score: Balancing precision and recall
Imbalanced Data: For imbalanced datasets, accuracy can be misleading. Focus on precision, recall, and F1-score.
Trade-offs: Improving precision often reduces recall and vice versa. Choose based on your specific requirements.
Threshold Adjustment: Adjusting classification thresholds can improve metrics for specific use cases.

Q&A

Q: When should I use F1-score instead of accuracy?

A: Use F1-score instead of accuracy when:

Imbalanced Datasets:

  • Example: Fraud detection where 99.9% of transactions are legitimate
  • Issue: Model could achieve 99.9% accuracy by predicting all transactions as legitimate
  • Solution: F1-score considers both precision and recall

Unequal Cost of Errors:

  • Medical Diagnosis: Missing a disease (FN) vs. false alarm (FP)
  • Spam Detection: Blocking legitimate emails (FP) vs. allowing spam (FN)
  • Quality Control: Rejecting good products (FP) vs. shipping defective ones (FN)

F1-score provides a balanced measure when class distribution is skewed.

Q: How do I interpret precision and recall values?

A: Interpretation of precision and recall:

Precision (Positive Predictive Value):

  • Definition: Of all positive predictions, how many were correct?
  • Formula: TP / (TP + FP)
  • Interpretation: High precision = Low false positive rate
  • Use Case: Spam detection, medical screening

Recall (Sensitivity/TNR):

  • Definition: Of all actual positives, how many were correctly identified?
  • Formula: TP / (TP + FN)
  • Interpretation: High recall = Low false negative rate
  • Use Case: Disease detection, fraud prevention

Perfect model has both precision and recall of 1.0 (100%).

Test Your Knowledge

Question 1: Accuracy Formula

According to the formula Accuracy = (TP + TN) / (TP + TN + FP + FN), what happens to accuracy if TP and TN increase while FP and FN stay the same?

Accuracy decreases
Accuracy increases
Accuracy remains the same
Cannot be determined
Solution

The correct answer is (b). If TP and TN increase while FP and FN remain constant, the numerator (TP + TN) increases while the denominator (TP + TN + FP + FN) also increases but at a slower rate, resulting in a higher accuracy value.

Key Definition

Accuracy = (TP + TN) / (TP + TN + FP + FN)

Question 2: Precision vs Recall Trade-off

In a medical diagnosis system, if you increase the threshold for positive predictions, what happens to precision and recall?

Both precision and recall increase
Precision increases, recall decreases
Precision decreases, recall increases
Both precision and recall decrease
Solution

The correct answer is (b). Increasing the threshold makes the model more conservative in predicting positives, which reduces false positives (improving precision) but increases false negatives (reducing recall).

Tips for Threshold Adjustment
  • Increase threshold to improve precision at the cost of recall
  • Decrease threshold to improve recall at the cost of precision
  • Use ROC curve to find optimal threshold
  • Consider the cost of different types of errors in your domain

About

AI Education Team
This confusion matrix calculator was created with Calculators tools and may make errors. Consider checking important information. Updated: April 2026.