-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
[WIP] Implemented SelectFromModel meta-transformer #3011
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
Conversation
Thanks for tackling this. A number of points:
I'm changing this PR to a [WIP]. I hope that's alright with you. |
Also, the failing tests happen because this can't be constructed as it is. I think it should be included here: https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/utils/testing.py#L441. And although it does nothing at the moment, please inherit from |
I have separated out the section where Other issues are fixed. |
|
||
return estimator | ||
|
||
def __init__(self, estimator=None, threshold=None): |
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.
Please move this method to right below the class docstring.
estimator=None
is not useful. Leave it without a default.
Since When |
The correct way is to redefine |
if self.estimator_ is None: | ||
raise ValueError("estimator cannot be None") | ||
|
||
def _make_estimator(self): |
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.
Please inline this method.
I don't think it's a good idea to store |
self.estimator = self._make_estimator() | ||
|
||
# Convert data | ||
X, y = check_arrays(X, y) |
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 don't think this belongs here. It's the base estimator's business.
Btw, it may be cleaner to implement this with the metaestimator not inheriting from the mixin. Please feel free to do it that way if you think it improves the code. |
I couldn't find a way to implement |
This should probably support |
@jnothman, I apologize for the inconvenience, Can you explain what exactly needs to be done in |
importances = estimator.feature_importances_ | ||
if importances is None: | ||
raise ValueError("Importance weights not computed. Please set " | ||
"the compute_importances parameter before fit.") |
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.
This is deprecated in forests. You can remove this if-statement.
The only reason I say it's necessary is because it's a way the current mixin can be used. |
I have added BTW is there something wrong with Travis CI? It doesn't seem to be building my last two commits. |
It's highly non user-friendly, but this means that it can't automatically merge your work with master, which it does before testing. Could you please rebase on the current master and force-push the rebased branch? |
Returns self. | ||
""" | ||
if not hasattr(self.estimator, "partial_fit"): | ||
raise(AttributeError, "estimator does not have" |
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.
That (
can't be there for this to be correct syntax in Python 3.
But I think it's fine if you don't explicitly check this case. The AttributeError
produced by self.estimator_.partial_fit
(e.g. ''LinearSVC' object has no attribute 'partial_fit'') is clear enough.
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.
Yes, I agree.
I removed the test case for that as well.
I'm not sure the tests are quite satisfactory yet (and I might not be around for the next few days to take another look), but I think we need to seek opinions as to whether a meta-estimator improves on the mixin. @glouppe, WDYT, and who else is likely to be opinionated on this? |
What are the tests that need to be improved. I can work on those. |
I'm not able to look in great detail at the tests right now, but in order On 2 April 2014 02:35, maheshakya notifications@github.com wrote:
|
Thanks. I will give it a shot. (for improved test cases, examples and documentation) |
I suppose we need to change every example that uses feature selection based on LearntSelectorMixin, right? |
Yes, unfortunately. |
It seems that there are unrelated changes. I'm not sure how adding a meta-transformer should affect travis.yml |
Closed in favor of #4242 . I rescued this PR from git hell! |
Fix for #2160
Implemented a meta-transformer to with
_LearntSelectorMixin
. Test cases are included.Documentation(with examples) needs to be completed.