0
0
ML Pythonml~20 mins

Recursive feature elimination in ML Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
RFE Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the main goal of Recursive Feature Elimination (RFE)?

Imagine you have many features in your dataset. What does RFE try to do with these features?

AIt tries to select the most important features by removing the least important ones step by step.
BIt creates new features by combining existing ones to improve model accuracy.
CIt randomly removes features to reduce dataset size without considering importance.
DIt increases the number of features by duplicating existing ones to add more data.
Attempts:
2 left
💡 Hint

Think about how RFE helps simplify the model by focusing on key features.

Predict Output
intermediate
2:00remaining
What is the output shape of X after applying RFE with 3 features?

Given the code below, what will be the shape of X_rfe?

ML Python
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)
A(4, 150)
B(150, 4)
C(3, 150)
D(150, 3)
Attempts:
2 left
💡 Hint

RFE reduces the number of features but keeps the number of samples the same.

Model Choice
advanced
2:00remaining
Which model is best suited for RFE in this scenario?

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?

ALogistic Regression with L2 regularization
BK-Nearest Neighbors without feature importance
CK-Means clustering
DPrincipal Component Analysis (PCA)
Attempts:
2 left
💡 Hint

RFE needs a model that can provide feature importance or coefficients.

Hyperparameter
advanced
2:00remaining
What does the hyperparameter n_features_to_select control in RFE?

In Recursive Feature Elimination, what is the role of n_features_to_select?

AIt specifies the percentage of features to remove at each step.
BIt sets the number of features to keep after elimination.
CIt controls the number of iterations to run the model.
DIt defines the minimum importance score for features to be kept.
Attempts:
2 left
💡 Hint

Think about how many features you want to end up with after RFE finishes.

Metrics
expert
2:00remaining
How to evaluate if RFE improved model performance?

You applied RFE to select features and trained a model. Which metric comparison best shows if RFE helped?

ACompare the time taken to train the model without checking accuracy.
BCompare training loss only on the training data before and after RFE.
CCompare model accuracy on a test set before and after RFE.
DCompare the number of features selected without checking model results.
Attempts:
2 left
💡 Hint

Think about how to know if the model got better at predicting new data.