Skip to content

Precision @ Recall K || Recall @ Precision K #20266

Open

Description

@Ryanglambert

Describe the workflow you want to enable

Enable users to conveniently calculate "Precision at Recall K" or "Recall at Precision K" on the probabilities from clf.predict_proba.

clf.fit(X_train, y_train)
y_pred = clf.predict_proba(X_test)


p_at_r99 = precision_at_recall_k(y_test, y_pred, k=.99)

Describe your proposed solution

precision_at_recall_k (also it's complement recall_at_precision_k)

Describe alternatives you've considered, if relevant

I've written this code myself probably 10 separate times. Facebook uses this metric pretty heavily, and they have coded up this functionality here: https://github.com/facebookresearch/mmf/blob/322bd33d4a67f5bbe806624d9afd3c2cf921ec50/mmf/modules/metrics.py#L1020

Additional context

Activity

  1. Onk24 commented on Jun 20, 2021

    @Onk24

    This is an important suggestion. I would like to contribute to the solution.

  2. scsanjay commented on Jun 25, 2021

    @scsanjay

    @Onk24 Are you still working on it? If not then I will have look at it.

  3. Ryanglambert commented on Jun 25, 2021

    @Ryanglambert
    Author
  4. shubhraneel commented on Aug 27, 2021

    @shubhraneel
    Contributor

    Is anyone working on this issue? If not, may I work on it?

  5. glemaitre commented on Sep 1, 2021

    @glemaitre
    Member

    @Ryanglambert We discussed IRL with @ogrisel today and it seems that these metrics would be a good addition indeed.

  6. Kshitij68 commented on Oct 15, 2022

    @Kshitij68
    Contributor

    Seems like the PR #20877 is under stalled state, so I have picked up this issue.

  7. lorentzenchr commented on Oct 15, 2022

    @lorentzenchr
    Member

    Doesn't precision_recall_curve already give you all the triples (precision, recall, threshold)?

    #24121 might be related as it would enable a convex hull (linear interpolation) for a (monotonically) transformed version of the precision-recall curve.

  8. Ryanglambert commented on Oct 15, 2022

    @Ryanglambert
    Author
  9. lorentzenchr commented on Oct 31, 2022

    @lorentzenchr
    Member

    Just filter the triples (precision, recall, threshold) for recall > some value.

    I don't like to be the spoilsport, but I'm currently -1 for this. I would very much prefer the ability to select a threshold for predict_proba, like #4813 #8614 #16525.

  10. Kshitij68 commented on Nov 4, 2022

    @Kshitij68
    Contributor

    I also agree with @lorentzenchr here.
    But I think we need to have some consensus on how to decide if a given metric is worthwhile the development + maintenance. something like this coming out of #21718 would be very useful IMHO.

  11. Kshitij68 commented on Dec 27, 2022

    @Kshitij68
    Contributor

    Hi,
    Is there any decision on whether to accept this feature?

  12. lorentzenchr commented on Dec 28, 2022

    @lorentzenchr
    Member

    @scikit-learn/core-devs Is the score "precision at recall k" in scope or out of scope for scikit-learn?
    This issue proposes a new score/function precision_at_recall_k returning the precision at a certain user specified recall value k. Note that precision_recall_curve already give you all the triples (precision, recall, threshold).

  13. lorentzenchr commented on Dec 28, 2022

    @lorentzenchr
    Member

    -1 from me as explained in my above comments.

  14. jnothman commented on Dec 28, 2022

    @jnothman
    Member

    With metrics, it's hard to say what belongs in the core library. It's important that there are reference implementations of these things, as their ad-hoc implementation is often prone to error or introduces spurious variation. If the implementation is a fairly trivial extension of existing library functionality, it may be worth demonstrating the usage of precision_recall_curve to calculate a desired metric in an example or similar documentation. We could, for example, have an example with popular custom metrics. The benefits of this approach over having it in the library are a lower bar to acceptance of a PR change (less bikesheddng), avoiding perfecting a name, maintenance costs and need to produce something especially efficient.

  15. Kshitij68 commented on Apr 28, 2023

    @Kshitij68
    Contributor

    I will decline my PR #24671 . We can re-open it once a consensus has been reached.

  16. Onk24 commented on Sep 18, 2026

    @Onk24

    I commented here in 2021 and never followed through, sorry. Back now because I actually need this at work, picking an enforcement threshold under a fixed recall floor, repeatedly, by hand.

    @lorentzenchr your -1 was in favour of threshold selection for predict_proba (#4813, #8614, #16525). That shipped in 1.5, but the constrained objectives from that work (max_precision_at_recall_constraint + constraint_value) were dropped before release — so there's still no way to express a recall-constrained objective as a scorer.

    I have an implementation ready with tests and docs, same max semantics as the closed #24671. Is the Dec 2022 scope question settled? If @jnothman's docs-instead-of-metric suggestion is preferred, I'll do that version.

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