ROC-AUC Curve

जब हम binary classification करते हैं (जैसे spam/not-spam, disease/healthy), तो हमें सिर्फ accuracy से model की गुणवत्ता नहीं पता चलती। ऐसे में ROC-AUC Curve model के prediction scores को analyze करने में मदद करता है।


🔶 ROC का अर्थ:

ROC = Receiver Operating Characteristic
यह एक graphical plot है जो बताता है कि model कैसे विभिन्न thresholds पर perform करता है।

📈 ROC Curve Plot:

  • X-axis → False Positive Rate (FPR)
  • Y-axis → True Positive Rate (TPR)

Threshold को 0 से 1 तक vary करते हुए हम विभिन्न FPR और TPR को plot करते हैं — और वो बनाता है ROC curve.


📐 Formulae:

✅ True Positive Rate (TPR) aka Recall:

✅ False Positive Rate (FPR):


🔷 AUC का अर्थ:

AUC = Area Under the Curve
यह ROC curve के नीचे आने वाले क्षेत्र का मान है।
AUC का मान 0 और 1 के बीच होता है:

AUC ScoreMeaning
1.0Perfect model
0.9 – 1.0Excellent
0.8 – 0.9Good
0.7 – 0.8Fair
0.5Random guess (no skill)
< 0.5Worse than random (bad model)

✅ Python Code (Scikit-learn + Visualization):

from sklearn.datasets import make_classification
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import roc_curve, auc
import matplotlib.pyplot as plt

# Sample data
X, y = make_classification(n_samples=1000, n_classes=2, n_informative=3)

# Train model
model = LogisticRegression()
model.fit(X, y)

# Get predicted probabilities
y_scores = model.predict_proba(X)[:, 1]

# Compute FPR, TPR
fpr, tpr, thresholds = roc_curve(y, y_scores)

# Compute AUC
roc_auc = auc(fpr, tpr)

# Plot
plt.figure(figsize=(8,6))
plt.plot(fpr, tpr, label=f'ROC Curve (AUC = {roc_auc:.2f})')
plt.plot([0, 1], [0, 1], 'k--', label='Random Guess')
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('ROC-AUC Curve')
plt.legend()
plt.grid(True)
plt.show()

📊 ROC vs Precision-Recall Curve:


Title Page Separator Site title

FeatureROC CurvePrecision-Recall Curve
Focuses onAll classes (balanced data)Positive class (imbalanced data)
X-axisFalse Positive RateRecall
Y-axisTrue Positive Rate (Recall)Precision

✅ Imbalanced datasets पर Precision-Recall Curve ज़्यादा informative हो सकता है।


📄 Summary Table:

ConceptDescription
ROC CurveTPR vs FPR plot for various thresholds
AUCROC Curve के नीचे का क्षेत्र
Best CaseAUC = 1.0 (Perfect classifier)
Worst CaseAUC = 0.5 (Random guessing)
Use CasesBinary classification performance check

📝 Practice Questions:

  1. ROC Curve में X और Y axes क्या दर्शाते हैं?
  2. AUC का score किस range में होता है और उसका क्या मतलब है?
  3. ROC और Precision-Recall Curve में क्या अंतर है?
  4. ROC curve कैसे बनता है?
  5. क्या AUC metric imbalanced datasets के लिए reliable है?