python - 如何参考管道步骤,在管道上使用 feature_importance_?
问题描述
我正在使用 imblearn 的 make_pipeline 函数进行一些数据准备和建模。现在我想在我的模型上使用 feature_importance_ 方法。但由于我的模型是我管道的一部分,我不能使用这种方法。所以我想参考我管道中的模型。因此,我稍微修改了我的管道代码,为我的管道步骤指定了特定名称。但这不起作用。
我的代码:
my_pipeline = make_pipeline([( make_column_transformer(
(make_pipeline(
MinMaxScaler()
), ['column_a','column_b']),
remainder="passthrough")),
(PCA()),
(SMOTE()),
("classifier",RandomForestClassifier())])
解决方案
只需要删除标签和几个括号,因为 make_pipeline 自己做,然后我可以使用索引 3
my_pipeline[3]
推荐阅读
- python - pygame 中缺少位置参数
- python - 使用 OpenCV 将 RGB 注册到具有不同分辨率和视场的热图像
- c++ - 一个函数只返回一个索引而不是两个或更多 | C++
- json - 如何使用特定数据附加 JSON 数组
- ios - 升级到 Uno.UI 3.9.7 后出现异常:FrameNavigationController 多次推送同一个视图控制器实例 PageViewController
- edmx - Business Central API 列表扩展/发布者
- java - Android dispatchKeyEvent , onKeyDown 回调不适用于手势音量控制(华为 mate 30 pro)
- reporting-services - 使用报表查看器控件的 SSRS 报表
- ios - WidgetKit 在小部件显示数据之前运行函数
- scala - 如何将 scala 中的数据框保存为 csv ?csv函数不工作