text_html_output_1.png text_plain_output_1.png
from sklearn.feature_selection import RFE

from sklearn.linear_model import LogisticRegression

from sklearn.linear_model import LogisticRegression
logreg = LogisticRegression(C=10)
logreg.fit(X_train, Y_train)
Y_predict1 = logreg.predict(X_test)

score_logreg = logreg.score(X_test, Y_test)

from sklearn.feature_selection import RFE
logreg_2 = LogisticRegression()
rfe = RFE(estimator=logreg_2, n_features_to_select=5, step=1)
rfe = rfe.fit(X_train, Y_train)
print('Chosen best 5 feature by rfe:', X_train.columns[rfe.support_])
X_train_3 = rfe.transform(X_train)
X_test_3 = rfe.transform(X_test)
logreg_2 = LogisticRegression()
logreg_2 = logreg_2.fit(X_train_3, Y_train)
Y_predict2 = logreg.predict(X_test_3)
score_logreg = logreg_2.score(X_test_3, Y_test)
print(score_logreg)