Created
May 9, 2020 12:48
-
-
Save VincentTatan/ae48866ff53bb61bc2a9c74512022b32 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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