![](/img/trans.png)
[英]Extracting feature importances from an sklearn pipeline containing a multioutputclassifier within gridsearchcv?
[英]Extracting feature importances along with column names from sklearn pipeline
我有一个包含两个步骤的 sklearn 管道(一个带有 One hot 编码器的 columntransformer 预处理器和一个 randomforestregressor 估计器)。 我想在一次热编码后获取编码列的特征名称。 我的管道看起来像这样。
categorical_preprocessor = OneHotEncoder(handle_unknown="ignore")
# Model processor
preprocessor = ColumnTransformer(
[('categorical', categorical_preprocessor, categorical_columns)], remainder="passthrough")
est = RandomForestRegressor(
n_estimators=100, random_state=0)
pipe = make_pipeline(preprocessor,est)
我正在尝试获取编码列的特征名称,如下所示:
管道['预处理器'].transformers[0][0].get_feature_names(categorical_columns)
但是我得到一个错误。
'str' object 没有属性 'get_feature_names'
scikit-learn 1.0 显然有一个新功能,我们将功能名称提取为:
pipeline[:-1].get_feature_names_out()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.