Consider the following ColumnTransformer code:
tree_preprocessor = ColumnTransformer(
[
(
"categorical",
OrdinalEncoder(),
["region","trade","shipping","payment","channel","device"]
),
(
"numeric",
"passthrough",
["bag_total", "hero_total", "acc_ind"]
),
# Custom Function for array hot encoding
(
"array_one_hot_encode",
MultiHotEncoder(df=df_final),
["model_list"]
)
],
remainder="drop",
)
How can I access the features of the categorical
transformer?
What I'm trying to do is create a DataFrame post fit_transform()
.
SKLearn does not have get_feature_names_out()
for all its transformers, so I would like to loop through each transformer in the ColumnTransformer and pull the features post fit (if possible). Otherwise, pull the input feature names out.
For example, because OrdinalEncoder()
does not have get_feature_names_out()
, I would like to access the original feature list (["region","trade","shipping","payment","channel","device"]
)
However, for MultiHotEncoder, I built a custom get_feature_names_out()
function, so it should definitely work and will return a list of columns post transformation.