2
$\begingroup$

In the discussion of this question, the following new one arose:

Why is the mean AURPRC higher the fewer examples are used?

Here is a minimal (Python) code example showing the effect:

import numpy as np
from sklearn.metrics import average_precision_score


def auprc(scores_of_negatives, scores_of_positives):
    y_true = np.concatenate(
        (np.full(scores_of_negatives.size, 0),
         np.full(scores_of_positives.size, 1))
    )
    y_scores = np.concatenate((scores_of_negatives, scores_of_positives))
    return average_precision_score(y_true, y_scores)


a_neg, b_neg = 0.3, 1.3
a_pos, b_pos = 2.0, 0.9

for n in [1, 2, 4, 8, 16, 32, 64, 128, 256]:
    auprcs = []
    for _ in range(10000):
        auprcs.append(auprc(
            np.random.beta(a_neg, b_neg, n),
            np.random.beta(a_pos, b_pos, n)
        ))
    print(n, np.mean(auprcs))

Output:

1 0.95795
2 0.9387583333333334
4 0.9231154166666665
8 0.9127574443265069
16 0.9044083984271667
32 0.8996982152618184
64 0.8967667717732809
128 0.895994038020052
256 0.8949927372666804
$\endgroup$
1

1 Answer 1

1
$\begingroup$

I think the answer has to do with the probability of drawing a sample from x1=np.random.beta(a_neg, b_neg, n) being greater than a sample from x2=np.random.beta(a_pos, b_pos, n). The more samples you draw the more likely you will catch the case where x1>x2. If you only draw a single sample (N=1) the probability of that happening is ~0.08673 (simulate it ;)

we can then calculate the PR auc as:

0.08673*0.5+(1-0.08673)*1 ~ 0.956635

which matches your N=1 case. N=2 is a bit more tricky so i will leave that to the avid reader.

About 0.08673 of the time our PR AUC will be 0.5 (the case where the negative sample has higher score than the positive one) and then (1-0.08673) of the time the other case will happen.

Now if you increase the sample size your PR_AUC converges to the true PR AUC given samples ranked with those distributions. (if you run your code with n=1024 or 4096 or any other big value it seems to slowly converge to something like ~0.894).

I apologize for it being not the most mathy answer but I think it catches the right idea.

$\endgroup$
5
  • $\begingroup$ Thanks for the answer. I think it makes sense when looking at single evaluations, especially with a sample size of 1. But we evaluate 10000 times (and the mean of the AUPRC is calculated) I wonder why the probable case (high AURPC) does not even out with the rare case (low AURPC) on average, approaching the expected value (without overestimation bias). I just tried with two distributions with a very strong overlap (low expected AURPC), expecting that this might invert the effect, but it does not. $\endgroup$ Commented Aug 15, 2023 at 12:40
  • $\begingroup$ I am not sure I understand what you mean, in your new example the probability that B_neg<B_pos is 0.48065 so the cases in ranking we have for N=1 is b_neg b_pos (PR AUC is 1, that happens (1-0.48065) of the time) b_pos b_neg (PR AUC is 0.5 that happens 0.48065 of the time) So the PR AUC is 1*(1-0.48065)+0.5*0.48065 ~ 0.759 which is similar to your N=1 case in the code $\endgroup$
    – TheD
    Commented Aug 15, 2023 at 23:27
  • $\begingroup$ If your question is why it always goes from a higher PR AUC to a lower one: If you have two samples, your PR AUC is 1 if you get it right and 0.5(not 0) if you get it wrong so depending on your distribution details you are somewhere between the two (averaging many trials). If you have four samples (with two 1 and two 0) the lowest PR AUC for any random sample is 0.416 etc. So in your sampling you always have perfect AUC (1.0) but you never get a score like 0. $\endgroup$
    – TheD
    Commented Aug 15, 2023 at 23:27
  • $\begingroup$ You can also see this if you take your original betas and use the b_neg for the positive samples essentially making a classifier that has inverted predictions. Your PR AUC will now be closer to the lowest PR aucs given the number of samples but still be decreasing because adding more samples allows for smaller average precisions. $\endgroup$
    – TheD
    Commented Aug 15, 2023 at 23:27
  • $\begingroup$ Ah, I think I get it now. Thanks a lot! $\endgroup$ Commented Aug 17, 2023 at 6:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.