RFE ran without errors, but how do I see which features it kept and how it ranked the others?
How RFE works
Recursive Feature Elimination fits a model, ranks the features by importance, removes the weakest one(s), and repeats until n_features_to_select remain. Along the way it records the order in which features were eliminated, so you get both a final selection and a full ranking.
Answer 1: Use support_ and ranking_
support_ is a boolean mask of the selected features. ranking_ gives every feature a rank: selected features get rank 1, the last feature eliminated gets rank 2, and so on. Higher numbers mean the feature was removed earlier, so it was considered less important.
from sklearn.feature_selection import RFE
from sklearn.linear_model import LogisticRegression
rfe = RFE(LogisticRegression(max_iter=1000),
n_features_to_select=5)
rfe.fit(X, y)
print("Selected:", X.columns[rfe.support_].tolist())
ranking = pd.Series(rfe.ranking_, index=X.columns).sort_values()
print(ranking)
