๐ 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
- Mathematical Formulas
- Why TPR and FPR Are Correlated
- ROC Curve Intuition
- Real-Life Example
- Code Example
- CLI Output
- Key Takeaways
- Related Articles
๐ง 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) \]
๐ฅ 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.