相关疑难解决方法(0)

从scikit管道中提取选定的要素名称

# 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)
Run Code Online (Sandbox Code Playgroud)

上述代码基于确保scikit learn中随机森林分类中的操作顺序

由于我使用的是SelectFromModel,我想打印所选功能的名称(在SelectFromModel管道中),但不确定如何提取它们.

python numpy scikit-learn

3
推荐指数
2
解决办法
3528
查看次数

标签 统计

numpy ×1

python ×1

scikit-learn ×1