Repository navigation
BUG Fixes stacker compatibility with estimators without n_features_in_ - #17357
Merged
glemaitre merged 8 commits intoJul 9, 2020
Merged
Conversation
NicolasHug
reviewed
May 26, 2020
|
|
||
| - |Fix| Fixes :class:`ensemble.StackingClassifier` and | ||
| :class:`ensemble.StackingRegressor` compatibility with estimators that | ||
| does not define `n_features_in_`. :pr:`17357` by `Thomas Fan`_. |
|
|
||
| return self | ||
|
|
||
| @property |
Member
There was a problem hiding this comment.
Could be worth using the same structure as others meta estimators for consistency
def n_features_in_(self):
# For consistency with other estimators we raise a AttributeError so
# that hasattr() fails if the estimator isn't fitted.
try:
check_is_fitted(self)
except NotFittedError as nfe:
raise AttributeError(
"{} object has no n_features_in_ attribute."
.format(self.__class__.__name__)
) from nfe
return self.estimators_[0].n_features_in_
Member
There was a problem hiding this comment.
Not for this PR but thinking about it, would it make sense to have something shared in a base class (or mixin).
| stack = Stacking(estimators=[('lr', MyLR())]) | ||
|
|
||
| # Does not raise | ||
| stack.fit(X, y) |
Member
There was a problem hiding this comment.
maybe assert an AttributeError when it's accessed after git
adrinjalali
reviewed
Jun 25, 2020
| (make_classification, StackingClassifier, LogisticRegression), | ||
| (make_regression, StackingRegressor, LinearRegression) | ||
| ]) | ||
| def test_stacking_without_n_features_in(make_dataset, Stacking, Regression): |
Member
There was a problem hiding this comment.
Suggested change
| def test_stacking_without_n_features_in(make_dataset, Stacking, Regression): | |
| def test_stacking_without_n_features_in(make_dataset, Stacking, Estimator): |
| # Stacking supports estimators without `n_features_in_`. Regression test | ||
| # for #17353 | ||
|
|
||
| class MyLR(Regression): |
Member
There was a problem hiding this comment.
Suggested change
| class MyLR(Regression): | |
| class MyEstimator(Estimator): |
| # for #17353 | ||
|
|
||
| class MyLR(Regression): | ||
| """Regresion without n_features_in_""" |
Member
There was a problem hiding this comment.
Suggested change
| """Regresion without n_features_in_""" | |
| """Estimator without n_features_in_""" |
adrinjalali
approved these changes
Jun 26, 2020
Member
|
Thanks @thomasjpfan |
glemaitre
pushed a commit
to glemaitre/scikit-learn
that referenced
this pull request
Aug 3, 2020
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Reference Issues/PRs
Fixes #17353
What does this implement/fix? Explain your changes.
Makes
n_features_in_a property that depends on the first estimator.