Imagine you have many features in your dataset. What does RFE try to do with these features?
Think about how RFE helps simplify the model by focusing on key features.
RFE works by repeatedly training a model and removing the weakest features until the desired number remains. This helps keep only the most useful features.
Given the code below, what will be the shape of X_rfe?
from sklearn.datasets import load_iris from sklearn.feature_selection import RFE from sklearn.linear_model import LogisticRegression iris = load_iris() X = iris.data Y = iris.target model = LogisticRegression(max_iter=200) rfe = RFE(model, n_features_to_select=3) rfe = rfe.fit(X, Y) X_rfe = rfe.transform(X) print(X_rfe.shape)
RFE reduces the number of features but keeps the number of samples the same.
The original data has 150 samples and 4 features. After RFE selects 3 features, the shape becomes (150, 3).
You want to use RFE to select features for a classification task with a small dataset. Which model below is most appropriate to use with RFE?
RFE needs a model that can provide feature importance or coefficients.
Logistic Regression provides coefficients that RFE uses to rank features. KNN and K-Means do not provide feature importance, and PCA is a dimensionality reduction method, not a model for RFE.
n_features_to_select control in RFE?In Recursive Feature Elimination, what is the role of n_features_to_select?
Think about how many features you want to end up with after RFE finishes.
The n_features_to_select parameter tells RFE how many features to keep after the elimination process.
You applied RFE to select features and trained a model. Which metric comparison best shows if RFE helped?
Think about how to know if the model got better at predicting new data.
Comparing accuracy on a test set before and after RFE shows if the feature selection improved the model's ability to predict unseen data.