Skip to content

Bugs in metrics.ranking.precision_recall_curve #5073

Closed

Description

@adamzjw

Current code for precision_recall_curve assumes the curve always passes through (recall=0, precision=1). However this is not the case.

For instance,
pred_proba = [0.8, 0.8, 0.8, 0.2, 0.2]
true_value = [0, 0, 1, 1, 0]
metrics.precision_recall_curve(true_value, pred_proba) will return
precision = [ 0.4 0.33333333 1. ]
recall = [ 1. 0.5 0. ]
index

the result's not correct and actually in favor of the poor model (the model misclassified points with high-score will have more area under the curve).

Be careful when using auc based on metrics.ranking.precision_recall_curve before the bug is solved

Activity

  1. agramfort commented on Aug 1, 2015

    @agramfort
    Member
  2. adamzjw commented on Aug 1, 2015

    @adamzjw
    Author

    I found this problem because one of my baseline model had a AUC score much higher then my expectation.
    The baseline model returned a result similar to my example above. The tie in the first threshold is the root cause.

    My suggestion is use the point (0, precision of the first threshold) as the most left end. (0,1) will over-estimate the AUC, while (0, 0) will under-estimate it.

    The current metrics.precision_recall_curve returns a curve with AUC = 0.5167, and the method based on my suggestion will return:

    p_fix = [0.4, 0.33333333, 0.3333333]
    recall = [ 1. 0.5 0. ]
    AUC = 0.3498

  3. added this to the 0.17 milestone on Aug 3, 2015
  4. agramfort commented on Aug 4, 2015

    @agramfort
    Member
  5. adamzjw commented on Aug 6, 2015

    @adamzjw
    Author

    R has several packages to plot PR curve.

    According to the 7th page of the doc of PRROC (https://cran.r-project.org/web/packages/PRROC/vignettes/PRROC.pdf), the PR curve starts from neither (0,0) or (0,1).

    The source code is like a mess, I'm not really understanding what they are doing there. But looks like they compute the curve point by point.

  6. agramfort commented on Aug 8, 2015

    @agramfort
    Member
  7. adamzjw commented on Aug 11, 2015

    @adamzjw
    Author

    Yeah, but taking average score of the first threshold should be a reasonable solution, since it's an expected value of y axis. If n is large and points are randomly ordered, the curve will be really close to the expected line.

  8. jnothman commented on Aug 15, 2015

    @jnothman
    Member

    I assume this is a duplicate of #4223 (and no doubt others!)

  9. adamzjw commented on Aug 16, 2015

    @adamzjw
    Author

    Yeah, exactly.

  10. jnothman commented on Aug 17, 2015

    @jnothman
    Member

    Closing as duplicate.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions