Skip to content

DOC oob_score is only available when bootstrap=True #19444

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

Merged
merged 1 commit into from
Feb 15, 2021

Conversation

hirzel
Copy link
Contributor

@hirzel hirzel commented Feb 11, 2021

Reference Issues/PRs

Fixes issue #19431

What does this implement/fix? Explain your changes.

This updates the docstrings for the oob_score argument to indicate that it depends on the bootstrap argument. It applies to six classes: {Bagging,ExtraTrees,RandomForest}{Classifier,Regressor}

Any other comments?

The following code demonstrates that when the constraint is violated, the code raises an exception:

from sklearn.ensemble import BaggingClassifier, ExtraTreesClassifier, RandomForestClassifier
from sklearn.datasets import load_iris
X, y = load_iris(return_X_y=True)
for cls in [BaggingClassifier, ExtraTreesClassifier, RandomForestClassifier]:
    est = cls(bootstrap=False, oob_score=True)
    try:
        est.fit(X, y)
    except ValueError as e:
        print(f"{cls.__name__}: {e}")

from sklearn.ensemble import BaggingRegressor, ExtraTreesRegressor, RandomForestRegressor
from sklearn.datasets import make_regression
X, y = make_regression(n_samples=200, n_features=4, n_informative=2)
for cls in [BaggingRegressor, ExtraTreesRegressor, RandomForestRegressor]:
    est = cls(bootstrap=False, oob_score=True)
    try:
        est.fit(X, y)
    except ValueError as e:
        print(f"{cls.__name__}: {e}")

Output:

BaggingClassifier: Out of bag estimation only available if bootstrap=True
ExtraTreesClassifier: Out of bag estimation only available if bootstrap=True
RandomForestClassifier: Out of bag estimation only available if bootstrap=True
BaggingRegressor: Out of bag estimation only available if bootstrap=True
ExtraTreesRegressor: Out of bag estimation only available if bootstrap=True
RandomForestRegressor: Out of bag estimation only available if bootstrap=True

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 @hirzel

@NicolasHug NicolasHug changed the title [MRG] Documents dependency of oob_score upon bootstrap as per Issue #19431. DOC oob_score is only available when bootstrap=True Feb 15, 2021
@NicolasHug NicolasHug merged commit a0ba256 into scikit-learn:main Feb 15, 2021
@glemaitre glemaitre mentioned this pull request Apr 22, 2021
12 tasks
glemaitre pushed a commit to glemaitre/scikit-learn that referenced this pull request Apr 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants