首页 > 解决方案 > 如何参考管道步骤,在管道上使用 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())])

标签: pythonscikit-learnpipelineimblearn

解决方案


只需要删除标签和几个括号,因为 make_pipeline 自己做,然后我可以使用索引 3

my_pipeline[3]

推荐阅读