Classification Metrics

What Are Classification Metrics?

Classification metrics are used to evaluate models that predict categories. These models assign each example to a class or label.

Classification Examples
  • Spam or Not Spam
  • Fraud or Not Fraud
  • Disease or No Disease
  • Cat, Dog, or Bird
  • Pass or Fail
  • Positive, Negative, or Neutral

Classification metrics help answer: how well is the model assigning examples to the correct category?

Why Classification Metrics Matter

One score is not always enough to understand model performance. A model may have high accuracy but still perform poorly on the most important class.

Fraud Detection Dataset
  • Normal Transactions: 99%
  • Fraud Transactions: 1%
  • Model: Predicts everything as normal
  • Accuracy: 99%
  • Fraud Caught: 0%

High accuracy does not mean the model is useful.

Accuracy

Accuracy measures the percentage of correct predictions.

Formula

Accuracy = Correct Predictions / Total Predictions

  • Correct Predictions: 90
  • Total Predictions: 100
  • Accuracy: 90 / 100 = 90%

Accuracy is easy to understand, but it can be misleading when the dataset is imbalanced.

When Accuracy Is Useful

Accuracy Is Useful When
  • Classes are balanced
  • Mistakes have similar costs
  • You want an overall correctness score
  • The dataset represents the real-world problem well

Example: A cat vs dog classifier with 50% cats and 50% dogs.

When Accuracy Is Not Enough

Accuracy is not enough when one class is much more common than another or when different mistakes have different consequences.

Rare Disease Example
  • Disease Rate: 1%
  • Model: Predicts everyone is healthy
  • Accuracy: 99%
  • Problem: The model finds no sick patients.

Precision

Precision measures how many predicted positives were actually positive.

Formula

Precision = True Positives / (True Positives + False Positives)

Precision asks: When the model predicted positive, how often was it correct?

  • Predicted Spam: 100
  • Actually Spam: 80
  • Precision: 80%

When Precision Matters

Precision matters when positive predictions should be trustworthy and false positives are costly.

Precision Matters For
  • Spam detection — avoid marking important emails as spam
  • Fraud alerts — avoid blocking normal transactions
  • Hiring screening — avoid recommending weak candidates
  • Search results — avoid showing irrelevant results

High precision means fewer false alarms.

Recall

Recall measures how many actual positives were found.

Formula

Recall = True Positives / (True Positives + False Negatives)

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

  • Actual Fraud Cases: 100
  • Found by Model: 70
  • Recall: 70%

When Recall Matters

Recall matters when missing a positive case is risky or costly.

Recall Matters For
  • Disease detection — avoid missing sick patients
  • Fraud detection — avoid missing fraudulent transactions
  • Safety systems — avoid missing dangerous events
  • Cybersecurity alerts — avoid missing attacks

High recall means fewer missed positives.

F1 Score

F1 score combines precision and recall into one balanced score.

Formula

F1 Score = 2 × (Precision × Recall) / (Precision + Recall)

  • Precision = 0.80, Recall = 0.60
  • F1 Score = 2 × (0.80 × 0.60) / (0.80 + 0.60)
  • F1 Score = 68.6%

The F1 score is lower when either precision or recall is weak.

Why F1 Score Matters

F1 score is useful when both false positives and false negatives matter. It is also helpful for imbalanced datasets.

Fraud Detection
  • Precision — How many fraud alerts were truly fraud?
  • Recall — How many fraud cases were found?
  • F1 Score — Balances both.

ROC-AUC

ROC-AUC measures how well a classification model separates positive and negative classes.

What It Stands For
  • ROC — Receiver Operating Characteristic
  • AUC — Area Under the Curve

Main idea: How well can the model rank positive examples higher than negative examples?

A higher ROC-AUC means the model is better at separating the classes.

ROC-AUC Score Range

Score Meanings
  • ROC-AUC = 1.0 — Perfect separation
  • ROC-AUC = 0.5 — No better than random guessing
  • ROC-AUC below 0.5 — Worse than random guessing
  • Example — ROC-AUC = 0.92 means very good class separation

Why ROC-AUC Is Useful

ROC-AUC is useful because it evaluates performance across many classification thresholds.

Example
  • Fraud Probability: 0.83
  • Default Threshold: 0.50
  • ROC-AUC checks how well the model separates classes across different thresholds.

Classification Thresholds

A classification threshold decides when a model predicts the positive class.

Example
  • Disease Probability: 0.70
  • Threshold: 0.50
  • Prediction: Disease Present

Raising the threshold makes the model stricter. Lowering it makes the model predict positive more often.

Threshold Tradeoff

Changing the threshold affects precision and recall.

Lower Threshold
  • More positive predictions
  • Higher recall
  • Lower precision
Higher Threshold
  • Fewer positive predictions
  • Higher precision
  • Lower recall

Confusion Matrix

A confusion matrix organizes classification results into four parts. Many classification metrics are calculated from it.

The Four Parts
  • True Positive — Predicted positive, actually positive
  • False Positive — Predicted positive, actually negative
  • True Negative — Predicted negative, actually negative
  • False Negative — Predicted negative, actually positive

Confusion Matrix Example

Disease Detection (100 patients)
  • True Positives: 40
  • False Positives: 10
  • True Negatives: 45
  • False Negatives: 5
  • Accuracy: (40 + 45) / 100 = 85%
  • Precision: 40 / (40 + 10) = 80%
  • Recall: 40 / (40 + 5) = 88.9%

Classification Metrics Compared

MetricWhat It Answers
AccuracyHow many predictions were correct overall?
PrecisionHow trustworthy are positive predictions?
RecallHow many actual positives were found?
F1 ScoreHow well are precision and recall balanced?
ROC-AUCHow well does the model separate classes?

Choosing the Right Metric

Metric Selection Guide
  • Use Accuracy — Classes are balanced, mistakes have similar costs
  • Use Precision — False positives are costly
  • Use Recall — False negatives are costly
  • Use F1 Score — Both false positives and false negatives matter
  • Use ROC-AUC — You want to evaluate class separation across thresholds

Example: Spam Detection

Metrics for Spam Detection
  • Accuracy — Overall percentage of emails classified correctly
  • Precision — How many emails sent to spam were actually spam
  • Recall — How many actual spam emails were caught
  • F1 Score — Balance between catching spam and avoiding false alarms
  • ROC-AUC — How well the model separates spam from not spam

Example: Disease Detection

Metrics for Disease Detection
  • Accuracy — Overall percentage of correct diagnoses
  • Precision — How many predicted disease cases actually had disease
  • Recall — How many actual disease cases were found
  • F1 Score — Balance between finding disease and avoiding false alarms
  • ROC-AUC — How well the model separates disease from no disease

In healthcare, recall may be especially important because missing actual cases can be harmful.

Example: Fraud Detection

Metrics for Fraud Detection
  • Accuracy — Overall percentage of transactions classified correctly
  • Precision — How many flagged transactions were actually fraud
  • Recall — How many fraud transactions were caught
  • F1 Score — Balance between catching fraud and avoiding false alerts
  • ROC-AUC — How well the model separates fraud from normal transactions

Because fraud is rare, accuracy alone is usually not enough.

Imbalanced Classification

Imbalanced classification happens when one class appears much more often than another.

Example
  • Normal: 95%
  • Fraud: 5%

Problem: A model can get high accuracy by mostly predicting the common class.

Better metrics: Precision, Recall, F1 Score, ROC-AUC

Training Metrics vs Test Metrics

Classification metrics can be calculated on training data or test data. Test metrics are usually more important because they estimate real-world performance.

Training Metrics

Performance on data the model learned from

Test Metrics

Performance on unseen data — better estimate of real-world performance

Overfitting Detection

Overfitting happens when the model performs very well on training data but poorly on test data.

Example
  • Training F1 Score: 0.96
  • Test F1 Score: 0.62
  • Problem: The model memorized training examples instead of learning general patterns.

Underfitting Detection

Underfitting happens when the model performs poorly on both training and test data.

Example
  • Training Accuracy: 58%
  • Test Accuracy: 56%
  • Training F1 Score: 0.40
  • Test F1 Score: 0.39
  • Problem: The model is not learning enough useful patterns.

Multi-Class Classification Metrics

Multi-class classification has more than two possible classes. Accuracy, precision, recall, and F1 score can still be used.

Multi-Class Examples
  • Cat, Dog, Bird
  • Positive, Neutral, Negative
  • Low, Medium, High
  • A, B, C, D, F

For precision, recall, and F1: scores may be calculated per class and then averaged.

Macro, Micro, and Weighted Averages

Average TypeMeaning
Macro AverageTreats each class equally
Micro AverageCombines all predictions before calculating
Weighted AverageGives larger classes more influence

Common Mistakes

Common Mistakes
  • Using accuracy alone
  • Ignoring class imbalance
  • Confusing precision and recall
  • Ignoring false positives
  • Ignoring false negatives
  • Choosing the wrong metric for the problem
  • Looking only at training metrics
  • Ignoring test metrics
  • Assuming high ROC-AUC means the model is perfect
  • Ignoring performance across groups

Summary

Key Takeaways
  • Classification metrics evaluate models that predict categories.
  • Accuracy measures the percentage of correct predictions.
  • Precision measures how many predicted positives were actually positive.
  • Recall measures how many actual positives were found.
  • F1 score balances precision and recall.
  • ROC-AUC measures how well the model separates positive and negative classes.
  • A confusion matrix helps calculate many classification metrics.
  • Accuracy alone can be misleading for imbalanced datasets.
  • The best metric depends on the real-world cost of mistakes.

Practice Prompt

A fraud detection model has high accuracy but low recall. Explain why this can happen and why accuracy alone is not enough. Then choose which metric you would focus on and explain why.

Need Help?

Ask the AI if you need help understanding accuracy, precision, recall, F1 score, ROC-AUC, confusion matrices, class imbalance, or how to choose the right classification metric.