Confusion Matrix Calculator: F1, Precision, Recall, MCC

Enter TP, FP, FN and TN, or a 3 to 8 class matrix, to get accuracy, precision, recall, F1, F-beta, MCC, Cohen's kappa and balanced accuracy with the formula behind each number.

Last updatedHow we build & check our tools
Results will appear here once you enter your values.

How the calculator works

In Binary mode you type the four cells of a 2 by 2 confusion matrix. Every metric is computed from those counts with the standard scikit-learn definitions, and any ratio whose denominator is 0 is shown as n/a instead of NaN, with a note explaining why.

  • Precision = TP / (TP + FP)
  • Recall (sensitivity) = TP / (TP + FN)
  • Specificity = TN / (TN + FP)
  • F1 = 2TP / (2TP + FP + FN)
  • F-beta = (1 + b2)TP / ((1 + b2)TP + b2 FN + FP), where b2 is beta squared
  • MCC = (TP x TN - FP x FN) / sqrt((TP + FP)(TP + FN)(TN + FP)(TN + FN))

In Multi-class mode you pick 3 to 8 classes, name them, and fill a grid where rows are the actual class and columns the predicted class. You get a per-class precision, recall and F1 report, macro, weighted and micro averages, balanced accuracy, Cohen's kappa and Gorodkin's multi-class MCC.

Worked example with the default numbers

The defaults describe 1,000 samples: TP = 85, FP = 15, FN = 10, TN = 890. Prevalence is 95 / 1,000 = 9.5%, so this is an imbalanced problem.

  • Accuracy = (85 + 890) / 1,000 = 97.5%
  • Precision = 85 / 100 = 85.0%
  • Recall = 85 / 95 = 89.5%
  • Specificity = 890 / 905 = 98.3%
  • F1 = 170 / 195 = 87.2%
  • F2 (beta = 2) = 425 / 480 = 88.5%
  • MCC = (75,650 - 150) / sqrt(100 x 95 x 905 x 900) = 0.858
  • Balanced accuracy = 93.9%, Cohen's kappa = 0.858

Accuracy looks best here because 890 easy true negatives inflate it. F1, MCC and balanced accuracy all tell a more modest story about how well the positive class is handled.

Common mistakes

Trusting accuracy on skewed data. A model that predicts negative for every sample in a set with 100 positives and 900 negatives scores 90% accuracy, yet its recall and F1 are 0, its balanced accuracy is 50% and its MCC has no value. The calculator warns you when accuracy runs more than 10 points above balanced accuracy.

Swapping FP and FN. A false positive is an actual negative that was predicted positive. Mixing them up swaps precision and recall. In the multi-class grid, rows are always the actual class.

Comparing averages that differ. Macro averages treat every class equally, weighted averages weight by support, and micro F1 equals accuracy for single-label problems. This tool skips classes whose score has no value when averaging, while scikit-learn counts them as 0 by default through zero_division, so its macro scores can be lower.

Tips for choosing a metric

Pick the metric that matches the cost of each error. When a missed positive is expensive, such as a disease screen or fraud alert, raise beta above 1 so F-beta weights recall more. When false alarms are expensive, use beta below 1.

  • Report MCC alongside F1. Chicco and Jurman (2020) argue MCC is more informative because it only scores high when both the positive and negative classes are predicted well.
  • F1 ignores true negatives entirely, so adding 10,000 more correct negatives leaves it unchanged.
  • Use balanced accuracy or macro F1 for multi-class sets where one class dominates.
  • Kappa and MCC range from -1 to 1, where 0 means no better than chance.

Frequently Asked Questions

Common questions about the Confusion Matrix Calculator: F1, Precision, Recall, MCC

F1 is the harmonic mean of precision and recall, which simplifies to 2TP divided by (2TP + FP + FN). With TP = 85, FP = 15 and FN = 10, F1 is 170 divided by 195, or about 0.872. True negatives do not appear in the formula at all, which is why F1 can hide poor performance on the negative class.
From the same team

Stop paying per token — route AI requests to your own GPU

Wide Area AI is a local-first AI gateway: repeated requests hit an edge cache, the rest run free on your own hardware, and the cloud is only a failover. OpenAI-compatible endpoint, free tier.

Start routing — free

Sources & References

scikit-learn User Guide: Classification metrics

Standard definitions of precision, recall, F-beta, averaging modes and zero_division.

Chicco and Jurman (2020), The advantages of the Matthews correlation coefficient (MCC) over F1 score and accuracy in binary classification evaluation, BMC Genomics

Argument for MCC over F1 and accuracy on imbalanced binary data.

scikit-learn API: matthews_corrcoef

Multi-class MCC formula used by the calculator.

Explore More Tools

Explore these related tools for your next step.

ai

AI Background Remover

Remove image backgrounds instantly in your browser — no upload, no signup, no watermark. Get a transparent PNG, solid-color, or blurred background, with the AI model running entirely on your device so your photos never leave it.

Try it now
ai

Private OCR — Image to Text Converter

Extract text from images and screenshots entirely in your browser. Paste a screenshot or drop image files, pick from 11 languages, and get editable text with per-word confidence highlighting — 100% private, nothing is ever uploaded.

Try it now
ai

Private Text-to-Speech (In-Browser TTS)

Turn text into natural-sounding speech entirely in your browser. Use instant built-in browser voices, or a high-quality downloadable AI neural voice (Kokoro-82M) — nothing you type ever leaves your device.

Try it now
ai

Private AI Translator (In-Browser, Offline)

Translate text between 13 languages with Helsinki-NLP opus-mt models that run entirely in your browser. Nothing is uploaded, and it keeps working offline once a language model has downloaded.

Try it now
ai

Batch AI Processor — Run a Prompt Over Every CSV Row Locally

Run one AI prompt across every row of a CSV or spreadsheet entirely in your browser with a local LLM. Classify, extract, summarize, or reformat thousands of rows with zero API costs and zero data sharing.

Try it now
ai

LLM Structured Output Builder

Visually build a JSON Schema and instantly generate OpenAI structured outputs, OpenAI/Anthropic tool definitions, Zod, and Pydantic code — plus validate sample responses and import existing schemas. 100% in-browser; nothing you type is uploaded.

Try it now