Accuracy

What Is Accuracy?

Accuracy is an evaluation metric that measures the percentage of predictions a model gets correct.

Formula

Accuracy = Correct Predictions / Total Predictions

Example: Correct Predictions = 85, Total Predictions = 100 → Accuracy = 85%

Accuracy answers the question: out of all predictions, how many were correct?

Why Accuracy Matters

Accuracy is useful because it gives a simple overall measure of model performance. It is easy to understand and easy to communicate.

Example

A model has 90% accuracy — the model is correct 90 out of 100 times.

Accuracy can be helpful when all classes are balanced and all mistakes have similar importance.

Accuracy Formula

The basic formula for accuracy divides the number of correct predictions by the total number of predictions.

Calculation
  • Correct Predictions: 80
  • Total Predictions: 100
  • Accuracy = 80 / 100 = 0.80
  • Accuracy Percentage: 80%

Accuracy Example

Imagine a model predicts whether emails are spam or not spam.

Spam Detection
  • Total Emails: 10
  • Correct Predictions: 8
  • Incorrect Predictions: 2
  • Accuracy = 8 / 10 = 80%

The model correctly classified 80% of the emails.

Correct vs Incorrect Predictions

A correct prediction means the model's prediction matches the true label. An incorrect prediction means the prediction does not match.

Correct Example

True Label: Spam

Prediction: Spam

Result: Correct

Incorrect Example

True Label: Spam

Prediction: Not Spam

Result: Incorrect

Accuracy in Binary Classification

Binary classification has two possible classes. Accuracy counts all correct predictions across both classes.

Binary Classification Examples
  • Spam or Not Spam
  • Fraud or Not Fraud
  • Disease or No Disease
  • Pass or Fail

Total Predictions = 200, Correct Predictions = 170 → Accuracy = 85%

Accuracy in Multi-Class Classification

Multi-class classification has more than two possible classes. Accuracy still counts how many predictions match the correct labels.

Multi-Class Examples
  • Cat, Dog, Bird
  • Red, Blue, Green
  • Low, Medium, High
  • A, B, C, D, F

Total Images = 500, Correct Labels = 425 → Accuracy = 85%

Accuracy and the Confusion Matrix

A confusion matrix shows correct and incorrect predictions by category. For binary classification, accuracy uses all four parts.

Confusion Matrix Terms
  • True Positives
  • False Positives
  • True Negatives
  • False Negatives

Accuracy = (True Positives + True Negatives) / Total Predictions

True Positives

A true positive happens when the model predicts positive and the true label is also positive.

Medical Diagnosis Example
  • Prediction: Disease Present
  • True Label: Disease Present
  • Result: True Positive

True Negatives

A true negative happens when the model predicts negative and the true label is also negative.

Medical Diagnosis Example
  • Prediction: No Disease
  • True Label: No Disease
  • Result: True Negative

False Positives

A false positive happens when the model predicts positive, but the true label is negative.

Medical Diagnosis Example
  • Prediction: Disease Present
  • True Label: No Disease
  • Result: False Positive

False Negatives

A false negative happens when the model predicts negative, but the true label is positive.

Medical Diagnosis Example
  • Prediction: No Disease
  • True Label: Disease Present
  • Result: False Negative

Confusion Matrix Accuracy Example

Accuracy counts both correctly predicted positives and correctly predicted negatives.

Disease Detection Model
  • True Positives: 40
  • True Negatives: 50
  • False Positives: 5
  • False Negatives: 5
  • Total Predictions: 100
  • Accuracy = (40 + 50) / 100 = 90%

When Accuracy Is Useful

Accuracy is most useful when the classes are balanced and different mistakes have similar costs.

Accuracy Is Useful When
  • Classes are balanced
  • Mistakes have similar costs
  • The goal is overall correctness
  • The dataset represents the real world well
  • False positives and false negatives are equally important

When Accuracy Can Be Misleading

Accuracy can be misleading when classes are imbalanced. In an imbalanced dataset, one class appears much more often than another.

Fraud Detection Dataset
  • Normal Transactions: 99%
  • Fraud Transactions: 1%
  • Model Predicts: Everything is normal
  • Accuracy: 99%
  • Fraud Detected: 0%

The model has high accuracy but is not useful.

Accuracy and Class Imbalance

Class imbalance can hide poor performance on the smaller class.

Example
  • Dataset: 950 normal transactions, 50 fraud transactions
  • Model predicts: all transactions are normal
  • Correct Predictions: 950
  • Accuracy: 95%
  • Problem: The model catches no fraud.

Accuracy vs Precision

Accuracy measures overall correctness. Precision measures how many predicted positives were actually positive.

Accuracy Asks

Out of all predictions, how many were correct?

Precision Asks

Out of all positive predictions, how many were actually positive?

Accuracy vs Recall

Recall measures how many actual positives were found. It is important when missing positives is costly.

Accuracy Asks

Out of all predictions, how many were correct?

Recall Asks

Out of all actual positives, how many did the model catch?

If there are 100 fraud cases and the model finds 60, recall is 60%.

Accuracy vs F1 Score

F1 score balances precision and recall. It is often useful when classes are imbalanced or when both false positives and false negatives matter.

Metric Comparison
  • Accuracy — Overall correctness
  • Precision — Quality of positive predictions
  • Recall — Ability to find actual positives
  • F1 Score — Balance between precision and recall

Accuracy in Medical Diagnosis

Accuracy can be helpful in medical diagnosis, but it is not always enough.

Rare Disease Example
  • Disease Rate: 1%
  • Model Predicts: Everyone is healthy
  • Accuracy: 99%
  • Problem: The model detects none of the sick patients.

In this case, recall may be more important because missing a disease can be dangerous.

Accuracy in Spam Detection

Accuracy can be useful in spam detection, but false positives and false negatives still matter.

Spam Tradeoffs
  • False Positive — Important email marked as spam
  • False Negative — Spam email allowed into inbox

Accuracy should be considered with precision and recall.

Accuracy in Image Classification

Accuracy is often useful in image classification when classes are balanced.

Example
  • Dataset: 1,000 cat images, 1,000 dog images
  • Correct Predictions: 1,800
  • Total Images: 2,000
  • Accuracy: 90%

Accuracy in Student Performance Models

A model may predict whether students pass or fail. If most students pass, accuracy can hide poor performance on students who need help.

Example
  • Pass: 95%, Fail: 5%
  • Model predicts: All students pass
  • Accuracy: 95%
  • Problem: The model does not identify students who may need support.

Training Accuracy vs Test Accuracy

Training accuracy measures accuracy on training data. Test accuracy measures accuracy on unseen test data.

Example
  • Training Accuracy: 98%
  • Test Accuracy: 72%
  • Possible Meaning: The model may be overfitting.

Good Accuracy Pattern

A good pattern is when both training and test accuracy are strong and close together.

Good Pattern
  • Training Accuracy: 91%
  • Test Accuracy: 89%
  • Meaning: The model learned useful patterns and generalizes well.

Poor Accuracy Patterns

Poor accuracy patterns can suggest overfitting, underfitting, or weak model performance.

Pattern Examples
  • Overfitting — Training: 99%, Test: 65%
  • Underfitting — Training: 58%, Test: 56%
  • Weak but Consistent — Training: 74%, Test: 73%

Accuracy and Generalization

Accuracy on unseen data helps measure generalization — the model's ability to perform well on new examples.

Poor Generalization

High Training Accuracy + Low Test Accuracy

Model memorized training data.

Good Generalization

Strong Test Accuracy

Better sign of real-world usefulness.

How to Improve Accuracy

There are several ways to improve accuracy, depending on the problem and the model.

Ways to Improve Accuracy
  • Collect more training data
  • Clean the dataset
  • Fix incorrect labels
  • Add useful features
  • Remove irrelevant features
  • Choose a better algorithm
  • Tune hyperparameters
  • Reduce overfitting
  • Reduce underfitting
  • Balance the dataset if needed

Limits of Accuracy

Accuracy is simple and useful, but it does not explain everything about model performance.

Accuracy Does Not Show
  • Which classes are being missed
  • Whether false positives are common
  • Whether false negatives are common
  • Whether performance is fair across groups
  • Whether the model works well on rare cases
  • Whether mistakes have serious consequences

Accuracy Summary

Core Idea

Accuracy is the percentage of correct predictions.

Formula: Accuracy = Correct Predictions / Total Predictions

  • Best Used When — Classes are balanced and mistakes have similar costs
  • Use Carefully When — Data is imbalanced or some mistakes are more serious

Summary

Key Takeaways
  • Accuracy measures the percentage of correct predictions.
  • Accuracy is calculated by dividing correct predictions by total predictions.
  • Accuracy is common in classification tasks.
  • Accuracy can be used for binary and multi-class classification.
  • Accuracy is easy to understand.
  • Accuracy works best when classes are balanced.
  • Accuracy can be misleading with imbalanced data.
  • High accuracy does not always mean a useful model.
  • Accuracy should often be used with precision, recall, F1 score, and a confusion matrix.

Practice Prompt

A fraud detection model has 95% accuracy because it predicts every transaction as normal. The dataset contains 950 normal transactions and 50 fraud transactions.

Explain why the accuracy is high, why the model is still not useful, and which metric might help evaluate fraud detection better.

Need Help?

Ask the AI if you need help understanding accuracy, correct predictions, confusion matrices, class imbalance, precision, recall, or why accuracy alone is not always enough.