Skip to content

Instantly share code, notes, and snippets.

@satkr7

satkr7/rfe.py Secret

Created April 18, 2021 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save satkr7/f5ececd972057f9111cd701082ef29c3 to your computer and use it in GitHub Desktop.
Save satkr7/f5ececd972057f9111cd701082ef29c3 to your computer and use it in GitHub Desktop.
from sklearn.feature_selection import RFE
from sklearn.linear_model import LogisticRegression
rfe_selector = RFE(estimator=LogisticRegression(), n_features_to_select=10, step=1, importance_getter='auto')
rfe_selector.fit(X, y)
# The best set of features that are selcted, denoted as True, False
print(selector.support_)
# All selected features are marked 1, the unselected redundant features ranked in increasing order
print(selector.ranking_)
# Get a mask, or integer index, of the features selected
rfe_support = rfe_selector.get_support()
rfe_feature = X.loc[:,rfe_support].columns.tolist()
print(str(len(rfe_feature)), 'selected features')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment