Skip to content

Precision Recall numbers computed by Scikits are not interpolated (non-standard) #4577

Closed

Description

@karpathy

Hi,

Scikit Learn seems to implement Precision Recall curves (and Average Precision values/AUC under PR curve) in a non-standard way, without documenting the discrepancy. The standard way of computing Precision Recall numbers is by interpolating the curve, as described here:
http://nlp.stanford.edu/IR-book/html/htmledition/evaluation-of-ranked-retrieval-results-1.html
the motivation is to

  1. Smooth out the kinks and reduce noise contribution to the score
  2. In any practical application, if your PR curve ever went up, then you would strictly prefer to set your threshold there rather than at the original place (achieving both more precision and recall). Hence, people prefer to interpolate the curve, which better integrates out the threshold parameter and gives a more sensible estimate of the real performance.

This is also what standard code for Pascal VOC does and explain this in their writeup:
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.157.5766&rep=rep1&type=pdf

VL_FEAT also has options for interpolation:
http://www.vlfeat.org/matlab/vl_pr.html
and as shown in their code here: https://github.com/vlfeat/vlfeat/blob/edc378a722ea0d79e29f4648a54bb62f32b22568/toolbox/plotop/vl_pr.m

The concern is that people using the scikit version will see incorrectly reported LOWER performance, than what they might see reported in other papers.

Activity

  1. jnothman commented on Apr 12, 2015

    @jnothman
    Member

    "Non-standard" might depend on the particular field of application. I think it would be worth having an interpolation mode. Could you also comment on #4223?

  2. karpathy commented on Apr 12, 2015

    @karpathy
    Author

    RE "Non-standard" granted. More precisely, the community-agreed-on gold standard at least in the chunk of Machine Learning and Computer Vision that I work in is the Pascal VOC evaluation code.

    The Pascal VOC code is in Matlab, and works as follows. First, in VOCevalaction.m we have:

    % compute precision/recall
    [so,si]=sort(-out); % out are class confidences
    tp=gt(si)>0; % true positives
    fp=gt(si)<0; % false posities
    fp=cumsum(fp);
    tp=cumsum(tp);
    rec=tp/sum(gt>0); % recalls
    prec=tp./(fp+tp); % precisions

    and then they call ap=VOCap(rec,prec);, which we can descend into:

    function ap = VOCap(rec,prec)
    mrec=[0 ; rec ; 1];
    mpre=[0 ; prec ; 0];
    for i=numel(mpre)-1:-1:1
        mpre(i)=max(mpre(i),mpre(i+1));
    end
    i=find(mrec(2:end)~=mrec(1:end-1))+1;
    ap=sum((mrec(i)-mrec(i-1)).*mpre(i));

    In particular note the padding with 0 and 1, and the interpolation (loop with max). The last part integrates the precision over the recalls.

  3. glouppe commented on Apr 12, 2015

    @glouppe
    Contributor

    +1 for documenting and/or adding this variant. This is the kind of hidden pitfalls that users should be made more aware of.

  4. amueller commented on Apr 13, 2015

    @amueller
    Member

    +1 that probably makes the numbers in my papers better ^^

  5. arjoly commented on Jul 8, 2015

    @arjoly
    Member

    Are we sure that this is correct way to interpolate the pr-curve?

    I thought that the interpolation has to be done first in the roc-space then translated into as there is a one-to-one mapping between those curves. This is highlighted in this paper.

  6. chiragnagpal commented on Jul 9, 2015

    @chiragnagpal

    We could have multiple values for the interpolate parameter, that way we can add newer interpolation techniques ?

  7. arjoly commented on Jul 10, 2015

    @arjoly
    Member
  8. amueller commented on Jul 11, 2015

    @amueller
    Member

    Having multiple strategies is probably a good idea. I think VOC and vl_feat are pretty good references, but that is because I'm from the computer vision community. Other communities might have different conventions, and interpolating AUC in the precision/recall space does seem a bit odd.

  9. amueller commented on Jul 11, 2015

    @amueller
    Member

    [I haven't really put any thought into it though]

  10. amueller commented on Jul 12, 2015

    @amueller
    Member
  11. agramfort commented on Jul 14, 2015

    @agramfort
    Member

    fair enough

  12. 9 remaining items

  13. amueller commented on Jun 10, 2017

    @amueller
    Member

    @GaelVaroquaux I don't think this was fixed by your PR, as it neither implemented the "interpolated" nor the "11 point interpolated" version.

  14. amueller commented on Jun 10, 2017

    @amueller
    Member

    On the off-chance that @karpathy is reading this: the IR book doesn't use interpolation from what I understand. vl_feat uses non-interpolated average precision by the default form the code you linked to.
    The Pascal VOC code uses "interpolated" AP, while their paper said they use 11 point. We should probably add options for those two, but I don't think we should use either by default.

  15. GaelVaroquaux commented on Jun 10, 2017

    @GaelVaroquaux
    Member
  16. modified the milestone: 0.19 on Jun 12, 2017
  17. amueller commented on Jul 21, 2017

    @amueller
    Member

    The nips paper linked above is quite nice and argues again that the VOC measure makes no sense ^^

  18. agitter commented on Aug 17, 2017

    @agitter
    Contributor

    I'm pleased to see that average_precision_score no longer linearly interpolates between operating points, but I found the updated documentation confusing. The referenced Stanford IR book and VOC paper implement interpolated versions that differ from the sklearn implementation. Adding the average precision formula as @brendano suggested or removing these references would make it easier to see what the function computes without looking at the source.

  19. jnothman commented on Aug 17, 2017

    @jnothman
    Member
  20. adrinjalali commented on Apr 18, 2024

    @adrinjalali
    Member

    #9583 solves the last issues here IIUC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions