image_output_1.png
from sklearn.feature_selection import RFE

from sklearn.feature_selection import RFECV

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)
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)

from sklearn.feature_selection import RFECV
logreg_3 = LogisticRegression()
rfecv = RFECV(estimator=logreg_3, step=1, cv=5, scoring='accuracy')
rfecv = rfecv.fit(X_train, Y_train)
print('Optimal number of features :', rfecv.n_features_)
print('Best features :', X_train.columns[rfecv.support_])