Accuracy Calculator
A classifier’s report card starts with four counts — true positives, true negatives, false positives, false negatives — and accuracy is the headline grade: the share of all calls that were right, taken across every case the classifier was shown. This calculator takes the four counts and returns the full transcript: accuracy, error rate, precision, recall, specificity and the F1 score, because the headline alone has misled more projects than any other single number in machine learning, statistics teaching, or applied classification work anywhere.
The Confusion Matrix: Four Counts, Whole Story
Every binary classifier — spam filter, cancer screen, fraud flag, quality gate — sorts the world into four boxes. True positives: flagged, and rightly. True negatives: passed, and rightly. False positives: flagged wrongly (the Type I error, the false alarm). False negatives: missed (the Type II error, the one that got away). Accuracy reads only the diagonal — (TP + TN) ÷ everything — which is precisely its virtue and its blindness: it cannot tell a model that misses disease from a model that cries wolf, when both make the same number of mistakes, even though their consequences in the world may differ by orders of magnitude, by cost, by harm, and by every other measure an application actually cares about. The companion metrics this page computes exist to separate those failures: precision interrogates the positive calls, recall interrogates the positive cases, specificity audits the negative side, and F1 forces precision and recall to be good simultaneously before it applauds.
Worked Example: A Decent, Imperfect Model
The defaults describe a realistic test set of 200: TP 80, TN 70, FP 10, FN 40. Accuracy = 150/200 = 75.0%, error rate 25.0%. The transcript tells the richer story: precision = 80/90 = 88.9% (when it flags, it is usually right); recall = 80/120 = 66.7% (but it lets a third of real cases slip through); specificity = 70/80 = 87.5%; F1 = 76.2%. A manager reading only “75% accurate” cannot tell this model from its mirror image (TP 80, TN 70, FP 40, FN 10 — same accuracy, but trigger-happy rather than timid), while a clinician or a fraud officer cares about nothing but the difference. The four counts cost nothing to report and everything to omit.
The Accuracy Paradox: When 99% Is Worthless
Imbalanced classes make accuracy lie with a straight face. Screen for a condition present in 1% of a population with a “model” that simply declares everyone negative: TP 0, TN 990, FP 0, FN 10 per thousand — accuracy 99.0%, recall exactly 0%, a detector that detects nothing wearing a medal. Real screening targets live at such prevalences, which is why the field reports sensitivity and specificity (recall’s and specificity’s clinical names) and treats accuracy as a courtesy statistic. The paradox’s mirror also exists: at 50% prevalence the same lazy strategy scores 50%, and accuracy behaves again. The calculator’s note raises the class-balance warning on every run, because whether accuracy is a metric or a mirage is decided entirely by the base rate it is quoted against — the false-positive page on this hub devotes itself to that arithmetic.
Choosing Which Metric to Optimise
The metrics disagree because the errors’ costs do, and the costs are the application’s, not the mathematics’. Recall rules where misses are catastrophic (disease screening, safety interlocks, fraud’s first pass) — accept false alarms as the price of catching cases. Precision rules where false alarms are the expensive failure (spam folders eating real mail, trading signals, any alert a human must act on and will learn to ignore). Specificity guards the negative class’s dignity in confirmatory testing. F1 is the compromise candidate when both error types hurt comparably and classes are imbalanced; accuracy suffices only when classes are near-balanced and errors near-symmetric — a legitimate but narrower jurisdiction than its popularity suggests. Report the full transcript, as this page does, and let the application’s costs pick the headline.
Thresholds: The Four Counts Are Chosen, Not Found
Most classifiers output a score, and a threshold converts scores into the calls the matrix counts — which means the four counts, and every metric on this page, are functions of a decision someone made. Tighten the worked example’s threshold (flag only the confident cases) and the counts migrate: TP 80 → 65, FP 10 → 3, FN 40 → 55, TN 70 → 77. The transcript reprices: accuracy falls to 142/200 = 71.0% while precision leaps to 65/68 = 95.6% and recall sinks to 54.2%. Nothing about the underlying model changed — only the trade it was asked to strike between the error types. Comparing two models’ accuracies at unmatched thresholds is therefore meaningless; the transcript must travel with its threshold stated, and serious evaluations sweep the threshold entirely (the ROC curve) rather than grading one chosen point.
Balanced Accuracy: The Standard Repair
When classes are imbalanced and a single accuracy-like number is still demanded, the field’s repair is balanced accuracy: the average of recall and specificity — (66.7 + 87.5)/2 = 77.1% for the worked example, against raw accuracy’s 75.0%. The repair works by grading each class on its own cases before averaging, so the majority class can no longer subsidise the grade; the all-negative fraud of the paradox section scores its balanced accuracy at (0 + 100)/2 = 50%, exposed as the coin-flip it is. Balanced accuracy is not in the calculator’s output row because it deserves its derivation in the open — recall and specificity are printed precisely so the average can be taken knowingly, and any report adopting it should say so by name.
From Counts to Decisions
The transcript’s final use is decision, not description: multiply the counts by the costs of each error in your application and the model’s true price appears — ten false positives at a dollar of review time each against forty false negatives at five hundred dollars of missed fraud each is a $20,010 argument no percentage can make. This is why the calculator insists on the four raw counts as its inputs rather than accepting pre-computed rates: counts compose with costs, thresholds and base rates, while a bare accuracy figure composes with nothing. Keep the counts, and every future question — a new threshold, a new cost structure, a new population — can be answered from the same evidence.
Related Tools
More from the Statistics Calculators hub: the False Positive Calculator — what a positive result is worth at a given prevalence — and the McNemar’s Test Calculator for comparing two classifiers on the same cases.
Frequently Asked Questions
What is the formula for accuracy?
Accuracy = (TP + TN) ÷ (TP + TN + FP + FN): correct calls over all calls — 75.0% in the worked example. Its complement is the error rate. The formula’s simplicity is its danger as much as its appeal: it weights every error identically and every class by its frequency, so quote it with the class balance and at least one of precision or recall beside it.
Accuracy versus precision: what is the difference?
They divide by different worlds. Accuracy divides correct calls by all cases (150/200); precision divides true positives by positive calls only (80/90) — accuracy grades the whole exam, precision grades only the questions the model answered “yes”. A model that flags rarely but wisely can pair modest accuracy with glittering precision, and a model that flags everything achieves perfect recall with precision at the base rate. Neither figure implies the other; the transcript prints both because decisions need both.
What is a good accuracy for a model?
There is no universal bar — the honest comparisons are the baseline (always predicting the majority class: 60% in the worked example’s balance, which the 75% model beats by a real but modest margin), the cost-weighted alternative models, and the application’s requirement. An accuracy below the majority baseline is worse than a coin weighted by class frequencies — an embarrassment the baseline comparison catches instantly and a bare percentage conceals forever, in every domain where these figures are reported to decision-makers.
What is the F1 score, in one sentence?
The harmonic mean of precision and recall — 76.2% here — which punishes lopsidedness: a model with 100% precision and 10% recall earns an F1 of about 18%, not the flattering 55% the ordinary average would report. The harmonic mean’s cruelty is the point: F1 certifies that both virtues are present together, and refuses to let either subsidise the other’s absence.
Can accuracy be computed for multi-class problems?
Yes — the diagonal of the larger confusion matrix over the total — and the companion metrics generalise by averaging per-class precisions and recalls (macro-averaging treats classes equally; micro-averaging pools counts and, for single-label problems, collapses back to accuracy itself). This calculator serves the binary case completely; multi-class work begins from the same four-count logic applied class by class against the rest.
My counts are rates, not counts. Can I still use this?
Scale them to any total (rates per 100 or per 1,000 work directly as counts) — every metric here is a ratio and indifferent to the total, as long as the four entries share one denominator’s world. What cannot be repaired is mixing sources: a sensitivity from one study and a specificity from another describe no single confusion matrix, and the calculator will happily grade the chimera. Four counts, one test set, one threshold — that discipline is the whole game.