Coding Hubs School of AI – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 8448811540
Back to Deep Learning Notes
Topic #334

Accuracy

Accuracy is the simplest classification metric — the fraction of predictions that were correct overall. It's also, famously, the metric most likely to mislead you when classes are imbalanced.

Formula

\[ \text{Accuracy} = \frac{TP+TN}{TP+TN+FP+FN} \]

Numerical Example

Continuing the spam example from Confusion Matrix (TP=24, TN=63, FP=7, FN=6):

\[ \text{Accuracy} = \frac{24+63}{24+63+7+6} = \frac{87}{100} = 0.87 \]

Why Accuracy Can Be Deeply Misleading

Consider a disease that affects only 1% of a population. A classifier that always predicts "no disease," regardless of input, achieves 99% accuracy — an impressive-sounding number that reflects zero actual diagnostic ability. This is exactly the class-imbalance issue previewed in Bayes' Theorem: accuracy alone doesn't distinguish a genuinely capable model from one that's simply exploiting a skewed class distribution.

Code

from sklearn.metrics import accuracy_score

y_true = [1,1,1,1,1,0,0,0,0,0]
y_pred = [1,1,1,0,0,0,0,1,0,0]
print(accuracy_score(y_true, y_pred))   # 0.7 for this small example

When Accuracy Is a Reasonable Metric

SituationIs Accuracy Reasonable?
Roughly balanced classesYes — a fairly informative, easy-to-interpret starting point
Severely imbalanced classesNo — precision, recall, F1, or PR-AUC (covered next) give a far more honest picture
Costs of false positives and false negatives are very differentNo — accuracy treats every error identically, which rarely matches real-world stakes (see the confusion matrix's medical diagnosis example)

Common Mistakes

  • Reporting accuracy as the sole metric on an imbalanced dataset — this is one of the most common and consequential mistakes in applied machine learning, capable of making a genuinely useless model look impressive.
  • Assuming a high accuracy number automatically implies a good model without checking class balance first — always check the confusion matrix and class distribution before trusting accuracy alone.

Interview Relevance

Q: "A fraud-detection model achieves 99.5% accuracy on a dataset where only 0.5% of transactions are actually fraudulent. Should you be impressed?" Not necessarily — a model that always predicts "not fraud" would achieve exactly this accuracy while catching zero actual fraud. This is the classic accuracy-paradox scenario; precision, recall and F1 (or PR-AUC) are needed to understand whether the model is actually detecting fraud, not just exploiting the class imbalance.

Practice Question

Using the confusion matrix from the medical diagnosis practice question in Confusion Matrix, compute the model's accuracy.

Related DL Notes

Want to go beyond the notes?

Join Coding Hubs School of AI's Deep Learning course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →