ROC-AUC vs. PR-AUC: Which Metric Should You Use?
When evaluating binary classification models across different decision thresholds, data scientists often rely on threshold-independent evaluation metrics rather than choosing an arbitrary cutoff such as 0.5.
Two of the most widely used evaluation methods are ROC-AUC (Receiver Operating Characteristic – Area Under the Curve) and PR-AUC (Precision-Recall – Area Under the Curve).
Although both metrics evaluate how effectively a classification model distinguishes positive instances from negative instances, they measure performance from different perspectives.
ROC-AUC is widely used in machine learning because it measures how well a model ranks positive examples above negative examples. However, on highly imbalanced datasets, ROC-AUC can sometimes present an overly optimistic picture of practical performance.
PR-AUC focuses on precision and recall, making it particularly useful when the positive class is rare and identifying positive cases is the primary objective.
Understanding how these metrics behave under different class distributions is essential for building reliable classification systems.
In this guide, we will explore ROC-AUC and PR-AUC through mathematical formulas, numerical examples, Python implementation, comparisons, and real-world applications.
1. Deconstructing the Curves
Both metrics evaluate how a classification model ranks positive instances above negative instances across different decision thresholds.
However, they use different measurements derived from the confusion matrix.
| Metric Curve | Y-Axis | X-Axis | Primary Focus |
|---|---|---|---|
| ROC Curve | True Positive Rate (TPR) / Recall | False Positive Rate (FPR) | Tradeoff between detecting positives and incorrectly flagging negatives |
| PR Curve | Precision | Recall (TPR) | Tradeoff between positive prediction reliability and positive-class coverage |
Let's understand the mathematical components.
True Positive Rate (TPR)
TPR measures the proportion of actual positive cases correctly identified.
\[ TPR = \frac{TP}{TP+FN} \]
It is also known as Recall or Sensitivity.
False Positive Rate (FPR)
FPR measures the proportion of actual negative cases incorrectly classified as positive.
\[ FPR = \frac{FP}{FP+TN} \]
Precision
Precision measures the proportion of predicted positive cases that are actually positive.
\[ Precision = \frac{TP}{TP+FP} \]
Recall
Recall measures the proportion of actual positive cases correctly identified.
\[ Recall = \frac{TP}{TP+FN} \]
These measurements form the foundation of ROC and Precision-Recall curves.
2. What Is ROC-AUC?
ROC-AUC stands for Receiver Operating Characteristic – Area Under the Curve.
The ROC Curve plots the True Positive Rate against the False Positive Rate at different classification thresholds.
It helps determine how effectively a model distinguishes positive and negative classes.
Understanding the ROC Curve
- Y-axis: True Positive Rate (Recall).
- X-axis: False Positive Rate.
- Ideal direction: Toward the top-left corner.
A good classifier aims to achieve:
- High True Positive Rate.
- Low False Positive Rate.
Key Properties of ROC-AUC
1. Random Classifier Baseline
A classifier that randomly ranks positive and negative examples has an expected ROC-AUC of:
\[ ROC\text{-}AUC = 0.50 \]
Its ROC curve follows the diagonal line from (0,0) to (1,1), assuming continuous scores without special tie effects.
2. Perfect Classifier
A perfect classifier ranks every positive example above every negative example.
\[ ROC\text{-}AUC = 1.00 \]
Its ROC curve reaches the top-left corner and then follows the top and left boundaries.
3. Class-Prevalence Invariance
ROC-AUC is based on TPR and FPR, both of which are calculated using class-specific denominators.
If the class-conditional score distributions remain unchanged, changing the ratio of positive to negative observations does not change the expected ROC curve.
This makes ROC-AUC useful when comparing ranking performance across datasets with different class proportions.
However, this does not mean ROC-AUC is always the best metric for imbalanced datasets. It can still hide the practical impact of false-positive predictions.
Interpreting ROC-AUC Scores
| ROC-AUC Score | General Interpretation |
|---|---|
| 1.00 | Perfect ranking performance |
| 0.90–0.99 | Excellent discrimination |
| 0.80–0.89 | Good discrimination |
| 0.70–0.79 | Moderate discrimination |
| 0.50 | Random ranking performance |
| Below 0.50 | Worse-than-random ranking, potentially indicating reversed scores |
These are general guidelines, not universal performance standards.
A Useful Statistical Interpretation
ROC-AUC can also be interpreted as the probability that a randomly selected positive example receives a higher model score than a randomly selected negative example, with appropriate handling of tied scores.
For example, a ROC-AUC of 0.90 indicates that the model has approximately a 90% probability of ranking a randomly selected positive example above a randomly selected negative example.
Important: ROC-AUC measures ranking ability. It does not directly tell you whether the model's predicted probabilities are well calibrated or whether a particular classification threshold is suitable.
3. What Is PR-AUC?
PR-AUC stands for Precision-Recall – Area Under the Curve.
The Precision-Recall Curve plots Precision against Recall at different classification thresholds.
Unlike ROC-AUC, which considers both positive and negative class rates, PR-AUC focuses on the performance of positive-class predictions.
It is especially useful when positive cases are rare.
Understanding the PR Curve
- Y-axis: Precision.
- X-axis: Recall.
- Ideal direction: Toward the top-right corner.
A strong classifier aims to achieve:
- High Precision.
- High Recall.
Key Properties of PR-AUC
1. Random Classifier Baseline
Unlike ROC-AUC, the random-ranking baseline of a Precision-Recall curve depends on the proportion of positive examples in the dataset.
\[ Baseline_{PR} = \frac{P}{P+N} \]
Where:
- P = Number of actual positive examples.
- N = Number of actual negative examples.
For example, suppose a dataset contains:
- 100 positive examples.
- 9,900 negative examples.
The positive-class prevalence is:
\[ Prevalence = \frac{100}{100+9900} \]
\[ \boxed{Prevalence = 0.01 = 1\%} \]
For a random ranking model, expected precision is approximately 1% across recall levels, and Average Precision has an expected baseline around the positive-class prevalence.
2. Perfect Classifier
A perfect classifier achieves both:
\[ Precision = 1 \]
\[ Recall = 1 \]
Its Precision-Recall Curve reaches the top-right corner, with an ideal area of 1.00.
3. Sensitivity to Class Imbalance
Precision directly depends on false-positive predictions.
\[ Precision = \frac{TP}{TP+FP} \]
When negative examples greatly outnumber positive examples, even a small false-positive rate can produce a large number of false-positive predictions.
This can significantly reduce precision and PR-AUC.
Why Does PR-AUC Matter?
Consider a fraud-detection system that identifies 80 fraudulent transactions but incorrectly flags 999 legitimate transactions.
The model may have a low False Positive Rate, but its positive predictions are unreliable.
PR-AUC helps expose this problem because it directly evaluates the relationship between precision and recall.
Key takeaway: PR-AUC is particularly valuable when the positive class is rare and you care about finding positive examples without overwhelming your system with false alarms.
4. The Critical Trap: Why ROC-AUC Can Be Misleading on Imbalanced Data
Let's consider a real-world fraud-detection scenario.
Suppose a financial institution processes 100,000 transactions.
The dataset contains:
- Actual Positives (Fraud): 100 transactions (0.1%).
- Actual Negatives (Legitimate): 99,900 transactions (99.9%).
Now suppose a classification model produces the following results:
- True Positives = 80.
- False Negatives = 20.
- False Positives = 999.
- True Negatives = 98,901.
Step 1: Calculate the ROC Metrics
True Positive Rate:
\[ TPR = \frac{TP}{TP+FN} \]
\[ TPR = \frac{80}{80+20} \]
\[ \boxed{TPR = 0.80 = 80\%} \]
False Positive Rate:
\[ FPR = \frac{FP}{FP+TN} \]
\[ FPR = \frac{999}{999+98901} \]
\[ \boxed{FPR = 0.01 = 1\%} \]
At this particular classification threshold, the model achieves:
- TPR = 80%.
- FPR = 1%.
This is a relatively attractive operating point on the ROC Curve.
However, we cannot determine the complete ROC-AUC from this single point. The model's performance across all thresholds is required to calculate the area under the curve.
Step 2: Calculate Precision
Now calculate the precision of the model.
\[ Precision = \frac{TP}{TP+FP} \]
\[ Precision = \frac{80}{80+999} \]
\[ Precision = \frac{80}{1079} \]
\[ \boxed{Precision \approx 0.0741 = 7.41\%} \]
This means:
- The model correctly identifies 80 fraudulent transactions.
- It incorrectly flags 999 legitimate transactions.
- Only approximately 7.41% of its fraud alerts are actually fraudulent.
In other words, more than 92% of the flagged transactions are false alarms.
Step 3: Understand the Difference
<text weight="semibold">ROC perspective</text>
The model incorrectly flags only 1% of all legitimate transactions.
That sounds impressive because the negative class contains 99,900 transactions.
<text weight="semibold">PR perspective</text>
The model correctly identifies only approximately 7.41% of all transactions it flags as fraudulent.
That is a serious operational problem if investigators must manually review every alert.
Why Does This Happen?
The reason is the large difference between positive and negative class sizes.
Even a small percentage of false positives can represent a large number of observations when the negative class is enormous.
ROC uses:
\[ FPR = \frac{FP}{FP+TN} \]
PR uses:
\[ Precision = \frac{TP}{TP+FP} \]
The ROC calculation measures false positives relative to all actual negatives.
The precision calculation measures false positives relative to all predicted positives.
These are fundamentally different perspectives.
The takeaway: A low False Positive Rate does not necessarily mean that positive predictions are reliable. When the positive class is extremely rare, examine precision and the Precision-Recall Curve carefully.
5. ROC-AUC vs. PR-AUC: Head-to-Head Comparison
Both metrics are valuable, but they answer different evaluation questions.
| Feature | ROC-AUC | PR-AUC |
|---|---|---|
| Full Name | Receiver Operating Characteristic – AUC | Precision-Recall – AUC |
| Y-axis | True Positive Rate | Precision |
| X-axis | False Positive Rate | Recall |
| Main Focus | Ranking separation between positive and negative classes | Positive prediction reliability and coverage |
| Uses True Negatives? | Yes, through FPR | No, not directly |
| Random Baseline | 0.50 for random ranking | Positive-class prevalence |
| Sensitivity to Class Prevalence | Expected ROC curve is prevalence-invariant if class-conditional score distributions stay unchanged | Strongly affected by positive-class prevalence |
| Best Suited For | General ranking evaluation and balanced or moderately imbalanced datasets | Rare-positive and highly imbalanced classification |
| Main Limitation | May hide the operational impact of false positives | Changes with class prevalence and can be harder to compare across datasets |
Which One Should You Trust?
Neither metric is universally superior.
ROC-AUC is useful for understanding overall ranking discrimination between positive and negative classes.
PR-AUC is often more informative when positive cases are rare and false-positive predictions have a significant operational cost.
For many real-world classification problems, reporting both metrics provides a more complete picture.
6. Practical Decision Framework: Which Metric Should You Use?
Choosing between ROC-AUC and PR-AUC depends on your dataset and business objective.
Choose PR-AUC When:
- Your positive class is rare.
- You are working on fraud detection.
- You are detecting rare diseases or medical conditions.
- You are identifying cybersecurity attacks or system intrusions.
- False-positive alerts create expensive manual investigations.
- You care about the reliability of positive predictions.
Examples:
- Credit card fraud detection.
- Rare disease screening.
- Network intrusion detection.
- Defect detection in manufacturing.
- Spam detection with a very low spam prevalence.
Choose ROC-AUC When:
- You want to measure overall ranking discrimination.
- You are comparing models across different classification thresholds.
- Your classes are balanced or moderately imbalanced.
- You want to evaluate the tradeoff between sensitivity and false-positive rate.
- You need a metric that is less sensitive to changes in class prevalence, assuming class-conditional score distributions remain stable.
Examples:
- General binary classification.
- Customer churn prediction.
- Some credit-risk ranking applications.
- Model comparison where ranking quality across both classes matters.
Use Both Metrics When:
- Your dataset is imbalanced but you also care about overall ranking performance.
- You need to compare model discrimination and positive-class prediction quality.
- You are developing a production classification system.
- Your evaluation needs to communicate performance to both technical and business teams.
Recommended approach: For rare-event detection, prioritize PR-AUC or Average Precision alongside ROC-AUC, and always inspect precision and recall at the intended operating threshold.
7. Python Implementation: ROC-AUC vs. PR-AUC
Let's implement both metrics using Python and Scikit-learn.
Scikit-learn provides built-in functions to calculate ROC-AUC, Average Precision, and the coordinates needed to plot ROC and Precision-Recall curves.
Step 1: Install Required Libraries
pip install numpy pandas scikit-learn matplotlib
Step 2: Import Libraries
import numpy as np
import matplotlib.pyplot as plt
from sklearn.metrics import (
roc_curve,
roc_auc_score,
precision_recall_curve,
average_precision_score,
auc
)
Step 3: Create Actual Labels and Prediction Scores
Let's create an illustrative binary classification dataset.
# Actual class labels
y_actual = np.array(
[1] * 100 + [0] * 9900
)
# Predicted scores for the positive class
np.random.seed(42)
positive_scores = np.random.uniform(
0.60, 1.00, 100
)
negative_scores = np.random.uniform(
0.00, 0.70, 9900
)
y_scores = np.concatenate(
[positive_scores, negative_scores]
)
# Shuffle the observations
indices = np.random.permutation(len(y_actual))
y_actual = y_actual[indices]
y_scores = y_scores[indices]
Here:
- 1 represents the positive class.
- 0 represents the negative class.
y_scorescontains the model's continuous scores for the positive class.
In an actual project, these scores should come from a trained model rather than randomly generated values.
Step 4: Calculate ROC-AUC
roc_auc = roc_auc_score(
y_actual,
y_scores
)
print("ROC-AUC:", roc_auc)
The result will be between 0 and 1.
A higher ROC-AUC generally indicates better ranking separation between positive and negative examples.
Step 5: Calculate PR-AUC Using Average Precision
pr_auc = average_precision_score(
y_actual,
y_scores
)
print("Average Precision:", pr_auc)
Scikit-learn's average_precision_score() calculates Average Precision (AP), a commonly used summary of Precision-Recall performance.
Step 6: Calculate ROC and Precision-Recall Curve Coordinates
# ROC Curve
fpr, tpr, roc_thresholds = roc_curve(
y_actual,
y_scores
)
# Precision-Recall Curve
precision, recall, pr_thresholds = (
precision_recall_curve(
y_actual,
y_scores
)
)
print("ROC points:", len(fpr))
print("PR points:", len(precision))
These arrays contain the values needed to visualize model performance at different thresholds.
Step 7: Plot the ROC Curve
plt.figure(figsize=(7, 5))
plt.plot(
fpr,
tpr,
label=f"ROC-AUC = {roc_auc:.3f}"
)
plt.plot(
[0, 1],
[0, 1],
linestyle="--",
label="Random Classifier"
)
plt.xlabel("False Positive Rate")
plt.ylabel("True Positive Rate")
plt.title("ROC Curve")
plt.legend()
plt.grid(True)
plt.show()
How to interpret it:
- A curve closer to the top-left corner generally indicates better discrimination.
- The diagonal line represents random ranking.
- The area under the curve summarizes the model's ranking performance.
Step 8: Plot the Precision-Recall Curve
plt.figure(figsize=(7, 5))
plt.plot(
recall,
precision,
label=f"Average Precision = {pr_auc:.3f}"
)
baseline = np.mean(y_actual)
plt.axhline(
y=baseline,
linestyle="--",
label=f"Positive Prevalence = {baseline:.3f}"
)
plt.xlabel("Recall")
plt.ylabel("Precision")
plt.title("Precision-Recall Curve")
plt.legend()
plt.grid(True)
plt.show()
How to interpret it:
- A curve closer to the top-right corner generally indicates better positive-class performance.
- The horizontal baseline represents positive-class prevalence.
- Higher precision at a given recall indicates fewer false-positive predictions at that level of positive-class coverage.
Important Note: Average Precision vs. Trapezoidal PR-AUC
The terms PR-AUC and Average Precision are sometimes used interchangeably in practice, but their calculations can differ.
Average Precision (AP) summarizes precision across recall increments using a step-wise weighted calculation:
\[ AP = \sum_n (R_n-R_{n-1})P_n \]
Where:
- \(P_n\) = Precision at a particular point.
- \(R_n\) = Recall at that point.
Alternatively, you can calculate the trapezoidal area under the Precision-Recall curve:
pr_trapezoidal_auc = auc(
recall,
precision
)
print(
"Trapezoidal PR-AUC:",
pr_trapezoidal_auc
)
The two values are not guaranteed to be identical because they use different numerical integration methods.
When publishing or reporting results, clearly state whether you are using Average Precision or trapezoidal PR-AUC.
8. Choosing the Classification Threshold
ROC-AUC and PR-AUC summarize performance across multiple classification thresholds.
However, real-world applications eventually need a specific threshold to convert prediction scores into class labels.
For example:
- Score >= 0.50: Predict positive.
- Score < 0.50: Predict negative.
The default threshold of 0.50 is common, but it is not automatically the best choice.
How to Select a Suitable Threshold
- Train the model using training data.
- Generate prediction scores on validation data.
- Calculate precision and recall at different thresholds.
- Identify the threshold that meets your business requirements.
- Evaluate the selected model and threshold on an untouched test set.
Example: Threshold Selection Using Scikit-learn
from sklearn.metrics import (
precision_recall_curve
)
precision, recall, thresholds = (
precision_recall_curve(
y_actual,
y_scores
)
)
# Example: Select a threshold that achieves
# at least 90% precision, if available.
valid_indices = np.where(
precision[:-1] >= 0.90
)[0]
if len(valid_indices) > 0:
best_index = valid_indices[
np.argmax(recall[:-1][valid_indices])
]
selected_threshold = thresholds[best_index]
print(
"Selected Threshold:",
selected_threshold
)
print(
"Precision:",
precision[best_index]
)
print(
"Recall:",
recall[best_index]
)
else:
print(
"No threshold achieved the required precision."
)
This example chooses the available threshold with the highest recall among those satisfying a minimum precision requirement.
In a real project, perform this selection using validation data, not the final test data.
Key takeaway: ROC-AUC and PR-AUC help compare ranking performance, but the final classification threshold should be selected according to operational requirements.
9. Limitations of ROC-AUC and PR-AUC
Both metrics are powerful, but neither provides a complete picture of model performance.
Limitations of ROC-AUC
- It can look impressive even when positive predictions have low precision on highly imbalanced datasets.
- It does not directly communicate the number of false-positive alerts generated at a particular threshold.
- It does not measure probability calibration.
- A strong overall ROC-AUC does not guarantee strong performance in the low-FPR region that matters to your application.
Limitations of PR-AUC
- It is sensitive to positive-class prevalence.
- It can be difficult to compare directly across datasets with different positive-class proportions.
- It does not directly include True Negatives.
- A single PR-AUC value does not identify the best operating threshold.
- Different PR-AUC calculation methods can produce different values.
What Else Should You Evaluate?
For a more complete evaluation, consider reporting:
- Confusion Matrix.
- Precision.
- Recall.
- F1 Score or F-beta Score.
- Specificity.
- Balanced Accuracy.
- ROC-AUC.
- Average Precision or PR-AUC.
- Calibration metrics, when predicted probabilities are important.
For highly imbalanced applications, also consider reporting precision and recall at the actual operating threshold.
10. Best Practices for Evaluating Imbalanced Classification Models
Follow these practices when developing and evaluating classification systems:
- Understand Class Distribution: Calculate the number and percentage of positive and negative observations.
- Start with a Baseline: Compare your model against a simple baseline classifier or random-ranking benchmark.
- Use Multiple Metrics: Avoid depending on ROC-AUC or accuracy alone.
- Prioritize Positive-Class Performance: Examine precision, recall, and PR-AUC when positive cases are rare.
- Inspect the Confusion Matrix: Understand the actual number of false positives and false negatives.
- Select Thresholds Carefully: Choose classification thresholds using validation data and business requirements.
- Prevent Data Leakage: Keep preprocessing, feature selection, and model tuning inside the training process.
- Keep Test Data Untouched: Use the final test set only for unbiased evaluation after model and threshold selection.
- Monitor Class Prevalence: Changes in the real-world positive-class rate can affect precision and PR-AUC.
- Monitor Production Performance: Evaluate model performance using newly labeled data as it becomes available.
Conclusion
ROC-AUC and PR-AUC are two important metrics for evaluating binary classification models across different decision thresholds.
ROC-AUC measures how effectively a model ranks positive examples above negative examples using the relationship between True Positive Rate and False Positive Rate.
PR-AUC evaluates the relationship between Precision and Recall, making it particularly useful for rare-positive and highly imbalanced classification problems.
The most important difference is how they communicate false-positive performance.
ROC-AUC measures false positives relative to all actual negative cases, while Precision-Recall evaluation shows how false positives affect the reliability of positive predictions.
For balanced datasets and general ranking evaluation, ROC-AUC can be a useful metric. For fraud detection, rare disease identification, cybersecurity, and other rare-event problems, PR-AUC or Average Precision often provides more actionable insight.
However, neither metric should be used in isolation.
The best evaluation strategy is to understand your class distribution, compare ROC-AUC and PR-AUC, inspect the confusion matrix, and select a classification threshold that reflects the real-world cost of prediction errors.
Remember: A model that ranks examples well is not necessarily a model that produces useful predictions at the threshold your business needs.