Precision-Recall Curve & Average Precision Calculator

Paste model scores and 0/1 labels to get the precision-recall curve, Average Precision exactly as scikit-learn computes it, trapezoidal PR AUC, the prevalence baseline and the best-F1 threshold.

Last updatedHow we build & check our tools
Results will appear here once you enter your values.

How the precision-recall curve is built

One point per distinct score. Sort rows by score from high to low. For each distinct score t, predict positive for every row with score at least t, then count true positives (TP) and false positives (FP). Precision = TP / (TP + FP) and recall = TP / (all positives). Tied scores are one threshold, so three rows at 0.6 move the curve in a single step, exactly as scikit-learn precision_recall_curve groups them.

Worked example. The scikit-learn docs use labels [0, 0, 1, 1] and scores [0.1, 0.4, 0.35, 0.8]. Thresholds 0.8, 0.4, 0.35 and 0.1 give precision 1, 0.5, 0.667, 0.5 and recall 0.5, 0.5, 1, 1. The curve then ends at recall 0 with precision 1, a point with no threshold that anchors the plot on the y axis.

Best F1. F1 = 2PR / (P + R) at each threshold. The highlighted row is the threshold with the highest F1, a common starting point when you must pick one cutoff.

Average Precision versus PR AUC

Average Precision (AP). scikit-learn computes AP = sum over n of (R_n - R_(n-1)) times P_n. Each gain in recall is multiplied by the precision reached at that threshold, a step function with no interpolation. For the docs example: 0.5 times 1 + 0.5 times 0.667 = 0.8333.

PR AUC by trapezoid. Calling auc(recall, precision) connects the points with straight lines and averages neighbouring precisions. The same example gives 0.7917. On the default 12-row data AP is 0.6815 while the trapezoid gives 0.7134.

Why they differ. Linear interpolation between PR points is not achievable by any real threshold, because precision does not change linearly as recall grows. The scikit-learn documentation warns that the trapezoidal rule, which linearly interpolates, can be too optimistic. Report AP when comparing models and state which one you used.

Pitfalls with imbalanced data

Compare against the baseline. A random classifier has precision equal to the positive rate at every recall, so its AP is roughly the prevalence. An AP of 0.30 is weak when 25 percent of rows are positive but strong when only 1 percent are. The dashed line on the chart marks this baseline.

Do not compare AP across test sets with different prevalence. Unlike ROC AUC, precision depends on class balance. Resampling a test set to 50/50 will raise AP without the model improving.

Undefined cases. With no positive labels recall is 0/0, so AP, PR AUC and F1 are shown as n/a. scikit-learn instead warns and sets recall to 1, which returns a misleading number. With every label positive, precision is 1 everywhere and AP is exactly 1.

Few thresholds. Rounded scores such as 0.1, 0.2, 0.3 create large ties and a coarse curve. Keep raw probabilities or logits, which also work because only the score order matters.

When to use a PR curve instead of ROC

Rare positives. ROC curves use the false positive rate, which stays small when negatives vastly outnumber positives, so a model can look excellent on ROC while most of its alerts are false. The PR curve shows that directly through precision. Saito and Rehmsmeier (2015) recommend PR plots for imbalanced binary classification.

Retrieval and detection. AP is the standard summary in information retrieval and object detection, where mean AP (mAP) averages AP across queries or classes. Note that COCO and Pascal VOC use interpolated variants with 101 or 11 recall points, so their numbers differ slightly from scikit-learn's step AP.

Choosing a threshold. Read the table from the top: high thresholds give high precision and low recall. If a false positive costs more than a missed positive, pick a threshold left of the best-F1 point; if misses cost more, move right toward higher recall.

Frequently Asked Questions

Common questions about the Precision-Recall Curve & Average Precision Calculator

Not exactly. Average precision in scikit-learn is a step-wise sum of precision weighted by each increase in recall, with no interpolation. PR AUC usually means the trapezoidal area from auc(recall, precision), which draws straight lines between points. For labels [0, 0, 1, 1] and scores [0.1, 0.4, 0.35, 0.8], AP is 0.8333 while the trapezoid gives 0.7917. Many papers use the terms loosely, so state which one you report.
From the same team

Stop paying per token — route AI requests to your own GPU

Wide Area AI is a local-first AI gateway: repeated requests hit an edge cache, the rest run free on your own hardware, and the cloud is only a failover. OpenAI-compatible endpoint, free tier.

Start routing — free

Sources & References

sklearn.metrics.average_precision_score

AP = sum (R_n - R_(n-1)) P_n, the note that it differs from the optimistic trapezoidal rule, and the 0.83 docs example.

sklearn.metrics.precision_recall_curve

Threshold handling, the final precision 1 and recall 0 point, and the example precision and recall arrays.

The Precision-Recall Plot Is More Informative than the ROC Plot When Evaluating Binary Classifiers on Imbalanced Datasets

Supports using PR curves and the prevalence baseline for imbalanced data.

Explore More Tools

Explore these related tools for your next step.

ai

AI Energy & Water per Query Calculator

Estimate the electricity, water and CO2e behind your AI prompts, images and video seconds using published figures from Google, OpenAI, Epoch AI, the IEA and peer-reviewed studies. Switch between low, median and high estimates and set your own grid intensity and water use effectiveness.

Try it now
ai

Expected Calibration Error (ECE) Calculator

Paste predicted probabilities and 0/1 labels to get ECE, MCE, Brier score and log loss, a per-bin table and a reliability diagram. Binning matches scikit-learn calibration_curve with uniform or quantile bins.

Try it now
ai

Speculative Decoding Speedup Calculator

Estimate the walltime speedup from speculative decoding using the acceptance rate, draft length and draft model cost. Uses Theorem 3.8 from Leviathan, Kalman and Matias (2023) and finds the best number of draft tokens.

Try it now
ai

Text-to-Speech Cost Calculator

Compare ElevenLabs, OpenAI, Google Cloud, Amazon Polly and Azure text-to-speech costs for your script or monthly character volume. See the cheapest voice tier, cost per audio hour and which ElevenLabs plan covers your usage.

Try it now
ai

NDCG Calculator

Compute DCG, IDCG and NDCG@k from the relevance grades of a ranked result list, with linear or exponential gain. Paste a full judged set so the ideal ranking includes relevant documents your system missed.

Try it now
ai

AI Video Prompt Builder (Sora, Veo, Runway)

Describe a shot once (subject and action, camera move, lens, pace, dialogue and sound) and get a prompt formatted for Veo 3, Sora 2, Runway Gen-4 or any text-to-video model, ready to copy or download.

Try it now