What is AUC - ROC Curve?
The ROC (Receiver Operating Characteristic) curve plots a binary classifier's True Positive Rate against its False Positive Rate across all classification thresholds from 0 to 1. AUC (Area Under the ROC Curve) summarizes this curve as a scalar between 0 and 1, equal to the probability that the model ranks a randomly chosen positive instance higher than a randomly chosen negative instance. A higher AUC indicates stronger threshold-independent class separation, with 1.0 representing perfect ranking and 0.5 representing random guessing.
Study Card: What is AUC - ROC Curve?
Direct Answer
AUC (Area Under the ROC Curve) is a threshold-independent performance metric for binary classification models. The ROC (Receiver Operating Characteristic) curve plots the True Positive Rate (TPR) on the vertical axis against the False Positive Rate (FPR) on the horizontal axis as the decision threshold varies across all predicted score values.
AUC integrates the area beneath the ROC curve over :
Equivalently (via the Mann–Whitney statistic), AUC equals the probability that a randomly drawn positive example receives a higher score than a randomly drawn negative example. An AUC of denotes perfect separation, corresponds to random ranking, and values below indicate inverted predictions.
Key Terms
- ROC Curve: A plot of True Positive Rate (TPR) versus False Positive Rate (FPR) across all possible classification thresholds.
- True Positive Rate (TPR) / Sensitivity / Recall: The fraction of actual positives correctly identified: .
- False Positive Rate (FPR) / Fall-out: The fraction of actual negatives incorrectly flagged as positive: .
- Decision Threshold: The cutoff score above which an instance is assigned to the positive class.
- AUC (Area Under the Curve): A scalar summary in measuring overall ranking separability across all thresholds.
Example
Imagine a customer churn classifier outputting predicted churn probabilities. Sweeping the classification threshold from down to traces the ROC curve from to . A strong model pushes quickly toward the top-left corner (high TPR while keeping FPR very low). An AUC of means that if you pick one churning customer and one non-churning customer at random, the model assigns a higher churn score to the actual churner of the time.
Code Implementation
import matplotlib.pyplot as plt
from sklearn.datasets import make_classification
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import auc, roc_auc_score, roc_curve
from sklearn.model_selection import train_test_split
# Generate synthetic binary classification data
X, y = make_classification(
n_samples=1000,
n_features=4,
n_informative=2,
n_redundant=0,
random_state=42,
)
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.3, random_state=42
)
# Fit logistic regression and get positive-class probabilities
model = LogisticRegression()
model.fit(X_train, y_train)
y_prob = model.predict_proba(X_test)[:, 1]
# Compute ROC curve and AUC
fpr, tpr, thresholds = roc_curve(y_test, y_prob)
roc_auc = auc(fpr, tpr)
direct_auc = roc_auc_score(y_test, y_prob)
print(f"ROC-AUC (trapezoidal): {roc_auc:.4f}, roc_auc_score: {direct_auc:.4f}")
# Plot ROC curve
plt.figure(figsize=(6, 5))
plt.plot(fpr, tpr, color="darkorange", lw=2, label=f"ROC curve (AUC = {roc_auc:.2f})")
plt.plot([0, 1], [0, 1], color="navy", lw=1.5, linestyle="--", label="Random baseline (AUC = 0.50)")
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.05])
plt.xlabel("False Positive Rate (FPR)")
plt.ylabel("True Positive Rate (TPR)")
plt.title("Receiver Operating Characteristic (ROC)")
plt.legend(loc="lower right")
plt.grid(True)
plt.show()
Related Concepts
- Precision–Recall (PR) Curve: Plots precision against recall across thresholds. On severely imbalanced datasets where negatives vastly outnumber positives, FPR stays small even when absolute false positives are high, making PR-AUC a more informative metric than ROC-AUC.
- F1-Score: The harmonic mean of precision and recall evaluated at a single fixed threshold, unlike AUC which aggregates across all thresholds.
- Log Loss (Binary Cross-Entropy): Evaluates probability calibration and confidence, not just rank ordering.
- Calibration vs. Discrimination: Because ROC-AUC depends solely on rank ordering, it is invariant to strictly monotonic transformations of predicted scores and does not measure probability calibration. If well-calibrated probabilities are needed (for expected-cost decisions), a higher-AUC model () still provides better underlying discrimination and can be calibrated post-hoc (e.g., Platt scaling or isotonic regression), whereas calibration alone cannot fix weak ranking ().