About Confusion Matrix Calculator
This confusion matrix calculator is free, needs no sign-up and runs in your browser, so your results are never uploaded. Type the counts of a binary or multi-class confusion matrix, or paste two columns of actual and predicted labels and let the tool build the matrix for you. It then reports accuracy, precision, recall, specificity, F1, F-beta, the Matthews correlation coefficient (MCC), Cohen's kappa and balanced accuracy.
For more than two classes you get a row of metrics for each class, treating that class as positive and all others as negative, plus macro, micro and weighted averages. The headline metric you pick is explained in plain English and worked through with your own numbers, so you can check a result or copy the method into a report.
A confusion matrix is the honest summary of a classifier. A single accuracy number hides which mistakes the model makes, and on imbalanced data it can look excellent while the model finds none of the rare class. Reading precision and recall together, or a balanced measure such as MCC, shows what accuracy conceals.
How to use Confusion Matrix Calculator
- Choose "Matrix counts" and set the number of classes, or choose "Actual and predicted labels" and paste the two lists.
- In matrix mode, rows are the actual class and columns the predicted class. Edit the cells and the class names.
- Pick the headline metric: accuracy, precision, recall, specificity, F1, F-beta, MCC, kappa or balanced accuracy.
- For precision, recall and F-scores, choose which class counts as positive. With two classes the first class is the positive one.
- Read the headline value and its explanation, then scroll to the per-class table, the averages and the worked steps.
- Use the copy button to take the metrics into your notes or report.
Features
- Binary and multi-class matrices up to 8 classes, or up to 12 classes built from pasted labels.
- Accuracy, precision, recall, specificity, F1, F-beta, MCC, Cohen's kappa and balanced accuracy in one place.
- Per-class true positive, false positive, false negative and true negative counts.
- Macro, micro and weighted averages for multi-class problems, so you can see how each differs.
- Worked steps with your numbers substituted into every formula, and the formulas rendered in LaTeX.
- A ratio with a zero denominator is shown as n/a instead of a misleading 0.
- Plain-English reading of the headline metric, including a warning about accuracy on imbalanced data.
- Editable class names, so the output reads like your own problem.
Formulas used
Every binary metric comes from four counts: true positives (TP), false positives (FP), false negatives (FN) and true negatives (TN). For a multi-class matrix each class is scored against all the others, which gives it its own four counts.
MCC for more than two classes uses the Gorodkin generalisation, which equals the usual formula when there are two classes. Macro averages give each class equal weight, micro averages pool all the counts, and weighted averages weight each class by how many true cases it has.
accuracy = (TP + TN) / (TP + TN + FP + FN)
precision = TP / (TP + FP)
recall = TP / (TP + FN)
specificity = TN / (TN + FP)
F1 = 2 P R / (P + R)
Fbeta = (1 + b^2) P R / (b^2 P + R)
MCC = (TP TN - FP FN) / sqrt((TP+FP)(TP+FN)(TN+FP)(TN+FN))
kappa = (po - pe) / (1 - pe)Worked examples
TP 40, FN 10, FP 5, TN 45 gives accuracy 0.85, precision 0.8889, recall 0.8
F1 is 0.8421, MCC is 0.7035 and kappa is 0.7. Precision is 40 / 45 because 45 cases were predicted positive.
TP 1, FN 9, FP 0, TN 90 (a rare disease) gives accuracy 0.91, recall 0.1
The model looks 91% accurate yet finds only one of ten sick people. Balanced accuracy is 0.55 and MCC is 0.3015.
Three classes: cat, dog, bird, 60 images gives accuracy 0.85, macro F1 0.8489
Micro F1 equals accuracy (0.85) for single-label problems, while weighted F1 is 0.8489.
Which metric answers which question
| Metric | Question it answers | Weak spot |
|---|---|---|
| Accuracy | How often is the model right overall? | Misleading when one class is rare |
| Precision | When it says positive, how often is it right? | Ignores missed positives |
| Recall | Of the real positives, how many did it find? | Ignores false alarms |
| Specificity | Of the real negatives, how many did it clear? | Ignores missed positives |
| F1 | Is there a balance of precision and recall? | Ignores true negatives |
| MCC | How strong is the overall relationship? | One number hides which error dominates |
| Cohen's kappa | How much better than chance agreement? | Depends on class frequencies |
| Balanced accuracy | Average recall across classes | Ignores precision |
Good to know
Reading the matrix: rows are actual, columns are predicted
Some libraries put actual classes on the columns instead. This tool follows the scikit-learn convention: rows are the true class and columns are the predicted class, so the diagonal holds the correct predictions and each off-diagonal cell counts one specific kind of mistake.
If your matrix comes from a tool that uses the other orientation, transpose it before entering it, or precision and recall will swap places.
Macro, micro and weighted averages
A macro average treats every class equally, so a rare class with poor results pulls it down. A micro average pools every prediction and for a single-label problem equals accuracy. A weighted average weights each class by its number of true cases, so it follows the common classes. Report the one that matches your goal, and say which it is.
Privacy: how it works
- The matrix and labels you enter are processed by code running in your browser tab. They are not sent to Ulkaa or anyone else.
Tips
- Do not rely on accuracy alone when one class is much rarer than the others. Check recall for that class and the MCC.
- Precision and recall trade against each other. Moving a classifier's decision threshold raises one and lowers the other; the ROC and AUC calculator shows the whole trade-off.
- F1 gives equal weight to precision and recall. Use F-beta with beta above 1 when missing a positive is worse than a false alarm, and below 1 when the reverse is true.
- A metric with an empty denominator, such as precision for a class never predicted, is shown as n/a and left out of macro averages.
Frequently asked questions
Is it really free?
Yes. There is no price, no trial and no credit card. Ulkaa Tool does the work with your own device, so there is no server bill to pass on to you.
Do I need an account?
No. There is no sign-up and no login. Open the page and use it. An Ulkaa account is not needed for anything on this tool.
Does it run in my browser?
Yes. Your matrix and labels are processed by code running in your browser tab, on your own device.
Is my data uploaded?
No. Your matrix and labels are never sent to Ulkaa or to anyone else. You can check this yourself by watching the Network tab in your browser developer tools while you use the tool.
What is a confusion matrix?
A table that counts how often each actual class was predicted as each class. For two classes it holds true positives, false positives, false negatives and true negatives. The diagonal is correct predictions; everything else is a mistake of a specific kind.
How do I calculate precision and recall from a confusion matrix?
Precision is TP divided by TP plus FP, the share of positive predictions that were right. Recall is TP divided by TP plus FN, the share of real positives that were found. For 40 true positives, 5 false positives and 10 false negatives, precision is 0.889 and recall is 0.8.
What is the difference between accuracy and F1?
Accuracy counts all correct predictions, including true negatives. F1 is the harmonic mean of precision and recall and ignores true negatives, so it is more informative when positives are rare.
When should I use MCC instead of F1?
Use MCC when you want one number that uses all four counts and stays honest on imbalanced data. It ranges from -1 to +1, and 0 means no better than chance. F1 can look good when a model simply predicts the majority class.
How does this tool handle more than two classes?
Each class is scored as positive against the rest, and the tool shows macro, micro and weighted averages. MCC uses the multi-class Gorodkin formula and kappa uses the full matrix.
What does n/a mean in the results?
The denominator of that ratio is zero, so the value is undefined. For example, precision for a class that was never predicted. The tool does not turn it into 0.
Can I paste actual and predicted labels instead of counts?
Yes. Choose the labels mode and paste two lists in the same order, separated by commas or new lines. The matrix is built for you, with up to 12 distinct classes.
What is Cohen's kappa?
Kappa measures agreement between predictions and truth after removing the agreement expected by chance. A value of 0 is chance level and 1 is perfect agreement.
Popular Confusion Matrix Calculator pages
- Precision and Recall CalculatorEnter your confusion matrix to get precision and recall with the formula worked through.
- F1 Score CalculatorGet the F1 score of a classifier from its confusion matrix, with every step shown.
- Classification Accuracy CalculatorWork out accuracy from a confusion matrix and see when it misleads.
- MCC Calculator (Matthews Correlation Coefficient)Compute the MCC of a classifier from its confusion matrix, with the formula substituted.
- Cohen's Kappa CalculatorMeasure agreement beyond chance between two raters or between a model and the truth.
- Sensitivity and Specificity CalculatorEnter a test's counts to get sensitivity (recall) and specificity, with the working shown.
- F-beta Score CalculatorChoose beta to weight recall or precision more, and get the F-beta score with its working.
- Balanced Accuracy CalculatorAverage the recall of every class so a rare class counts as much as a common one.
- Multi-class Confusion Matrix CalculatorScore a classifier with three or more classes, class by class and on average.
- Confusion Matrix From Actual and Predicted LabelsPaste the true labels and the predictions and get the matrix and its metrics.