如何从 Sklearn 管道中提取特征重要性 [英] How to extract feature importances from an Sklearn pipeline

查看:72
本文介绍了如何从 Sklearn 管道中提取特征重要性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Scikit-Learn 中构建了一个管道,分为两个步骤:一个是构建特征,第二个是 RandomForestClassifier.

I've built a pipeline in Scikit-Learn with two steps: one to construct features, and the second is a RandomForestClassifier.

虽然我可以保存该管道,但查看各个步骤和步骤中设置的各种参数,我希望能够从生成的模型中检查特征重要性.

While I can save that pipeline, look at various steps and the various parameters set in the steps, I'd like to be able to examine the feature importances from the resulting model.

这可能吗?

推荐答案

啊,是的.

您列出要检查估算器的步骤:

You list identify the step where you want to check the estimator:

例如:

pipeline.steps[1]

哪个返回:

('predictor',
 RandomForestClassifier(bootstrap=True, class_weight=None, criterion='gini',
             max_depth=None, max_features='auto', max_leaf_nodes=None,
             min_samples_leaf=1, min_samples_split=2,
             min_weight_fraction_leaf=0.0, n_estimators=50, n_jobs=2,
             oob_score=False, random_state=None, verbose=0,
             warm_start=False))

然后您可以直接访问模型步骤:

You can then access the model step directly:

pipeline.steps[1][1].feature_importances_

pipeline.steps[1][1].feature_importances_

这篇关于如何从 Sklearn 管道中提取特征重要性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆