-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
[MRG] run check_estimator on meta-estimators #9741
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
Closed
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
307c360
Don't modify steps in Pipeline.__init__
amueller 8845760
add check with last step None in pipeline.
amueller 44bb61c
Merge branch 'master' into meta_check_estimator
amueller 40612a4
use parametrize_with_checks instead of check_estimator
amueller 8a20c88
minor fixes, try to hack the tags
amueller 83c0a8f
cheat a bit and skip the tests the pipeline fails b/c of clone
amueller 07260c6
make it a bit easier
amueller 206630c
fix comment
amueller 3848f67
tags for feature union are actually correct
amueller 06e5bbe
do proper delegation in pipeline fit_transform
amueller 5e6ee2b
pep8
amueller 556dde5
add fit_transform ducktyping tests
amueller a2a1e32
address some comments
amueller 94a0e5e
fix typo
amueller 2625b58
use standard all on generator expression
amueller 8931521
Merge branch 'master' into meta_check_estimator
amueller 525a540
Merge remote-tracking branch 'origin/master' into pr/amueller/9741
glemaitre 646e0d8
changes during merge
glemaitre b1722ea
Merge remote-tracking branch 'upstream/main' into meta_check_estimator
adrinjalali File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,21 +6,24 @@ | |
import pytest | ||
|
||
from sklearn.base import BaseEstimator, is_regressor | ||
from sklearn.cluster import KMeans | ||
from sklearn.datasets import make_classification | ||
from sklearn.decomposition import PCA | ||
from sklearn.ensemble import BaggingClassifier | ||
from sklearn.exceptions import NotFittedError | ||
from sklearn.feature_extraction.text import TfidfVectorizer | ||
from sklearn.feature_selection import RFE, RFECV | ||
from sklearn.feature_selection import RFE, RFECV, SelectFromModel | ||
from sklearn.linear_model import LogisticRegression, Ridge | ||
from sklearn.model_selection import GridSearchCV, RandomizedSearchCV | ||
from sklearn.pipeline import Pipeline, make_pipeline | ||
from sklearn.pipeline import FeatureUnion, Pipeline, make_pipeline, make_union | ||
from sklearn.preprocessing import MaxAbsScaler, StandardScaler | ||
from sklearn.semi_supervised import SelfTrainingClassifier | ||
from sklearn.utils import all_estimators | ||
from sklearn.utils._testing import set_random_state | ||
from sklearn.utils.estimator_checks import ( | ||
_enforce_estimator_tags_X, | ||
_enforce_estimator_tags_y, | ||
parametrize_with_checks, | ||
) | ||
from sklearn.utils.validation import check_is_fitted | ||
|
||
|
@@ -74,6 +77,38 @@ def __init__( | |
), | ||
] | ||
|
||
TESTED_META = [ | ||
# pipelines | ||
Pipeline((("ss", StandardScaler()),)), | ||
Pipeline([("ss", StandardScaler())]), | ||
make_pipeline(StandardScaler(), LogisticRegression()), | ||
# union | ||
make_union(StandardScaler()), | ||
# union and pipeline | ||
make_pipeline(make_union(PCA(), StandardScaler()), LogisticRegression()), | ||
# pipeline with clustering | ||
make_pipeline(KMeans(random_state=0)), | ||
# SelectFromModel | ||
make_pipeline( | ||
SelectFromModel(LogisticRegression(), threshold=-np.inf), LogisticRegression() | ||
), | ||
# grid-search | ||
GridSearchCV(LogisticRegression(), {"C": [0.1, 1]}, cv=2), | ||
# will fail tragically | ||
# make_pipeline(StandardScaler(), None) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this failing because of how There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there were multiple issues |
||
] | ||
|
||
|
||
@parametrize_with_checks(TESTED_META) | ||
def test_metaestimators_check_estimator(estimator, check): | ||
if check.func.__name__ in [ | ||
"check_estimators_overwrite_params", | ||
"check_dont_overwrite_parameters", | ||
] and (isinstance(estimator, Pipeline) or isinstance(estimator, FeatureUnion)): | ||
# we don't clone in pipeline or feature union | ||
return | ||
check(estimator) | ||
|
||
|
||
def test_metaestimator_delegation(): | ||
# Ensures specified metaestimators have methods iff subestimator does | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why if this better here than in test_pipeline.py, test_from_model.py, etc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure it is. Having them in one place has pros and cons I think.
Right now it shows what kind of cases we're testing and what interactions we're testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for putting them all at the same place (for now?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no strong opinion either way, I was about to move them to the respective files, mostly into the pipeline tests.