ROC-AUC in Machine Learning
A classifier often produces a score for each example: for instance, a fraud probability of 0.82 or a decision score from an SVM. A threshold then turns that score into a final class such as Fraud / Not Fraud.
ROC-AUC in Simple Words
Why accuracy alone can be misleading
Suppose 990 of 1,000 transactions are normal and only 10 are fraud. A model that predicts “normal” every time gets 99% accuracy but detects none of the fraud cases. ROC-AUC is one useful way to study ranking performance across many thresholds instead of judging the model at only one threshold.
What Is the ROC Curve?
ROC stands for Receiver Operating Characteristic. For binary classification, the ROC curve plots the True Positive Rate (TPR) against the False Positive Rate (FPR) as the decision threshold changes.
Important: use continuous prediction scores
ROC analysis works best with continuous scores such as predict_proba(... )[:, 1] or a model's decision_function(). Hard class predictions like only 0 and 1 contain very little threshold information and usually produce only a small number of operating points.
A tiny score example
| Sample | Actual Class | Model Score |
|---|---|---|
| A | Positive | 0.95 |
| B | Positive | 0.85 |
| C | Negative | 0.70 |
| D | Positive | 0.60 |
| E | Negative | 0.40 |
| F | Negative | 0.20 |
Why changing the threshold matters
Threshold = 0.85
Predicted positive: A, B
TP = 2, FP = 0, FN = 1, TN = 3
TPR = 2/3 = 0.667
FPR = 0/3 = 0.000
Threshold = 0.55
Predicted positive: A, B, C, D
TP = 3, FP = 1, FN = 0, TN = 2
TPR = 3/3 = 1.000
FPR = 1/3 = 0.333
Lowering the threshold caught the remaining positive example, but it also created a false alarm. The ROC curve records this trade-off over many thresholds.
Understanding the ROC Axes
X-Axis: False Positive Rate
If 10 of 100 actual negatives are incorrectly flagged positive, FPR = 10/100 = 0.10.
Y-Axis: True Positive Rate
TPR is also Recall or Sensitivity. If 90 of 100 actual positives are detected, TPR = 90/100 = 0.90.
One simple ROC picture
Curves that reach toward the top-left generally indicate stronger ranking performance: high TPR can be achieved while keeping FPR relatively low. The diagonal represents random ranking in the usual binary ROC interpretation.
What Is AUC?
AUC means Area Under the ROC Curve. It compresses the ROC curve into one number that summarizes how well the model's scores rank positive examples above negative examples across thresholds.
Useful reference points
| AUC = 1.0 | Perfect ranking on the evaluated data |
| AUC = 0.5 | Random-ranking baseline |
| AUC < 0.5 | Ranking is worse than that baseline; investigate labels/scores/model |
Do not memorize universal labels
Rules such as “0.8 is always good” or “0.9 is always excellent” are not universal. Whether an AUC is useful depends on the task, data quality, costs of errors, baseline models, and deployment requirements.
Ranking interpretation
An AUC of 0.92 can be interpreted as the model having about a 92% chance of assigning a higher score to a randomly selected positive example than to a randomly selected negative example, under the usual ranking interpretation.
How ROC Points Are Created
Start with the score table from earlier. At each threshold, convert scores into positive/negative predictions, count TP/FP/FN/TN, and calculate TPR and FPR.
At threshold 0.85
TP = 2, FP = 0, FN = 1, TN = 3
TPR = 2 / (2 + 1) = 0.667
FPR = 0 / (0 + 3) = 0.000
ROC point = (0.000, 0.667)
Repeating this process across score thresholds creates the sequence of ROC points. AUC summarizes the resulting curve.
Comparing Models with ROC-AUC
ROC-AUC is useful when you care about how well models rank positives above negatives across many possible thresholds. It can reveal differences that a single fixed-threshold accuracy score hides.
Model A
AUC = 0.91
Model B
AUC = 0.86
But ask one more question
Which model is better in the FPR/TPR region your application actually uses?
AUC is not the entire decision
Two ROC curves can cross. A model with a larger overall AUC may still be worse in a narrow operating region that matters to your application. Always inspect the curve and connect evaluation to real false-positive and false-negative costs.
ROC-AUC Does Not Choose Your Final Threshold
ROC-AUC evaluates ranking across thresholds. Deployment still needs a particular decision threshold, and that threshold should reflect the real problem.
Cost of False Positives
Cost of False Negatives
Operational Capacity
For example, if investigators can review only a limited number of alerts each day, a threshold that produces an impractical number of false alarms may be unusable even when the overall ROC-AUC is strong.
Python Implementation
This example uses a leakage-safe Pipeline, an explicit stratified train/test split, continuous positive-class probabilities, and Scikit-learn's ROC utilities.
ROC Curve & AUC Score
Pythonimport matplotlib.pyplot as plt
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import roc_curve, roc_auc_score, RocCurveDisplay
# 1. Load educational binary-classification data
X, y = load_breast_cancer(return_X_y=True)
# 2. Keep a final test set
X_train, X_test, y_train, y_test = train_test_split(
X, y,
test_size=0.30,
random_state=42,
stratify=y
)
# 3. Scale using training data inside the Pipeline, then fit
model = make_pipeline(
StandardScaler(),
LogisticRegression(max_iter=2000)
)
model.fit(X_train, y_train)
# 4. Use continuous scores for the positive class
# (decision_function scores can also be used by many estimators)
y_score = model.predict_proba(X_test)[:, 1]
# 5. Compute ROC points and ROC-AUC
fpr, tpr, thresholds = roc_curve(y_test, y_score)
auc_score = roc_auc_score(y_test, y_score)
print(f"AUC Score: {auc_score:.3f}")
print(f"ROC points: {len(fpr)}")
# 6. Plot from the same predictions
RocCurveDisplay.from_predictions(y_test, y_score)
plt.plot([0, 1], [0, 1], "--", label="Random ranking")
plt.legend()
plt.show()Expected output for this fixed split:
AUC Score: 0.998 ROC points: 6
Why only 6 plotted ROC points?
Scikit-learn's roc_curve uses drop_intermediate=True by default, so thresholds whose ROC points are collinear with neighboring points can be omitted. This reduces plotting points without changing the ROC-AUC or the visual shape of the curve.
Educational dataset note
A high score on this built-in dataset is only a demonstration of the metric. It does not imply that a model is ready for medical or other high-stakes deployment.
ROC Curve vs Precision-Recall Curve
ROC and Precision-Recall curves answer related but different questions. When the positive class is very rare, a Precision-Recall curve can often be especially informative because precision directly reflects how many predicted positives are actually positive.
| Curve | Axes | Useful focus |
|---|---|---|
| ROC | TPR vs FPR | Ranking trade-off across positives and negatives |
| Precision-Recall | Precision vs Recall | Positive-class retrieval quality, often informative for rare positives |
Do not choose only from a slogan
“Balanced data = ROC” and “imbalanced data = PR” are useful beginner shortcuts but not universal rules. Look at the decision problem, class prevalence, operating region, and costs of mistakes.
What About Multiclass Problems?
The basic ROC curve is easiest to understand for binary classification. ROC-AUC can also be extended to multiclass and multilabel problems using strategies such as one-vs-rest or one-vs-one and then combining class-level scores with averaging choices.
For a first lesson, master the binary case first. The key idea remains the same: evaluate ranking scores rather than relying only on one hard threshold.
Common Mistakes
Quick Recap
What does the ROC curve plot?
True Positive Rate against False Positive Rate across changing score thresholds.
Does ROC-AUC tell us the best production threshold?
No. It summarizes ranking across thresholds; the final threshold depends on the application's trade-offs and constraints.
Should ROC be computed from hard predictions?
Use continuous model scores whenever possible. Hard labels discard most threshold-ranking information.
Continue learning
Most Important Insight
ROC-AUC is mainly about ranking quality across thresholds. Use continuous scores, inspect the actual curve, and choose the final decision threshold using the real cost of mistakes—not AUC alone.