Machine LearningClassification Evaluation

What is a precision-recall curve?

A precision–recall (PR) curve plots a classifier's precision against its recall as the decision threshold changes. It shows how many positive predictions are correct and how many actual positives the model finds at different operating points.

What are its axes?

  • X-axis: Recall = TP / (TP + FN). Of actual positives, how many were found?
  • Y-axis: Precision = TP / (TP + FP). Of predicted positives, how many were correct?

Each threshold gives a point (recall, precision) on the curve. A curve concentrated near the upper-right generally indicates better positive-class detection with fewer false alarms.

Numerical example: fraud alerts

A model scores six transactions:

  • Fraud (positive): 0.90, 0.70, 0.40.
  • Legitimate (negative): 0.80, 0.30, 0.10.

Flag a transaction when its score is at least the threshold.

  • Threshold 0.90: TP=1, FP=0, FN=2 → precision 100%, recall 33.3%.
  • Threshold 0.80: TP=1, FP=1, FN=2 → precision 50%, recall 33.3%.
  • Threshold 0.70: TP=2, FP=1, FN=1 → precision 66.7%, recall 66.7%.
  • Threshold 0.40: TP=3, FP=1, FN=0 → precision 75%, recall 100%.
  • Threshold 0.10: TP=3, FP=3, FN=0 → precision 50%, recall 100%.

These points form a step-like curve. Notice that precision can improve when recall rises (from threshold 0.80 to 0.70): precision is not guaranteed to decrease monotonically.

Python example

PYTHON
import matplotlib.pyplot as plt from sklearn.metrics import precision_recall_curve y_true = [1, 1, 1, 0, 0, 0] scores = [0.90, 0.70, 0.40, 0.80, 0.30, 0.10] precision, recall, thresholds = precision_recall_curve( y_true, scores ) plt.step(recall, precision, where='post') plt.xlabel("Recall") plt.ylabel("Precision") plt.title("Precision–Recall curve") plt.show()

Pass continuous scores or positive-class probabilities, rather than hard 0/1 predictions. In scikit-learn, the returned precision and recall arrays each have one more element than thresholds; the additional point is the plotting endpoint at recall 0, precision 1.

When is a PR curve useful?

  • Rare-positive problems: fraud, unusual defects, and event detection, where precision among alerts matters.
  • Threshold selection: find an operating point with enough recall without too many false-positive alerts.
  • Model comparison: compare precision at recall levels important to the application instead of considering accuracy alone.

How is it different from an ROC curve?

  • PR curve: precision versus recall, focusing on the positive class and positive-prediction quality.
  • ROC curve: true positive rate versus false positive rate, considering correct positive detection relative to all actual negatives.

PR curves often provide more actionable insight when positive examples are scarce.

What about PR-AUC and average precision?

A PR curve can be summarized by area under the precision–recall curve (PR-AUC) or average precision (AP). They are related but not necessarily numerically identical: scikit-learn's average_precision_score uses a recall-weighted sum of precisions and does not interpolate linearly between the curve points. The next question covers when these summaries are more informative than ROC-AUC.

In short: a precision–recall curve shows the trade-off between catching real positives and keeping positive alerts reliable across classification thresholds.

References

#precision recall curve example#PR curve thresholds precision recall#precision recall curve sklearn#precision recall vs ROC curve#average precision vs PR AUC#machine-learning#classification-evaluation#precision-recall-curve#classification-thresholds#pr-curve

Learning Sequence

Machine Learning Curriculum

76% Completed
Up NextMachine Learning

When is PR-AUC more useful than ROC-AUC?

Explore Related Questions

Deepen your understanding across related Machine Learning topics.

Machinoai Logo
Machinoai

Your edge in the AI era. Deep dives into machine learning concepts, paper explainers, verified industry jobs, and developer tools.

© 2026 Machinoai. All rights reserved.