Skip to content

Instantly share code, notes, and snippets.

@VincentTatan
Created May 9, 2020 12:48
Show Gist options
  • Save VincentTatan/ae48866ff53bb61bc2a9c74512022b32 to your computer and use it in GitHub Desktop.
Save VincentTatan/ae48866ff53bb61bc2a9c74512022b32 to your computer and use it in GitHub Desktop.
def create_rfe_feature_selection(df, target_feature, n_features=3):
columns_list = list(df.columns)
columns_list.remove(target_feature)
logreg = LogisticRegression(solver='lbfgs')
rfe = RFE(logreg, n_features)
rfe = rfe.fit(df[columns_list],df[target_feature].values.ravel())
filtered_rfe_list = list(compress(df.columns, rfe.support_))
print(rfe.support_)
print(rfe.ranking_)
print(filtered_rfe_list)
return [x for _,x in sorted(zip(rfe.ranking_,columns_list))]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment