UtilityToolsLab

© 2026 UtilityToolsLab. Built and maintained by the UtilityToolsLab Team.

About·Changelog·Privacy Policy·Terms of Service·Contact
HomeML & Data PrepConfusion Matrix

Related Tools

Data AnonymizerData Normalizer

Confusion Matrix Calculator — F1, Recall

Get accuracy, precision, recall, F1, specificity and MCC from TP, FP, FN and TN, or paste actual and predicted labels for a multiclass matrix and report.

You Might Also Like

All ML & Data Prep

Data Anonymizer

Paste any CSV, toggle which columns hold PII, and choose Redact, Hash or Fake per column. Anonymised CSV downloads instantly — nothing leaves your browser.

Data Normalizer

Rescale a numeric dataset with Min-Max Scaling or Z-Score Standardisation. Value-by-value table, visual bars, Copy CSV and Download CSV.

A/B Significance

Run a two-proportion z-test on your A/B test results and get a real p-value, not just a percentage. Fully client-side, no data ever leaves your device.

Factorial Calculator

Compute n! for any n from 0 to 500 using exact BigInt arithmetic. Shows digit count, trailing zeros, Stirling approximation, and a P(n,r)/C(n,r) helper.

Your classifier is right 85% of the time. Is that good? On its own the number says little. A confusion matrix splits the predictions into four kinds: true positives, false positives, false negatives and true negatives. Each common score asks a different question of those four numbers. Precision asks how often a “yes” is right. Recall asks how many of the real cases were found. F1 balances the two.

Enter the four counts for a binary model and every standard metric appears, each with the working that produced it. Or paste the actual and predicted labels, for any number of classes. The tool then builds the matrix itself and prints a report like scikit-learn's classification_report, with precision, recall, F1 and support for every class plus macro, weighted and micro averages.

Worked Example: 45 Hits, 5 False Alarms

The page opens with TP 45, FP 5, FN 10 and TN 40, 100 cases in all.

  • Accuracy (45 + 40) ÷ 100 = 85.00%. Precision 45 ÷ 50 = 90.00%. Recall 45 ÷ 55 = 81.82%.
  • F1 = 2 × 45 ÷ (90 + 5 + 10) = 85.71%. It sits between precision and recall but nearer the lower one, which is the point of a harmonic mean.
  • Specificity 40 ÷ 45 = 88.89%, balanced accuracy 85.35%, and the Matthews correlation coefficient 0.7035.
  • Switch to Actual vs predicted labels (or press Load Sample once) for 12 cat, dog and bird labels. The matrix shows 9 of 12 correct (75.00%), with per-class F1 of 0.667 for bird, 0.800 for cat and 0.750 for dog, and a macro F1 of 0.739.

The Formulas, Each With Its Own Denominator

  • Precision = TP ÷ (TP + FP), over everything the model called positive. Recall = TP ÷ (TP + FN), over everything that really was positive.
  • F1 = 2·TP ÷ (2·TP + FP + FN), the same value as 2PR ÷ (P + R). Specificity = TN ÷ (TN + FP) is recall for the negative class.
  • MCC = (TP·TN − FP·FN) ÷ √((TP+FP)(TP+FN)(TN+FP)(TN+FN)). It runs from −1 to 1 and stays honest on imbalanced data.
  • For several classes, each class is scored one against the rest. The macro average is the plain mean over classes; the weighted average weights each class by its support. In single-label classification the micro average equals the overall hit rate.

In the label lists, labels may be separated by commas, semicolons, tabs or new lines, so a column pasted from a spreadsheet works as it is. Rows of the matrix are the actual class and columns the predicted one, the layout scikit-learn uses. Numeric labels sort as numbers, so 10 comes after 9.

Edge Cases: 0 ÷ 0, Imbalanced Sets and Mismatched Lists

  • A ratio with nothing in its denominator is shown as undefined, with the reason, never as 0% or 100%. A model that never predicts positive (TP 0, FP 0, FN 5, TN 95) has no precision at all. Its F1 is 0, as scikit-learn reports it. In the class averages an undefined score counts as 0, again matching scikit-learn's default.
  • When fewer than 10% (or more than 90%) of cases are positive and accuracy runs more than 5 points above balanced accuracy, a note appears. Press Load Sample twice for a set where only 1.2% of cases are positive and accuracy is 99.40%, yet a model that always said “negative” would score 98.8%. Recall there is just 66.67%.
  • The two label lists pair up item by item. If their lengths differ you see, for example: “Actual has 12 labels and predicted has 11. They pair up one to one, in the same order, so the counts must match.”
  • Counts must be whole numbers. 1,250 is read as a thousands comma; anything else with a comma is refused. Up to 20,000 labels per list and 30 classes.

Start from

Predicted positive

Predicted negative

Actual positive

Actual negative

Classification metrics

Accuracy

85.00%

(45 + 40) ÷ 100

Precision

90.00%

45 ÷ (45 + 5)

Recall (sensitivity)

81.82%

45 ÷ (45 + 10)

F1 score

85.71%

2×45 ÷ (2×45 + 5 + 10)

Specificity 40 ÷ (40 + 5)88.89%
Negative predictive value 40 ÷ (40 + 10)80.00%
Balanced accuracy (recall + specificity) ÷ 285.35%
False positive rate 5 ÷ (5 + 40)11.11%
False negative rate 10 ÷ (10 + 45)18.18%
Prevalence (45 + 10) ÷ 10055.00%
Matthews correlation (MCC) −1 to 10.7035