๐Ÿ”ฅLimited Offer: Get 50% OFFon AI & Full Stack Courses๐Ÿ”ฅ
Back to Deep Learning Notes
Topic #145

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.

Want to go beyond the notes?

Join CodingNow 2.0's Deep Learning course โ€” live mentorship, real projects, and 100% placement support.

Enroll Now โ€” Free Demo Available

Accuracy โ€“ FAQs

Quick answers about learning Accuracy in Deep Learning.

This free note from CodingNow 2.0 explains Accuracy in Deep Learning โ€” concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Deep Learning topic on CodingNow 2.0, including Accuracy, is 100% free with no signup required.
With focused practice, most students grasp Accuracy in 1โ€“3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) โ€” expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now