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:
Where:
- TP: True Positives
- TN: True Negatives
- FP: False Positives
- FN: False Negatives
Confusion Matrix Inputs
Confusion Matrix Visualization
Performance Metrics
Detailed Metrics
Metric Progress Bars
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
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.
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
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
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
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?
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.
Accuracy = (TP + TN) / (TP + TN + FP + FN)
In a medical diagnosis system, if you increase the threshold for positive predictions, what happens to precision and recall?
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).
- 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