Beginner Topic 16 of 51 AI & Machine Learning
Confusion Matrix
Table of correct and incorrect predictions per class.
How it works
A confusion matrix is a table that compares predicted classes with actual classes. For binary classification its cells are true positives, false positives, false negatives and true negatives. From it come accuracy, precision, recall, specificity and F1, and it shows which classes the model confuses in the multiclass case. Changing the decision threshold moves counts between cells, trading false positives against false negatives.
Step-by-step walkthrough
- Rows are actual classes and columns are predicted classes.
- True positives and true negatives are correct.
- A false positive is a false alarm.
- A false negative is a missed case.
- Precision and recall come from these four counts.
Where it is used
Evaluating medical tests, fraud detection, spam filters and any classifier where different errors have different costs uses the confusion matrix, usually shown as a heatmap.
Common pitfall
Rows and columns conventions differ between tools, so check whether actual labels are rows or columns. Reading only accuracy hides poor performance on minority classes. Counts depend on class balance, so normalize by row or column when comparing. A single threshold yields one matrix, so also examine ROC or precision-recall curves. Relate error types to their costs.
Where it fits in the course
Confusion Matrix is topic 16 of 51 in AI & Machine Learning, rated Beginner. It follows Evaluation Metrics. The next topic is Cross-Validation.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the AI & Machine Learning quiz.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the AI & Machine Learning quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is Confusion Matrix?
Where do people use Confusion Matrix?
What is the most common mistake with Confusion Matrix?
What should I learn before this topic?
How can I practice it?
Is Confusion Matrix hard to learn?
How long does it take to learn Confusion Matrix?
Which topics are related to Confusion Matrix?
What should I study after Confusion Matrix?
Related topics
- Evaluation Metrics (AI & Machine Learning)
- Cross-Validation (AI & Machine Learning)
- Bias-Variance Tradeoff (AI & Machine Learning)
- Gradient Descent (AI & Machine Learning)
- Matrix Multiplication (Math for Computing)
- Adjacency Matrix (Data Structures)