Monday, September 9, 2024

TPR vs FPR in Machine Learning: What’s the Difference?

TPR vs FPR Correlation Explained (ROC Curve Intuition + Math Guide)

๐Ÿ“Š TPR vs FPR Correlation Explained (Simple + Mathematical View)

When True Positive Rate (TPR) and False Positive Rate (FPR) are correlated, it means they tend to increase or decrease together as the classification threshold changes.


๐Ÿ“š Table of Contents


๐Ÿง  Basic Definitions

✔ True Positive Rate (TPR)

Also called Recall:

It measures how many actual positives are correctly identified.

✔ False Positive Rate (FPR)

It measures how many actual negatives are incorrectly predicted as positive.


๐Ÿ“ Mathematical Formulas

TPR (Recall)

\[ TPR = \frac{TP}{TP + FN} \]

FPR

\[ FPR = \frac{FP}{FP + TN} \]

Explanation:

  • TP = True Positives
  • FP = False Positives
  • TN = True Negatives
  • FN = False Negatives

๐Ÿ”— Why TPR and FPR Are Correlated

Both metrics depend on the classification threshold.

If we lower the threshold:

  • More cases are predicted as positive
  • TP increases → TPR increases
  • FP also increases → FPR increases

This creates a positive correlation.


๐Ÿ“ˆ ROC Curve Intuition

The ROC (Receiver Operating Characteristic) curve plots:

  • X-axis → FPR
  • Y-axis → TPR

As the threshold changes, the model moves along the curve.

\[ ROC = (FPR, TPR) \]

๐Ÿ‘‰ A good model tries to stay in the top-left corner (high TPR, low FPR).

๐Ÿ”ฅ Real-Life Example: Spam Detection

Scenario Effect of Lower Threshold
Spam Email Detection More spam caught (↑TPR) but more normal emails marked as spam (↑FPR)

๐Ÿ“Š Smoke Alarm Analogy

  • High sensitivity → catches real fire (high TPR)
  • But also alarms for toast (high FPR)

This shows why both move together.


๐Ÿ’ป Code Example (Python - ROC Calculation)

from sklearn.metrics import roc_curve y_true = [0,0,1,1] y_scores = [0.1,0.4,0.35,0.8] fpr, tpr, thresholds = roc_curve(y_true, y_scores) print("FPR:", fpr) print("TPR:", tpr) print("Thresholds:", thresholds)

๐Ÿ–ฅ️ CLI Output (Example)

Click to expand output
FPR: [0.  0.  0.5 1. ]
TPR: [0.  0.5 1.  1. ]
Thresholds: [inf 0.8 0.4 0.1]

๐Ÿ’ก Key Takeaways

  • TPR and FPR depend on classification threshold
  • Lower threshold increases both TPR and FPR
  • They are positively correlated in practice
  • ROC curve shows this trade-off visually
  • Best models maximize TPR while minimizing FPR

๐ŸŽฏ Final Insight

TPR and FPR are not independent. They are two sides of the same threshold decision. Improving one often impacts the other, and understanding this trade-off is essential for building reliable classification systems.

No comments:

Post a Comment

Featured Post

How HMT Watches Lost the Time: A Deep Dive into Disruptive Innovation Blindness in Indian Manufacturing

The Rise and Fall of HMT Watches: A Story of Brand Dominance and Disruptive Innovation Blindness The Rise and Fal...

Popular Posts