Skip to content

MNT Refactor scorer using _get_response #18589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 29 commits into from

Conversation

glemaitre
Copy link
Member

@glemaitre glemaitre commented Oct 9, 2020

Supersede #18212

Refactor the scorer such that they make use of _get_response already define in the plotting function.
This refactoring can also be beneficial for #16525.

Summary of what was done:

  • Create a _check_response_method. Its job is to return the method of a classifier or a regressor to later predict. If the method does not exist, it raises an error. This function was already existing indeed.
  • Create a _get_response. A function that returns the prediction depending on the response method. We take into account the pos_label. Thus, it will allow to not make any mistake in the future by forgetting to inverse the decision function or select the right column of probabilities for binary classification. We hard-coded this behaviour in a lot of different places and this function reduces the amount of redundant code.
  • The rest of the code is just to replace the pre-existing code and use these 2 new functions.
  • And as a bonus, several units tests that are directly testing the 2 functions.

f"pos_label={pos_label} is not a valid label: {classes}"
)

def _select_proba_binary(self, y_pred, classes):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function was moved within _get_response when selecting the binary probability.

@glemaitre glemaitre marked this pull request as draft October 10, 2020 10:43
@glemaitre glemaitre marked this pull request as ready for review October 12, 2020 17:06
@glemaitre
Copy link
Member Author

@ogrisel @thomasjpfan @NicolasHug
I am aware this is a huge refactoring but this is mainly adding a lot of tests and moving functions around such that they are in a meaningful place to be shared across the different module.

I think this is ready for a review.

@glemaitre
Copy link
Member Author

I added a summary of what was done in the welcoming message of this PR.

Copy link
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @glemaitre , just gave it a quick first look

@glemaitre
Copy link
Member Author

OK I think this is good for a new review @NicolasHug @ogrisel

"""Call estimator with method and args and kwargs."""
response_method = kwargs["response_method"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can update the scorers in a follow up PR so this PR can be a little shorter?

Parameters
----------
estimator : estimator instance
Classifier to check.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used for regressors and classifiers.

Base automatically changed from master to main January 22, 2021 10:53
@glemaitre glemaitre added this to the 1.0 milestone Feb 1, 2021
@adrinjalali
Copy link
Member

There's been no activity here since February when you added this to 1.0 @glemaitre . Do you think this can be merged in time for the release?

@glemaitre
Copy link
Member Author

glemaitre commented Aug 22, 2021 via email

@jeremiedbb
Copy link
Member

this pr is superseded. I'm removing it from the milestone and adding the more recent one instead

@jeremiedbb jeremiedbb removed this from the 1.1 milestone Mar 25, 2022
@thomasjpfan
Copy link
Member

Since this PR is superseded, can we close it? It would be easier to figure out which one is the "current one".

@lorentzenchr
Copy link
Member

Superseded by #20999.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module:metrics Superseded PR has been replace by a newer PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants