Skip to main content

Two perfect rankings can put the wrong cases at the front of one queue

Imagine a reviewer who has time for four cases. Two groups each send four, with the two worth investigating ranked first. The reviewer can take the top two from each group and find all four useful cases. But what if the eight scores go into one list?

In our fictional example we added 100 to every score in one group. Its own ranking was still perfect. In the combined list, however, even its two unwanted cases now outranked the best case in the other group. A reviewer who took the top four found only two of the four useful cases.

Call a case worth investigating a positive. At any cutoff, precision asks what share of the selected cases are positive. Recall asks what share of all the positives you’ve found. If only one of your first two cases is positive and there are four positives in all, precision is one-half and recall is one-quarter.

Average precision (AP) summarizes how early the positives appear across the whole list. Each time a lower score cutoff captures more positives, their share of all the positives determines how much the new precision counts. We used made-up cases and scikit-learn 1.7.2. Average precision definition

For example, one unwanted case’s score rose from 40 to 140 in the group we shifted. In the other group, a wanted case stayed at 80. Those two switched positions in the combined list even though neither moved within its own group. Each group’s AP stayed at 1.0. For the combined eight-case list it fell from 1.0 to 49/60, about 0.817. That is a whole-list score. The number found in the reviewer’s four available places fell from four to two. Report the measure and review budget for the queue people will actually use. Pooling replay

Two ways to score the same ranked answers

There is a second choice even after you agree on the queue: how should a single number summarize it? In a separate eight-case test, AP put B ahead of A, 0.6792 to 0.6500. Using the trapezoidal area under a precision–recall curve put A ahead, 0.6077 to 0.5792. The models’ rankings hadn’t changed. Each point on the curve represented the precision and recall at one score cutoff.

The AP calculation we used gives the precision at each point a weight equal to the increase in recall there. The other calculation joins neighboring points with straight lines and finds the area under those lines, called the trapezoidal area. They use the same predictions but treat the space between points differently. Save the name and version of the function you used and, for the area calculation, how you built the curve and treated its endpoints. Curve summary replay

How much does each kind of case count?

Suppose a positive case is rarer in the intended workload than in the test. In another example we changed the weights so positives accounted for 10% of the total instead of 50%. The models’ order by AP reversed. Their receiver operating characteristic (ROC) curves stayed fixed. An ROC curve tracks the fraction of all positives selected and the fraction of all negatives selected as the cutoff changes.

Giving every negative more influence makes the mistakes in a selected set count more heavily against its precision. It leaves the fractions selected within each class alone when all cases in that class get the same weight. Before using such a calculation to describe another population, check that the scores of its positive cases resemble those of the test positives, and likewise for negatives. Keep the IDs and weights used. Prevalence replay

Keep track of score rounding

In our six-case rounding test, A gave two positives scores of 0.904 and 0.902 and a negative 0.901. At three decimal places those are three different ranks. At two places all three read 0.90. In this AP calculation the cutoff reaches them together, so rearranging the tied rows cannot restore the earlier ranking. A led B at three places but B led A at two. Score rounding replay

The table uses the same six cases. ‘Weighted positive share’ is the fraction of all case weight assigned to positives. At 50%, all six cases carry equal weight. At 10%, each negative carries nine times the weight of each positive. The two models receive the same weights. Compare rows at the same positive share first to see what rounding alone changes. Combined replay

Average precision by weighted positive share and decimal places saved
Weighted positive shareSaved decimalsA APB APHigher AP
50%30.83330.6389A
50%20.61110.6944B
10%30.70000.1773A
10%20.15450.2045B

Changing from three decimal places to two reverses the winner at both positive shares. At two places, each model’s top tied group contains the same two positives and one negative. With equal weights that group’s precision is 2/3. If each positive counts one and the negative counts nine, it is 2/11.

Keep the scores before and after rounding for each case ID, the labels, which class counted as positive, and how cases were grouped and weighted. Together with the precise scoring function, those details let a reader reconstruct which comparison the published AP describes.