LearnViz CompSci
Home / Learn / AI & Machine Learning / Confusion Matrix

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

  1. Rows are actual classes and columns are predicted classes.
  2. True positives and true negatives are correct.
  3. A false positive is a false alarm.
  4. A false negative is a missed case.
  5. 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

How to study this topic

  1. Read the explanation above and restate the definition in your own words.
  2. Open the interactive lesson and answer its mini quiz.
  3. Read the common pitfall, then write a short example that avoids it.
  4. 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?
Table of correct and incorrect predictions per class. It belongs to AI & Machine Learning and is a beginner-level topic.
Where do people use Confusion Matrix?
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.
What is the most common mistake with Confusion Matrix?
Rows and columns conventions differ between tools, so check whether actual labels are rows or columns.
What should I learn before this topic?
Start with Evaluation Metrics, the topic just before it in AI & Machine Learning.
How can I practice it?
Answer the mini quiz in the interactive lesson, then take the AI & Machine Learning quiz.
Is Confusion Matrix hard to learn?
It is a Beginner topic, so it works as an entry point. If the terms are new, read the explanation twice and try the visualizer before the quiz.
How long does it take to learn Confusion Matrix?
Most learners can read the explanation and finish the interactive lesson in under an hour. Fluency comes from applying the idea, so plan a few short practice sessions with the quiz.
Which topics are related to Confusion Matrix?
Evaluation Metrics, Cross-Validation, Bias-Variance Tradeoff are closely connected. The full list is in the related topics section of this page.
What should I study after Confusion Matrix?
Continue with Cross-Validation, the next topic in AI & Machine Learning.

Related topics