What are the differences between the below feature selection methods?

Do the below codes do the same? If not, what are the differences?

fs = RFE(estimator=RandomForestClassifier(), n_features_to_select=10)
fs.fit(X, y)
print(fs.support_)
fs= RandomForestClassifier(),
fs.fit(X, y)
print(fs.feature_importances_[:10,])

Topic scikit-learn feature-selection machine-learning

Category Data Science


They are not the same.

As the name suggests, "recursive feature elimination" (RFE) recursively eliminates features, by fitting the model and throwing away the least-important one(s). After removing one feature, the next iteration may find the remaining features have changed order of importance. This is especially true in the presence of correlated features: they may split importance when included together, so might both be dropped by your second approach; but in RFE, one gets dropped at some point, but then the other one appears more important in the following iterations (since it no longer splits its importance with its now-dropped companion) and so is kept.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.