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

Skip to content

[MRG+1] RFE can raise NotFittedError #9283

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 6 commits into from
Jul 6, 2017

Conversation

sshleifer
Copy link
Contributor

Reference Issue

Fixes Issue #9276

What does this implement/fix? Explain your changes.

Any other comments?

@sshleifer
Copy link
Contributor Author

need to squash commits

@TomDLT
Copy link
Member

TomDLT commented Jul 5, 2017

need to squash commits

no need, GitHub will squash when merging

Copy link
Member

@TomDLT TomDLT left a comment

Choose a reason for hiding this comment

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

RFE doesnt raise NotFittedError, suspect other meta feature selectors have same issue.

I checked, the other classes inheriting SelectorMixin all have already a specific check_is_fitted call.

LGTM

@TomDLT TomDLT changed the title [MRG] RFE can raise NotFittedError [MRG+1] RFE can raise NotFittedError Jul 5, 2017
@jnothman
Copy link
Member

jnothman commented Jul 5, 2017

There should really be a non-regression test.

@@ -251,6 +252,7 @@ def score(self, X, y):
return self.estimator_.score(self.transform(X), y)

def _get_support_mask(self):
check_is_fitted(self, 'support_') # will raise NotFittedError if not fitted
Copy link
Member

Choose a reason for hiding this comment

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

This line is too long (>79 characters), you may remove the comment

Copy link
Member

@jnothman jnothman left a comment

Choose a reason for hiding this comment

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

This looks good!

Though now I wonder if it would be nice for check_is_fitted to return the value of that attribute... Hmm. Not required in this PR.

@TomDLT, this has changed a lot since you gave it +1. Could you please check again?

@@ -102,6 +104,8 @@ def score(self, X, *args, **kwargs):
self._check_fit()
return 1.0


Copy link
Member

Choose a reason for hiding this comment

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

These two blank lines should not have been added

@sshleifer
Copy link
Contributor Author

sshleifer commented Jul 6, 2017

is there an exhaustive list of estimators somewhere, so I can find more that don't raise NotFittedError?

In terms of a longer-term solution, maybe BaseEstimator and TransformerMixin could somehow call check_is_fitted?

@jnothman
Copy link
Member

jnothman commented Jul 6, 2017

This kind of thing is tested by way of sklearn.utils.estimator_checks. However:

  • currently metaestimators are excluded from this (although we recently implemented the ability to run check_estimator on an instance not just a class, and should probably have a test which calls check_estimator(LogisticRegression()))
  • currently we test that an error is raised when predicting on an unfitted estimator, but we don't presently require that error to be NotFittedError, only to be either an AttributeError or a ValueError.
  • no similar check is currently implemented for transformers, perhaps because some transformers happily predict without being fit.

@GaelVaroquaux
Copy link
Member

LGTM 👍 : merging now, more improvements can come later.

@GaelVaroquaux GaelVaroquaux merged commit 51c8c16 into scikit-learn:master Jul 6, 2017
massich pushed a commit to massich/scikit-learn that referenced this pull request Jul 13, 2017
* RFE can raise NotFittedError

* boom boom

* dont change tests

* tests pass

* remove two extra lines
dmohns pushed a commit to dmohns/scikit-learn that referenced this pull request Aug 7, 2017
* RFE can raise NotFittedError

* boom boom

* dont change tests

* tests pass

* remove two extra lines
dmohns pushed a commit to dmohns/scikit-learn that referenced this pull request Aug 7, 2017
* RFE can raise NotFittedError

* boom boom

* dont change tests

* tests pass

* remove two extra lines
NelleV pushed a commit to NelleV/scikit-learn that referenced this pull request Aug 11, 2017
* RFE can raise NotFittedError

* boom boom

* dont change tests

* tests pass

* remove two extra lines
paulha pushed a commit to paulha/scikit-learn that referenced this pull request Aug 19, 2017
* RFE can raise NotFittedError

* boom boom

* dont change tests

* tests pass

* remove two extra lines
AishwaryaRK pushed a commit to AishwaryaRK/scikit-learn that referenced this pull request Aug 29, 2017
* RFE can raise NotFittedError

* boom boom

* dont change tests

* tests pass

* remove two extra lines
maskani-moh pushed a commit to maskani-moh/scikit-learn that referenced this pull request Nov 15, 2017
* RFE can raise NotFittedError

* boom boom

* dont change tests

* tests pass

* remove two extra lines
jwjohnson314 pushed a commit to jwjohnson314/scikit-learn that referenced this pull request Dec 18, 2017
* RFE can raise NotFittedError

* boom boom

* dont change tests

* tests pass

* remove two extra lines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants