Understanding Classification Metrics: A Simple Guide to 'Accuracy', 'Precision', 'Recall', 'F1-Sc...

Confusion Matrix

Before diving into metrics, let's understand the confusion matrix, which is a summary of the model’s performance on classification tasks.

  • True Positive (TP) → Correctly predicted positive cases.

  • False Negative (FN) → Model predicted negative, but it was actually positive.

  • False Positive (FP) → Model predicted positive, but it was actually negative.

  • True Negative (TN) → Correctly predicted negative cases.


✅ Accuracy

Definition

Accuracy measures the percentage of correctly classified instances in the dataset.

Accuracy=TP+TN / TP+TN+FP+FN

When to Use?

  • Best for balanced datasets where positive and negative classes are evenly distributed.

  • Not reliable for imbalanced datasets (e.g., fraud detection where 99% of transactions are normal).

Example

A spam detection model classifies 1000 emails, correctly identifying 950 non-spam and 30 spam emails, but misclassifying 20 spam and 50 non-spam.

Accuracy=950+30/1000=98%

🛑 Problem: If spam emails make up only 5% of all emails, accuracy will be misleading as the model may favor the majority class.


✅ Precision (Positive Predictive Value - PPV)

Definition

Precision measures how many predicted positive instances were actually correct.

Precision=TP / TP+FP

When to Use?

  • Important when false positives (FP) are costly (e.g., fraud detection, spam classification).

  • High precision ensures fewer false alarms but may reduce the number of true positives detected.

Example

A fraud detection system flags 100 transactions as fraud, but 30 are false alarms.

Precision=70 / 70+30=70%

🛑 Problem: The model is conservative in labeling fraud cases, possibly missing real fraudulent transactions.


✅ Recall (Sensitivity, True Positive Rate - TPR)

Definition

Recall measures how many actual positive instances were correctly identified.

Recall=TP / TP+FN

When to Use?

  • Important when missing positive cases is costly (e.g., medical diagnosis, security threats).

  • High recall ensures fewer false negatives, meaning fewer missed cases.

Example

A COVID-19 detection model identifies 90 infected patients correctly but misses 10.

Recall=90 / 90+10

🛑 Problem: High recall may increase false positives, meaning more healthy individuals are mistakenly classified as infected.


✅ F1-Score (Harmonic Mean of Precision and Recall)

Definition

F1-Score balances precision and recall:

F1=2×Precision×Recall / Precision+Recall

When to Use?

  • Best for imbalanced datasets where accuracy is misleading.

  • Provides a single metric to optimize when both false positives and false negatives matter.

Example

Using the fraud detection model:

  • Precision = 70%

  • Recall = 60%

F1=2×0.70×0.60 / 0.70+0.60=2×0.42 / 1.30=64.6%

🛑 Problem: F1-score doesn’t show whether high precision or high recall is more important for the application.


✅ ROC-AUC (Receiver Operating Characteristic - Area Under Curve)

Definition

  • ROC Curve plots TPR (Recall) vs. FPR (False Positive Rate) at different thresholds.

  • AUC (Area Under Curve) measures the ability of the model to distinguish between classes.

    • AUC = 1.0 → Perfect classifier.

    • AUC = 0.5 → Random guessing.

When to Use?

  • Best for probabilistic models (e.g., Logistic Regression, XGBoost, Neural Networks).

  • Works well with imbalanced datasets since it evaluates the ranking ability of predictions.

Example

A model with AUC = 0.90 is better than AUC = 0.60, meaning it ranks positive cases higher than negatives 90% of the time.

🛑 Problem: ROC-AUC doesn’t give exact class predictions, only ranking ability.