Art of DS

Appearance

Palette
Theme
Unlock $20 one time
Sign in, or create an account

Sign in to Art of DSCreate your Art of DS account

We email you a link and a six-digit code. Either one signs you in; there is no password.Enter your email. We send a link and a six-digit code to confirm it — no password to remember. The account is free.

  • You come back to this page, right where you were.
  • Already have an account? The same email simply signs you in.

By continuing you accept the Terms and the Privacy policy.

Your account

Free accountLifetime access

difficulty 1/5 Free

Accuracy

Definition

The fraction of predictions a classifier got right — correct predictions divided by total predictions.

Formula
Accuracy=TP+TNTP+TN+FP+FN\text{Accuracy} = \frac{TP + TN}{TP + TN + FP + FN}

Intuition

Count how many predictions were right, divide by how many you made. That is accuracy, and it is the first metric everybody reaches for because it is the one that needs no explanation.

It is also the one most likely to mislead you, for a single reason: it treats every mistake as identical and every class as equally common. Both assumptions fail routinely.

Formal definition

scikit-learn computes the fraction of correctly classified samples [1, definition]. In terms of the confusion matrix, it is the diagonal divided by the whole table.

With normalize=False the same function returns the raw count instead of the fraction [1, normalize].

In multilabel problems it becomes subset accuracy: the predicted label set must match the true label set exactly, which is a far stricter test than it sounds [1, definition].

How it works

thresholdactually negativeactually positiveTNFPFNTP
Two populations overlap, and one threshold has to separate them. As it sweeps, every confusion-matrix count changes at once: move it left to catch more true positives and the false positives rise with them. The overlap is why no threshold makes all four cells good — that is a property of the data, not of the model.

Accuracy is one number summarising the entire confusion matrix, which means it compresses four counts into one — and compression loses information. Two models with identical accuracy can behave in opposite ways: one refusing to predict the positive class at all, the other flagging everything.

Where it's used

  • Balanced benchmarks. Where classes are roughly equal and errors cost the same, accuracy is a fair summary and an easy one to communicate.
  • A first sanity check. Comparing accuracy against the majority-class base rate tells you immediately whether a model has learned anything.
  • Reporting to non-specialists. It is the only classification metric that needs no preamble.

Why & when

Use it when the classes are balanced and the two kinds of error cost about the same. Under those conditions it is genuinely the right summary.

Reach for something else the moment the data is skewed. In a dataset that is 99% negative, predicting "negative" every time scores 99% accuracy while being completely useless [4, §8.3]. Precision, recall and the confusion matrix are what survive class imbalance; accuracy does not [2, Accuracy].

Worked example

Python 9 lines Show the code Hide the code
from sklearn.metrics import accuracy_score

y_pred = [0, 2, 1, 3]
y_true = [0, 1, 2, 3]

accuracy_score(y_true, y_pred)
# 0.5
accuracy_score(y_true, y_pred, normalize=False)
# 2.0

Two of four predictions are correct — positions 0 and 3 — so accuracy is 0.5 [1, examples]. Note that the two wrong predictions were a straight swap of classes 1 and 2, which accuracy cannot show you and a confusion matrix would.

Pitfalls

Always compare against the base rate. An accuracy of 95% is excellent if the majority class is 50% of the data and worthless if it is 96%. The number alone is uninterpretable [2, Accuracy].

Accuracy hides which error the model makes. Two models with the same accuracy can fail in opposite ways — one missing the positives, the other raising false alarms — and when one kind of mistake costs more than the other, which is "the case in most real-world applications", that difference is the whole question [2, Accuracy].

It ignores confidence entirely. A prediction made at 51% certainty counts exactly like one made at 99% [3, classification threshold]. If calibrated probabilities matter to your decision, accuracy is not measuring the thing you care about.

Not read yetReach the end of the page and it counts as read.

Keep your progressWith lifetime access, every page you finish is marked and you pick up where you stopped, on all your devices.

Unlock

Check yourself

3 questions

Each answer is explained, with the section it tests and its source.

On the cheat sheet: Classification metrics →

Sources

  1. scikit-learn — sklearn.metrics.accuracy_scoredocs · retrieved 2026-08-30https://scikit-learn.org/stable/modules/generated/sklearn.metrics.accuracy_score.html
  2. Google. Machine Learning Crash Course — Classification: accuracy, recall, precision, and related metricscourse · retrieved 2026-10-04https://developers.google.com/machine-learning/crash-course/classification/accuracy-precision-recall
  3. Google. Machine Learning Crash Course — Thresholds and the confusion matrixcourse · retrieved 2026-10-04https://developers.google.com/machine-learning/crash-course/classification/thresholding
  4. Manning, Raghavan, Schütze. Introduction to Information Retrieval (2008)bookhttps://nlp.stanford.edu/IR-book/html/htmledition/irbook.html

Have a promo code?

A code that takes 100% off unlocks everything at once. A smaller one takes its share off the price in the payment window: enter the same code there.

Write to support

A question, a problem with access, a refund? Write to us and we answer by email.

What is it about?

Your address is used only to answer you.

Message sent

Thank you. We will reply to the address you gave, by email.

Or write to us directly

support@artofds.com

Message sent Thank you. We will reply to the address you gave, by email.

Check the email address: we need it to reply.

That is our own address. Enter yours, so the reply reaches you.

This address cannot receive email. Check it for a typo.

Write a little more: at least 10 characters.

Too many messages in a short time. Try again in a few minutes.

The message could not be sent. Please write to us directly: support@artofds.com