python feature selection in pipeline: how determine feature names?

后端 未结 3 1771
眼角桃花
眼角桃花 2021-02-03 12:11

i used pipeline and grid_search to select the best parameters and then used these parameters to fit the best pipeline (\'best_pipe\'). However since the feature_selection (Selec

3条回答
  •  -上瘾入骨i
    2021-02-03 13:05

    This could be an instructive alternative: I encountered a similar need as what was asked by OP. If one wants to get the k best features' indices directly from GridSearchCV:

    finalFeatureIndices = gs.best_estimator_.named_steps["feat"].get_support(indices=True)
    

    And via index manipulation, can get your finalFeatureList:

    finalFeatureList = [initialFeatureList[i] for i in finalFeatureIndices]
    

提交回复
热议问题