StatFASConfusion Matrix makerGuideTutorial

Guide · Updated 2026-11-07 · Free tool included

Confusion Matrix Explained: Accuracy, Sensitivity, Specificity, F1, MCC and Kappa

A confusion matrix is a table that compares the predicted class with the actual class for every case at one chosen threshold. This guide explains what the confusion matrix shows, when and why to use the confusion matrix, the key points of interpretation, and how to create the confusion matrix in SPSS, R and Python or in seconds on statfas.com.

What is a confusion matrix?

A confusion matrix is a table that compares the predicted class with the actual class for every case at one chosen threshold. For a yes/no outcome the confusion matrix has four cells: true positives (TP), false positives (FP), false negatives (FN) and true negatives (TN).

Almost every classification metric comes from those four cells: accuracy, sensitivity (recall), specificity, positive and negative predictive value, F1, the Matthews correlation coefficient (MCC) and Cohen’s kappa.

When and why should you use a confusion matrix?

Use a confusion matrix in these situations:

The confusion matrix is the most transparent view of classification errors, and reviewers often ask for the raw counts behind every percentage.

How to interpret a confusion matrix: key points

How to make a confusion matrix in SPSS, R and Python

The snippets below show the core commands; the full confusion matrix tutorial has complete, copy-and-run code. Examples assume a data frame df with the columns named in the code.

Confusion Matrix in SPSS

First create the predicted class: Transform > Compute Variable, target pred, expression score >= 0.5. Then choose Analyze > Descriptive Statistics > Crosstabs. Put the actual outcome in Row(s) and pred in Column(s). Under Statistics tick Chi-square, Phi and Cramér’s V, and Kappa. Under Cells tick Observed and Row percentages.

SPSS syntax

COMPUTE pred = (score >= 0.5).
EXECUTE.
CROSSTABS
  /TABLES=outcome BY pred
  /STATISTICS=CHISQ PHI KAPPA
  /CELLS=COUNT ROW.

Confusion Matrix in R

R code

library(caret)
confusionMatrix(factor(df$score >= 0.5, levels = c(FALSE, TRUE), labels = c(0, 1)),
                factor(df$outcome, levels = c(0, 1)), positive = "1")

Confusion Matrix in Python

Python code

from sklearn.metrics import confusion_matrix
pred = (df["score"] >= 0.5).astype(int)
cm = confusion_matrix(df["outcome"], pred)   # [[TN, FP], [FN, TP]]

The easy way: free confusion matrix maker on statfas.com

The Confusion Matrix maker on statfas.com uploads an Excel, CSV or SPSS file, lets you set the threshold, draws the confusion matrix with row percentages, and returns accuracy, sensitivity, specificity, PPV, NPV, F1, MCC, kappa, a chi-square test and the accuracy versus no-information-rate test, all with 95% confidence intervals. No coding is needed: upload the file, confirm the columns and read the results.

Try the confusion matrix maker

How to report a confusion matrix in APA 7

Example wording (illustrative values; replace with your own results):

At a classification threshold of 0.50, the model correctly classified 172 of 200 cases (accuracy = .86, 95% CI [.80, .90]), significantly exceeding the no-information rate of .60, p < .001. Sensitivity was .88 and specificity was .84. Predicted and actual classes were significantly associated, χ²(1, N = 200) = 105.2, p < .001, φ = .73.

Place the figure number and title above the confusion matrix and a note below, as the APA 7 style requires. The statfas.com confusion matrix maker writes the caption and results paragraph automatically.

Frequently asked questions

How do I read a confusion matrix?
Rows show actual classes and columns show predicted classes in most software. The diagonal holds correct predictions; the off-diagonal cells hold false positives and false negatives.
What is the difference between sensitivity and precision?
Sensitivity (recall) is TP/(TP+FN), the share of real positives found. Precision (PPV) is TP/(TP+FP), the share of positive calls that are correct.
Why is accuracy not enough?
On imbalanced data a model can reach high accuracy by always predicting the majority class. Report sensitivity, specificity, MCC or kappa as well.
What is a good kappa or MCC?
Landis and Koch (1977) labelled kappa .41–.60 moderate, .61–.80 substantial and above .80 almost perfect. The MCC ranges from −1 to 1 and 0 means no better than chance.

References

Chicco, D., & Jurman, G. (2020). The advantages of the Matthews correlation coefficient (MCC) over F1 score and accuracy in binary classification evaluation. BMC Genomics, 21, Article 6.

Landis, J. R., & Koch, G. G. (1977). The measurement of observer agreement for categorical data. Biometrics, 33(1), 159–174.

Make a confusion matrix now. Open the free confusion matrix makerStep-by-step Confusion Matrix tutorial

More StatFAS guides

ROC Curve guide · Precision–Recall Curve guide · Calibration Plot guide · Feature Importance Plot guide