Extracting selected feature names from scikit pipeline
<pre><code># Load dataset
iris = datasets.load_iris()
X, y = iris.data, iris.target

rf_feature_imp = RandomForestClassifier(100)
feat_selection = SelectFromModel(rf_feature_imp, threshold=0.5)

clf = RandomForestClassifier(5000)

model = Pipeline([
          ('fs', feat_selection), 
          ('clf', clf), 
        ])

 params = {
    'fs__threshold': [0.5, 0.3, 0.7],
    'fs__estimator__max_features': ['auto', 'sqrt', 'log2'],
    'clf__max_features': ['auto', 'sqrt', 'log2'],
 }

 gs = GridSearchCV(model, params, ...)
 gs.fit(X,y)
</code></pre>

<p>The above code is based on <a href="https://stackoverflow.com/questions/35256876/ensuring-right-order-of-operations-in-random-forest-classification-in-scikit-lea">Ensuring right order of operations in random forest classification in scikit learn</a></p>

<p>Since I am using SelectFromModel, I would like to print the names of the features that were selected (in the SelectFromModel pipeline), but not sure how to extract them.</p>