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

Skip to content

Conversation

GaetandeCast
Copy link
Contributor

@GaetandeCast GaetandeCast commented Sep 22, 2025

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 to sklearn.feature_selection._base._get_feature_importances that is given to the importance_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

Copy link

github-actions bot commented Sep 22, 2025

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: db66df6. Link to the linter CI: here

@GaetandeCast GaetandeCast changed the title base logic and test FEAT allow RFE(CV) be used with pemutation_importance Sep 22, 2025
Copy link
Member

@ogrisel ogrisel left a 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

Comment on lines 7 to 8
This allows methods like :func:`permutation_importance` to extract the relevant features
from its test set.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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.

Copy link
Contributor Author

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."

@GaetandeCast GaetandeCast marked this pull request as ready for review September 25, 2025 14:13
Copy link
Member

@ogrisel ogrisel left a 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:

`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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
`feature_indices` allows RFE to be used with permutation importance, as
`feature_indices` allows `RFE` to be used with permutation importance, as

`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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
`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
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEAT] Let importance_getter from RFE accept test data for permutation importance
2 participants