Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ENH Add option to pass custom scorer for RandomForest OOB calculation - #25177

Merged
thomasjpfan merged 13 commits into
scikit-learn:mainfrom
betatim:rf-custom-oob-scoring
Dec 22, 2022
Merged

ENH Add option to pass custom scorer for RandomForest OOB calculation#25177
thomasjpfan merged 13 commits into
scikit-learn:mainfrom
betatim:rf-custom-oob-scoring

Conversation

@betatim

@betatim betatim commented Dec 12, 2022

Copy link
Copy Markdown
Member

Check if the oob_score is a function, if yes pass it in, otherwise
don't.

Reference Issues/PRs

Continuation of #23043. Closes #21521

What does this implement/fix? Explain your changes.

If the user wants to use a different score function to compute the OOB score they can now pass a callable to the oob_score parameter. This will be used instead of the accuracy/R2 score that is the default for classification/regression problems.

Comment thread sklearn/ensemble/_forest.py Outdated
@betatim
betatim force-pushed the rf-custom-oob-scoring branch from 9a18f0e to 4ff5975 Compare December 12, 2022 16:37
@glemaitre
glemaitre self-requested a review December 14, 2022 10:50

@glemaitre glemaitre left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. I would just prefer to have the same signature between the abstract method and specialized one and inside the body of the code to specialize to accuracy or r2 score.

Comment thread sklearn/ensemble/_forest.py Outdated
Comment thread sklearn/ensemble/_forest.py Outdated
Comment thread sklearn/ensemble/_forest.py Outdated
Comment thread sklearn/ensemble/_forest.py Outdated
Comment thread sklearn/ensemble/_forest.py Outdated
Comment thread sklearn/ensemble/_forest.py
Comment thread sklearn/ensemble/_forest.py Outdated
Comment thread sklearn/ensemble/_forest.py Outdated
Comment thread sklearn/ensemble/_forest.py Outdated
Comment thread sklearn/ensemble/_forest.py
@betatim

betatim commented Dec 16, 2022

Copy link
Copy Markdown
Member Author

Thanks for the feedback! Switched to the approach you suggested.

@glemaitre glemaitre left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Thanks @betatim

@betatim betatim added the Waiting for Second Reviewer First reviewer is done, need a second one! label Dec 19, 2022

@thomasjpfan thomasjpfan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for the PR!

Nit: For consistency, can we update the signature of RandomTreesEmbedding._set_oob_score_and_attributes to match the new one?

def _set_oob_score_and_attributes(self, X, y):
raise NotImplementedError("OOB score not supported by tree embedding")

Comment thread sklearn/ensemble/_forest.py Outdated
@betatim

betatim commented Dec 20, 2022

Copy link
Copy Markdown
Member Author

Implemented both ideas.

Comment thread sklearn/ensemble/_forest.py Outdated

@thomasjpfan thomasjpfan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@thomasjpfan thomasjpfan changed the title Add option to pass custom scorer for RandomForest OOB calculation ENH Add option to pass custom scorer for RandomForest OOB calculation Dec 22, 2022
@thomasjpfan
thomasjpfan merged commit 0b202ca into scikit-learn:main Dec 22, 2022
@betatim
betatim deleted the rf-custom-oob-scoring branch January 3, 2023 08:26
jjerphan pushed a commit to jjerphan/scikit-learn that referenced this pull request Jan 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module:ensemble Waiting for Second Reviewer First reviewer is done, need a second one!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add option to choose OOB scorer in RandomForest

4 participants