sk.learn average_precision_score

424 Views Asked by At

sklearn.metrics.average_precision_score formula

The average precision score calculate in the sklearn function follows the formula shown below and in the attached image.

        AP = Σ(Rn - Rn-1)Pn *The index value of the sumation is n. Please refer to the attached image for a clear version of the formula

I am struggling to fully understand the math behind this function. I am particularly curious about how the nth thresholds in the formula are calculated. Are the number of thresholds equivalent to the number of samples?

1

There are 1 best solutions below

0
On

The number of thresholds is at most equal to the number of samples as several samples may have the same underlying continuous value from the classifier.

As for the math, the precision-recall curve has recall on the abscissa and precision on the ordinata. So this is basically just an approximation of the area under the precision-recall curve where (Rn-Rn-1) is the width of the rectangle while Pn is the height. It's kind of like AUC only for the precision-recall curve instead of the ROC curve.