Skip to content

Adds gain scoring metrics - #24121

Open
bradleyfowler123 wants to merge 13 commits into
scikit-learn:mainfrom
bradleyfowler123:adds_gain_scoring_metrics
Open

bradleyfowler123 wants to merge 13 commits into
scikit-learn:mainfrom
bradleyfowler123:adds_gain_scoring_metrics

Conversation

@bradleyfowler123

Copy link
Copy Markdown

What does this implement/fix? Explain your changes.

This PR adds Precision Gain, Recall Gain and Fscore Gain metrics to scikit-learn.

The metrics are described in this paper by Peter Flach and Meelis Kull at the University of Bristol, UK.

In short, these improved metrics have desirable properties such as meaningful linear interpolation of PR curves and a universal baseline across tasks.

I've added test coverage for the gain metrics and utilized existing scikit-learn Precision/Recall functionality where-ever possible.

The new methods, which can be imported from sklearn.metrics are:

- f1_gain_score
- fbeta_gain_score
- precision_recall_fgain_score_support
- precision_gain_score
- recall_gain_score

Reference Issues/PRs

Request for this feature was referenced in #21391 (comment) by @glemaitre

@bradleyfowler123
bradleyfowler123 force-pushed the adds_gain_scoring_metrics branch from 154679d to c0d3e76 Compare August 5, 2022 14:10
@lorentzenchr

Copy link
Copy Markdown
Member

@bradleyfowler123 Thanks for this PR and your willingness to contribute. Please note that #21391 (comment) was a suggestion only and not a consensus.
From a very quick view, I have to say that I'm not convinced to include those transformed metrices into scikit-learn.

@bradleyfowler123

bradleyfowler123 commented Aug 5, 2022 •

Copy link
Copy Markdown
Author

Hi @lorentzenchr, thanks for your comment. Yes I was aware the referenced comment was just a suggestion, I only linked it on the PR for completeness.

May I ask what your reservations for adding these metrics are? The paper presents some pretty compelling, mathematically grounded reasons and I've seen them used industry more than once. I can see a real advantage to sci-kit learn in offering these metrics because awareness surrounding them continues to increase and their usage is becoming more widespread.

@Micky774

Micky774 commented Aug 5, 2022 •

Copy link
Copy Markdown
Contributor

May I ask what your reservations for adding these metrics are?

Generally this is not due to methods being unviable, but rather because even the best features incur necessary maintenance overhead for the rest of the library's lifespan. A good passage discussing this is in the FAQ. The paper itself warrants consideration since it meets our first-pass inclusion criteria but a discussion is still important :)

@lorentzenchr

Copy link
Copy Markdown
Member

We have a lot of requests for new metrics. That's why I opened the issue #21718. IIUC, this PR introduces metrics that are just monotonic mappings of already available metrics: something a user could easily do her/himself. Adding 1000+ loc seems way too much for such a functionality that does not really enable anything new (only better). That's why I'm

-1

That being said, I see that the proposed functionality makes sense.

@bradleyfowler123

Copy link
Copy Markdown
Author

A discussion would be good

@lorentzenchr I see your point about mapping to gain space being just a simple function however I disagree that it's easy for a user to do. The reason why is because the mapping needs to happen at a lower level to be just as useful as the traditional metrics. To show you why with just a single example; how does one make use of sci-kit learn's capability to average metrics with 'macro', 'weighted', 'binary' etc, you can't. Unless the transform happens within the internals of sci-kit learn the user would be required to build out that functionality themselves and not use sci-kit learn for metrics. There are of course more arguments than just the average option as well.

@bradleyfowler123

Copy link
Copy Markdown
Author

However I do see the trade off you are trying to weigh up. I did try and use the existing functionality as much as possible so hopefully there isn't too much overhead added to maintenance. Either way, let me know if I can do anything to help out / discuss further with it.

@cmarmo cmarmo added the Needs Decision - Include Feature Requires decision regarding including feature label Sep 14, 2022
@LarsDu

LarsDu commented Oct 3, 2022

Copy link
Copy Markdown

Probably too late to chime in, but I would support addition of such metrics to sklearn!

@lorentzenchr

Copy link
Copy Markdown
Member

@adrinjalali Do you have an opinion for this one?

@adrinjalali

Copy link
Copy Markdown
Member

I'm happy to add these functionalities, but as hinted in my comment here (#21391 (comment)), I rather introduce only one (or two) methods/classes.

One to do the plotting, which would take a metric and do the plot based on the threshold, another one gain_score which would take a metric and do the calculation for the metric based on different thresholds.

I find introducing all the methods proposed here a bit cluttering the metric module. I'm happy to have all of them as examples in the docs. The code from the users' perspective would then be like

gain_score(f1)(y_true, y_pred)
# or
make_scorer(gain_score(f1))(estimator, X, y)

cc @glemaitre

@glemaitre

Copy link
Copy Markdown
Member

I like the proposal of @adrinjalali. However, we need to make sure that this "gain" end-up in the PR curve because this is where it makes sense. I don't know if adding a keyword there is enough.

@oleg-kachan

Copy link
Copy Markdown

Hi, @bradleyfowler123

What is the status of this commit? Could you also implement precision_recall_gain_curve and maybe prg_auc_score?

@crypdick

Copy link
Copy Markdown
Contributor

I've added the code from this PR into crypdick/precision-recall-gain and handled a few more edge cases. cc @bradleyfowler123

This branch has not been deployed

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

Labels

module:metrics Needs Decision - Include Feature Requires decision regarding including feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants