A confusion matrix is a simple table that shows how well an AI model makes predictions. It is especially useful for yes or no classification tasks, such as spam or not spam, sick or healthy, and pass or fail. Instead of giving only one score, it shows the exact kinds of correct and incorrect predictions the model made.
This matters because two models can have the same accuracy but make very different mistakes.
A 2 by 2 confusion matrix compares the model's predicted labels with the true labels from real data. The four boxes are true positive, false positive, true negative, and false negative. From these four counts, you can calculate accuracy, precision, recall, and other performance measures.
These tools help scientists, engineers, and students decide whether an AI system is reliable enough for a real task.
Key Facts
- A confusion matrix compares predicted labels with actual labels.
- True Positive TP means the model predicted positive and the actual answer was positive.
- True Negative TN means the model predicted negative and the actual answer was negative.
- False Positive FP means the model predicted positive but the actual answer was negative.
- False Negative FN means the model predicted negative but the actual answer was positive.
- Accuracy = (TP + TN) / (TP + TN + FP + FN)
Vocabulary
- Confusion Matrix
- A table that counts how many predictions a classification model got right and wrong for each class.
- Classification
- A machine learning task where a model assigns an item to a category or label.
- True Positive
- A result where the model correctly predicts the positive class.
- False Positive
- A result where the model predicts the positive class, but the actual class is negative.
- Recall
- A measure of how many actual positive cases the model correctly finds, calculated as Recall = TP / (TP + FN).
Common Mistakes to Avoid
- Mixing up false positives and false negatives. A false positive is a false alarm, while a false negative is a missed positive case.
- Looking only at accuracy. Accuracy can hide serious problems when one class is much more common than the other.
- Forgetting which side is predicted and which side is actual. Always check the labels on the matrix before filling in TP, FP, TN, and FN.
- Assuming every mistake has the same cost. In medical testing, a false negative may be much more dangerous than a false positive.
Practice Questions
- 1 A model checks 100 emails for spam. It has TP = 30, TN = 50, FP = 10, and FN = 10. What is the model's accuracy?
- 2 A disease test has TP = 45, FN = 5, FP = 20, and TN = 130. Calculate the recall using Recall = TP / (TP + FN).
- 3 Two AI models have the same accuracy for detecting dangerous objects in images, but Model A has more false negatives and Model B has more false positives. Which model is safer to use in a security system, and why?