Skip to content

Confusion matrix calculator

Enter the four counts. Get 14 metrics, with the working shown.

Confusion matrix
Predicted +Predicted −Actual +Actual −
n = 1,000datasciencetrivia.com
Accuracy
0.930
Precision
0.400
Recall
0.800
F1
0.533

Only 5% of cases are positive, so accuracy flatters this model. MCC is 0.54.

MetricValueWorking
Accuracy0.930
Precision0.400
Recall0.800
Specificity0.937
F1 score0.533
Balanced accuracy0.868
Matthews correlation coefficient0.535
Cohen's kappa0.500
Negative predictive value0.989
False positive rate0.063
False negative rate0.200
False discovery rate0.600
Prevalence0.050
Youden's J statistic0.737

— means undefined: the formula divides by zero.

The example

A fraud model checks 1,000 transactions, 50 of them fraud. Accuracy is 0.93, but a model that flags nothing scores 0.95. Precision (0.40) and MCC (0.54) tell the real story.

FAQ

How do you calculate precision and recall?
Precision = TP / (TP + FP). Recall = TP / (TP + FN). Neither uses true negatives.
Which metric should I use on imbalanced data?
Not accuracy. Use MCC or balanced accuracy for one number, or F1 if only the positive class matters.
What about more than two classes?
Treat each class as positive and the rest as negative, compute per class, then macro- or micro-average.

Flashcards

Created by santiviquez

About · Quizzes · Tools · History of AI · To suggest new questions or report an error send me a dm.