ThisCalculator

Statistics

Confusion Matrix Accuracy: Formula and Example

Updated · Standard formula, shown below

Accuracy 80.00 %
Total cases
100
Result
True positives
42
You entered
False positives
8
You entered

Confusion Matrix Accuracy: Formula and Example

Confusion matrix accuracy is the share of all predictions that are correct: add the true positives and true negatives, then divide by the total number of cases. Enter those four counts—true positives, false positives, true negatives, and false negatives—to calculate accuracy as a percentage, alongside the total number of predictions.

Formula

Accuracy = (TP + TN) / (TP + FP + TN + FN). To express it as a percentage, multiply the result by 100.

  • TP (true positives): positive cases correctly predicted as positive; a count.
  • TN (true negatives): negative cases correctly predicted as negative; a count.
  • FP (false positives): negative cases incorrectly predicted as positive; a count.
  • FN (false negatives): positive cases incorrectly predicted as negative; a count.

The denominator is the total number of evaluated cases. Counts have no physical unit. The result is a proportion between 0 and 1, or a percentage between 0% and 100%. If the total is zero, accuracy is undefined because the formula would divide by zero.

Worked Example

Using the calculator’s default counts, TP = 42, FP = 8, TN = 38, and FN = 12:

  1. Count the correct predictions: TP + TN = 42 + 38 = 80.
  2. Count all predictions: TP + FP + TN + FN = 42 + 8 + 38 + 12 = 100.
  3. Divide correct predictions by all cases and convert to a percentage: 100 × 80 / 100 = 80.00%.

The total is 100 cases. The model classified 80 correctly and 20 incorrectly, so accuracy is 80.00%.

What the Confusion Matrix Shows

A confusion matrix compares a classifier’s predicted labels with the actual labels. For a binary classification task, it is often shown as a two-by-two table. Its rows and columns are labelled actual and predicted, though which direction is used for rows varies by convention. Read the labels before identifying each cell: the terms TP, FP, TN, and FN are determined by both the actual class and the prediction.

For example, imagine a model that flags transactions as suspicious or not suspicious. A true positive is a suspicious transaction correctly flagged; a false positive is a legitimate transaction flagged by mistake. A false negative is a suspicious transaction the model misses, while a true negative is a legitimate transaction correctly left unflagged. Which class counts as “positive” is a choice made for the task, not necessarily a statement that the class is good or desirable.

When Accuracy Is Useful

Accuracy is a simple summary when the classes are reasonably balanced and the costs of different errors are similar. It can help compare predictions on the same test set, provided the models are evaluated on the same cases and under the same label definitions.

Accuracy does not show which kind of mistake occurred. Two models can have the same accuracy even if one produces many false positives and the other misses many true positives. The consequences of those errors matter in practice, so accuracy is usually one part of an evaluation rather than the only metric.

Common Pitfalls and Better Context

A frequent misconception is that high accuracy always means a useful classifier. Consider a dataset with 990 negative cases and 10 positive cases. A classifier that predicts “negative” every time gets 990 correct out of 1,000, so its accuracy is 99%. Yet it detects none of the positive cases: all 10 are false negatives. If the rare class is important, that result may be inadequate despite the impressive percentage.

For imbalanced classes or unequal error consequences, examine other measures alongside accuracy. Precision, TP / (TP + FP), describes how many predicted positives are actually positive. Recall (also called sensitivity), TP / (TP + FN), describes how many actual positives are found. Specificity, TN / (TN + FP), describes how many actual negatives are correctly identified. These measures can also be undefined when their denominators are zero, so report the counts and explain the evaluation setup.

  • Check the positive-class definition. Swapping which class is positive changes the interpretation of precision, recall, and the confusion-matrix labels.
  • Use one evaluation set consistently. Comparing scores from different samples can confound model performance with differences in the cases tested.
  • Keep counts as counts. Do not enter percentages in place of the four cell counts. If you have normalized rates instead, this calculator’s total-count interpretation may not apply.
  • Round only the displayed result. A rounded percentage can conceal small differences, especially with a small sample. Retain the underlying counts when reporting results.
  • Check that cells add up. The four counts should sum to the number of cases included in the evaluation, with each case assigned to one cell.

Accuracy describes performance on the evaluated data; it does not by itself establish how well a model will perform on future cases. Its value depends on representative data, consistent labels, and a clearly stated evaluation method. For a multiclass confusion matrix, the same basic idea applies: sum the diagonal cells (correct predictions) and divide by the sum of all cells. The four-input calculator above is specifically for a binary matrix.

Frequently Asked Questions

Can accuracy be calculated from only true positives and true negatives?
Not unless you also know the total number of cases, or enough information to derive it. Accuracy is (TP + TN) divided by TP + FP + TN + FN; omitting false positives and false negatives can leave the denominator unknown.

Is accuracy the same as precision?
No. Accuracy is the fraction of all cases classified correctly. Precision is the fraction of predicted-positive cases that are truly positive: TP / (TP + FP).

Can a confusion-matrix accuracy be 100%?
Yes. It is 100% when every evaluated case is correctly classified, so FP and FN are both zero and TP + TN equals the total. This describes the evaluated set and does not guarantee perfect performance on other data.

What if the confusion matrix has no cases?
Accuracy is undefined when all four counts are zero, because the total-case denominator is zero. Do not report it as 0%; there were no evaluated predictions from which to calculate a rate.

How do I calculate accuracy for a multiclass confusion matrix?
Add the counts on the main diagonal, where predicted and actual classes match, and divide by the sum of every cell. Multiply by 100 for a percentage. State the class order and evaluation set so the result is interpretable.

Related

Formula used
in tp | True positives | - | 42 | 0
in fp | False positives | - | 8 | 0
in tn | True negatives | - | 38 | 0
in fn | False negatives | - | 12 | 0
out acc | Accuracy | % | 100 * (tp + tn) / (tp + fp + tn + fn) | 2
out total | Total cases | - | tp + fp + tn + fn | 0

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.