-
-
Notifications
You must be signed in to change notification settings - Fork 26.3k
FEAT allow RFE(CV) be used with pemutation_importance
#32251
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
base: main
Are you sure you want to change the base?
Conversation
pemutation_importance
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.
Thanks for the PR. This is very useful. Please indeed update the example and add a changelog entry.
EDIT: here are the instructions for the changelog entry: https://github.com/scikit-learn/scikit-learn/blob/main/doc/whats_new/upcoming_changes/README.md
This allows methods like :func:`permutation_importance` to extract the relevant features | ||
from its test set. |
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 allows methods like :func:`permutation_importance` to extract the relevant features | |
from its test set. | |
This allows methods like :func:`permutation_importance` and similar tools to | |
iteratively extract the previously selected features from a test set. |
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.
yeah I realized it was not very clear so I planned to change it to:
" This allows methods that need a test set, like :func:permutation_importance
, to know which
features of to use in their predictions."
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.
LGTM besides the following:
sklearn/feature_selection/_rfe.py
Outdated
`feature_indices` which stores the index of the features in the full dataset | ||
that have not been eliminated yet. | ||
`feature_indices` allows RFE to be used with permutation importance, as |
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.
`feature_indices` allows RFE to be used with permutation importance, as | |
`feature_indices` allows `RFE` to be used with permutation importance, as |
sklearn/feature_selection/_rfe.py
Outdated
`feature_indices` which stores the index of the features in the full dataset | ||
that have not been eliminated yet. | ||
`feature_indices` allows RFECV to be used with permutation importance, as |
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.
`feature_indices` allows RFECV to be used with permutation importance, as | |
`feature_indices` allows `RFECV` to be used with permutation importance, as |
If `callable`, overrides the default feature importance getter. | ||
The callable is passed with the fitted estimator and it should | ||
return importance for each feature. | ||
return importance for each feature. When it accepts it, the callable is passed |
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.
While we are at it, can you please fix the missing backtick before :class:
to get the ~sklearn.pipeline.Pipeline
link to render properly in HTML?
Reference Issues/PRs
Fixes #32201
What does this implement/fix? Explain your changes.
To be used in RFE and RFECV,
permutation_importance
needs to be aware of which features were already eliminated by the procedure to reduce its test dataset.This PR adds a
feature_indices
parameter tosklearn.feature_selection._base._get_feature_importances
that is given to theimportance_getter
so that it is aware of which features to compute the importance of.Any other comments?
The new feature is added to the test suite and illustrated in the
RFECV
doc example.@glemaitre @ogrisel