ML Metrics Calculator

Accuracy, precision, recall, F1, specificity and MCC from a confusion matrix.

How it works

Enter the four counts of a confusion matrix (true positives, false positives, false negatives, true negatives) and get accuracy, precision, recall, specificity, F1 and the Matthews correlation coefficient.

The formula

precision = TP / (TP + FP)
recall = TP / (TP + FN)
F1 = 2 x precision x recall / (precision + recall)
MCC = (TP x TN - FP x FN) / root((TP+FP)(TP+FN)(TN+FP)(TN+FN))

Worked example

TP 85, FP 10, FN 15, TN 90: accuracy 87.5%, precision 89.47%, recall 85%, F1 0.8718, MCC 0.7509.

Good to know

Common questions

Which metric should I report?
Report several, and say which error matters more for your problem.
What is specificity?
TN / (TN + FP), the recall of the negative class.
What is F1?
The harmonic mean of precision and recall, so it is low if either is low.

More in CS Labs & Coding.