如何参考流水线步骤,在流水线上使用 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]