Skip to content
p.mba

Type to search tools, guides, glossary terms, frameworks, formula sheets and pages.

Menu

Glossary · Data Science & AI

Confusion Matrix

Also called: error matrix · classification table

A table that counts a classifier's true positives, false positives, true negatives and false negatives, the basis for accuracy, precision and recall.

Definition

A confusion matrix cross-tabulates a classification model's predictions against actual outcomes. For a yes-or-no problem it has four cells: true positives, false positives (type I errors), false negatives (type II errors) and true negatives. Metrics such as accuracy, precision, recall and specificity are all ratios of these cells. When one class is rare, accuracy can look excellent even for a useless model, so the full matrix and costs of each error type should guide the choice of threshold.

Formula

Accuracy=TP+TNTP+FP+FN+TN\text{Accuracy} = \frac{TP + TN}{TP + FP + FN + TN}
TeX source
\text{Accuracy} = \frac{TP + TN}{TP + FP + FN + TN}

Worked example

Hypothetical: of 10,000 transactions, 100 are fraud. A model flags 480, catching 80 frauds (TP) and missing 20 (FN), with 400 false alarms (FP) and 9,500 true negatives. Accuracy is 95.8%, but precision is only 80 / 480 ≈ 16.7% while recall is 80%.

Try it in a tool

  • Precision and Recall: Precision is the share of predicted positives that are correct; recall is the share of actual positives the model finds.
  • Type I Error: Rejecting a null hypothesis that is actually true; concluding there is an effect when there is none.
  • Type II Error: Failing to reject a null hypothesis that is actually false; missing an effect that really exists.
  • Logistic Regression: A regression model for yes-or-no outcomes that predicts the probability of an event by passing a linear score through an S-shaped logistic function.
  • Supervised Learning: Machine learning that trains a model on examples with known answers (labels) so it can predict the answer for new cases.

Courses

More in Data Science & AI

All glossary terms