Skip to content
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

ENH add importance_getter to RFE* and SelectFromModel #15361

Merged
merged 60 commits into from May 20, 2020

Conversation

venkyyuvy
Copy link
Contributor

Reference Issues/PRs

Fixes #15312

What does this implement/fix? Explain your changes.

Any other comments?

@jnothman
Copy link
Member

jnothman commented Oct 26, 2019 via email

sklearn/feature_selection/rfe.py Outdated Show resolved Hide resolved
sklearn/feature_selection/rfe.py Outdated Show resolved Hide resolved
sklearn/feature_selection/rfe.py Outdated Show resolved Hide resolved
@venkyyuvy
Copy link
Contributor Author

Thanks. We could also consider the user specifying an attribute name/path (implemented with attrgetter)

Thanks for the pointers. I have added these options now.

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.

Do you think it is clearer if we don't add the attribute path support, and just handle 'auto' and callable? Maybe I shouldn't have suggested the additional option...

sklearn/feature_selection/rfe.py Outdated Show resolved Hide resolved
sklearn/feature_selection/rfe.py Outdated Show resolved Hide resolved
sklearn/feature_selection/rfe.py Outdated Show resolved Hide resolved
@venkyyuvy
Copy link
Contributor Author

Do you think it is clearer if we don't add the attribute path support, and just handle 'auto' and callable? Maybe I shouldn't have suggested the additional option...

Nop. I think including param/path support would be user-friendly.
Previously, I had misunderstood you suggestion as to get the input as attrgetter.

sklearn/feature_selection/_rfe.py Show resolved Hide resolved
sklearn/feature_selection/_rfe.py Outdated Show resolved Hide resolved
sklearn/feature_selection/_rfe.py Outdated Show resolved Hide resolved
sklearn/feature_selection/_rfe.py Outdated Show resolved Hide resolved
@glemaitre
Copy link
Contributor

I will have a look at it. I am running behind all my late review ;P

doc/whats_new/v0.23.rst Outdated Show resolved Hide resolved
sklearn/feature_selection/_rfe.py Outdated Show resolved Hide resolved
sklearn/feature_selection/_rfe.py Show resolved Hide resolved
Copy link
Contributor

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

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

OK a couple of comments. Basically, this is fine but I think that we can avoid some code duplicate.

sklearn/feature_selection/_from_model.py Outdated Show resolved Hide resolved
sklearn/feature_selection/_from_model.py Outdated Show resolved Hide resolved
sklearn/feature_selection/_rfe.py Outdated Show resolved Hide resolved
sklearn/feature_selection/_base.py Outdated Show resolved Hide resolved
sklearn/feature_selection/_rfe.py Outdated Show resolved Hide resolved
def test_w_target_transform(importance_getter, model):
n_features = 10
X, y = make_friedman1(n_samples=50, n_features=10, random_state=0)
estimator = SVR(kernel="linear")
Copy link
Contributor

Choose a reason for hiding this comment

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

yes LinearSVR sorry for the wrong pointer.

sklearn/feature_selection/tests/test_rfe.py Outdated Show resolved Hide resolved
@@ -8,6 +8,7 @@

import numpy as np
from joblib import Parallel, delayed, effective_n_jobs
from operator import attrgetter
Copy link
Contributor

Choose a reason for hiding this comment

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

Once the refactoring done, you will not need this import ;)

@glemaitre glemaitre moved this from TO REVIEW to REVIEWED AND WAITING FOR CHANGES in Guillaume's pet May 13, 2020
Copy link
Contributor

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

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

Almost there. Only nitpicks. I would add a bit of documentation and I think that we are good to go.

sklearn/feature_selection/_base.py Outdated Show resolved Hide resolved
sklearn/feature_selection/_base.py Outdated Show resolved Hide resolved
sklearn/feature_selection/_base.py Show resolved Hide resolved
sklearn/feature_selection/_base.py Outdated Show resolved Hide resolved
sklearn/feature_selection/tests/test_rfe.py Outdated Show resolved Hide resolved
sklearn/feature_selection/tests/test_rfe.py Outdated Show resolved Hide resolved
sklearn/feature_selection/tests/test_rfe.py Outdated Show resolved Hide resolved
renaming expected_features to expected_n_features
@venkyyuvy
Copy link
Contributor Author

Do you think, we need to add the .. versionadded:: 0.24 tag for this param?

Also, would it be helpful if we add one example, which uses the importance_getter in the docstring?

@glemaitre
Copy link
Contributor

Do you think, we need to add the .. versionadded:: 0.24 tag for this param?

Good remark. Yes, we need it.

Also, would it be helpful if we add one example, which uses the importance_getter in the docstring?

We can let it for now. I think that with the user guide it should be enough.

Copy link
Contributor

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

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

Just 2 quick changes and the version added and we are good to merge.

sklearn/feature_selection/_from_model.py Outdated Show resolved Hide resolved
sklearn/feature_selection/_from_model.py Outdated Show resolved Hide resolved
@venkyyuvy
Copy link
Contributor Author

We can let it for now. I think that with the user guide it should be enough.

Even the user guide is not updated as well.
Guess we need to update that?

Also there is no reference for user guide in documentation

@jnothman jnothman changed the title ENH add importance_getter to RFE* to get importances from meta-estimators ENH add importance_getter to RFE* and SelectFromModel May 20, 2020
@jnothman jnothman merged commit f6b8bc0 into scikit-learn:master May 20, 2020
@jnothman
Copy link
Member

Thanks @venkyyuvy!! Nice work!

@glemaitre glemaitre moved this from REVIEWED AND WAITING FOR CHANGES to MERGED in Guillaume's pet May 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

Compatability issue with TransformeredTargetRegressor and RFECV
3 participants