Skip to content
AI360XpertBeta
Playgrounds

Evaluation & RL

Precision-Recall Curve

ROC measures class-conditional ranking; precision also depends on the class mixture, and one threshold picks linked points from the same observations.

Data seed 42

Guided steps 1 / 3

Stage 1 of 3: One cut, two curves

ROC: class-conditional rates

ROC marker: FPR 0.2750, recall 0.7050. Same observations as PR.

Straight segments join tied-score endpoints; diagonal dashes are the population class-independent reference. Neutral dot: current threshold.

Precision–recall: quality of flags

PR marker: recall 0.7050, precision 0.7194.

Staircase area is average precision, not linear trapezoidal PR area. Horizontal dashes show prevalence. The (0,1) anchor is a plotting convention. Neutral dot: current threshold.

Score distributions and draggable threshold

Same observations, one cut

Seed 42. Finite-sample experiment, 400 observed rows. Threshold 0.500, equality positive. TP 141, FP 55, TN 145, FN 59. Precision 0.7194, recall 0.7050.

Upper lane: actually positive. Lower lane: actually negative. Common score and count scales; no stacking. Heights and confusion counts count observed rows. Hatched segments are mistakes. Vertical reference line and diamond: threshold. Cut edits keep the count scale fixed.

  • Actually positive (upper lane)
  • Actually negative (lower lane)
  • Missed (false negative)
  • Wrongly flagged (false positive)
Adjust parameters

Score at or above this cut predicts positive. Scores stay fixed.

  • Caution: All positive
  • Caution: Strictly above max: none positive

Changes scores, not just the decision policy.

Row 0: raw score 0.3465489960441609, actual positive, weight 1.

Confusion Matrix
Actual / predictedNegativePositive
NegativeTN 145FP 55
PositiveFN 59TP 141

Precision: 0.7194

Recall: 0.7050

FPR: 0.2750

Accuracy: 0.7150

F1: 0.7121

Precision = 141 / 196; recall = 141 / 200; FPR = 55 / 200. Zero denominator is undefined.

Where does one decision appear on two different plots?

Predict the inspected observation’s class at this cut.

Your prediction

Move the threshold: both markers and the confusion counts change, but the scored observations and both curves stay fixed. Equality predicts positive. Scores are not calibrated probabilities.

  1. Same scores and weights
  2. One cut
  3. Four outcomes
  4. Two coordinate systems
Operating point

The two curve coordinates produced by the same threshold and confusion counts.

Check this stage

Check your understanding

Move one cut through the same observations. Compare ROC and precision–recall, then separate prevalence changes from finite-sample variation.

One cut, two different questions

ROC asks how often each actual class is flagged. Precision–recall asks how many positives you find and how trustworthy those flags are. Both use the same scored observations here. Moving the decision threshold moves the two markers and confusion counts; it does not change the scores or the full curves.

Start with One cut, two curves. Inspect a row, predict its class, then reveal the answer. Open Score distributions and draggable threshold to inspect the class lanes or drag the cut; the native threshold range controls the same decision. A score at or above the cut predicts positive, including equality. The actual label decides whether that prediction is right. The histogram puts actual positives in the upper lane and actual negatives in the lower lane; hatching marks mistakes. Cut edits keep the common count scale fixed.

For TP=2, FP=2, TN=1 and FN=1, precision is 2/4, recall is 2/3 and FPR is 2/3. That one decision appears at (2/3, 2/3) on ROC and (2/3, 1/2) on PR. Raising the cut cannot increase recall on fixed rows. Precision can move either way: the next admitted row might be a true positive or a false alarm.

Does class imbalance inflate ROC AUC?

Abundant true negatives do not automatically inflate ROC AUC. At a fixed threshold, TPR=TP/(TP+FN) and FPR=FP/(FP+TN) divide within each actual class. If the two class-conditional score distributions stay fixed, changing positive prevalence leaves the population ROC and its AUC unchanged. Precision depends on the mixture:

P=p TPRp TPR+(1−p) FPR.P=\frac{p\,TPR}{p\,TPR+(1-p)\,FPR}.

For example, with TPR=.8 and FPR=.1, prevalence .5 gives precision .8/.9, about .889. At prevalence .01 it becomes .008/(.008+.099), about .075. Ranking can stay the same while most alerts become false alarms. This follows from the conditional-rate definitions in scikit-learn's ROC documentation.

In Change the mixture, choose Fixed support: reweight classes, then increase Negative class size. The same 400 rows remain; each negative carries more weight. Both class-conditional empirical distributions stay exactly fixed. The ROC curve and marker stay fixed, while precision and the PR curve change. The matrix and histogram sum weights in this mode; those weights are not extra observed people.

Switch to Finite sample: add negatives. This preserves the original experiment: 200 positives and between 200 and 4,000 negatives, with a common seeded draw. Adding negative observations changes the empirical negative score distribution, so empirical ROC and AUC can change too. New data changes the draw; separation changes the scores. Neither is a threshold-only edit. Population invariance under fixed conditional distributions is not a guarantee about two finite samples.

AP is not trapezoidal PR area

The PR staircase uses the precision after each group of tied scores enters. Its area is average precision, AP. Each recall gain is weighted by that new precision:

AP=∑k(Rk−Rk−1)Pk.AP=\sum_k(R_k-R_{k-1})P_k.

Trapezoidal PR area instead averages the two adjacent precision values before multiplying by the recall gain. Those summaries can differ. The official AP definition uses the step convention and warns against treating linear interpolation as identical. The drawer retains every tied threshold and its counts.

Work this six-row example: scores and labels (.9, negative), (.8, positive), (.5, positive), (.5, negative), (.2, negative), (.1, positive). At cut .5 the counts are the 2/2/1/1 example above. The two .5 scores enter together. Each of the three recall gains is 1/3 at precision 1/2, so AP=1/2. Linear trapezoids give 1/12+1/6+3/20=2/5. Positive–negative pair counting gives three strict wins and one tie out of nine pairs, so ROC AUC=(3+1/2)/9=7/18.

The artificial PR anchor at (recall 0, precision 1) completes the plotting convention. It does not make no-positive-prediction precision perfect. At threshold one on these synthetic scores, live precision is undefined and the PR marker hides. Recall is zero and F1 is zero when positives exist, using its own count denominator. ROC AUC requires both classes; PR and AP require positives. Empty or absent-class denominators remain undefined. See the curve endpoint contract.

Break the alerting policy

In Summaries and limits, try Flag everything at 20:1. Recall becomes one; precision becomes 1/21, about .0476. Read how many false alarms accompany each true flag. Then try threshold one: missing every positive does not produce a perfect PR operating point. Restore experiment returns your saved seed, settings, selected row, stage, exploration mode and prediction, even after further edits or New data.

Load the fixed 5:1 challenge and change only the threshold. Reach precision at least .30 and recall at least .70 without changing the seed, separation or mixture. The guard rejects easier data. Passing this sample challenge does not prove deployment performance; use separate data for policy selection and final evaluation.

The optional F1=0.5 guide shows points with the same harmonic mean. Its unit-square domain starts at recall 1/3, precision one; it ends at recall one, precision 1/3. It does not mean your score ranking can attain every point on that contour. F1 treats FP and FN symmetrically in its count formula, omits TN and supplies no application cost model. The contour follows the official precision–recall example.

Ranking scores are not calibrated probabilities

These scores are sigmoid transforms of shifted Gaussian draws. Their zero-to-one range does not establish calibration. A calibrated .8 probability would need observed positive frequencies near .8 among comparable predictions. Changing prevalence also changes the probability interpretation under prior shift. Neither ROC AUC nor AP provides that evidence; the calibration guide explains the separate reliability question.

ROC's diagonal and PR's prevalence line are population class-independent references. A finite random ranking need not achieve exactly .5 ROC AUC or AP equal to prevalence, especially with scarce positives. Report the positive class, sample mixture, tie and integration conventions, selected cut and error costs alongside summary metrics.

Stage recap

  1. One cut, two curves

    Move the threshold: both markers and the confusion counts change, but the scored observations and both curves stay fixed. Equality predicts positive. Scores are not calibrated probabilities.

  2. Change the mixture

    Fixed-support reweighting changes prevalence while preserving every within-class score distribution, so ROC stays identical and precision changes. Finite expansion adds negative observations and can change empirical ROC too.

  3. Summaries and limits

    AP weights each precision by its recall gain; trapezoidal PR area linearly joins endpoints and can differ. ROC AUC measures ranking with half credit for ties. None selects a deployment policy for you.

Reference

Precision and recall
P=TP/(TP+FP); R=TP/(TP+FN). A zero denominator is undefined; the PR anchor at (0,1) is only a plotting convention.
ROC
(FPR, recall), where FPR=FP/(FP+TN). AUC needs both classes and gives half credit to positive–negative ties.
Prevalence
p=positive weight/total weight. At fixed class-conditional scores, P=p*TPR/(p*TPR+(1-p)*FPR); ROC does not depend on p.
AP and PR area
AP=sum(delta recall * new precision). Trapezoidal PR area averages adjacent precisions. Both need positives; neither is accuracy or calibration.
F1 guide
F1=2TP/(2TP+FP+FN). Equal-F1 contours satisfy P=fR/(2R-f) for R>=f/(2-f). A guide does not establish attainable points or costs.

Break it on purpose

Flagging everything on a 20:1 mixture gives recall one but precision only 1/21. Flagging nothing misses every positive and leaves precision undefined.