I understand that if I run a OneHotEncoder by itself, I am able to change the feature names that it generates from x1_1, x1_2, etc. by calling .get_feature_names e.g.:
encoder.get_feature_names(['Sex', 'AgeGroup'])
will change x1_1, x2_2 to AgeGroup_1, AgeGroup_2 etc.
However, if I run the OneHotEncoder as one of a few transformations in a ColumnTransformer, how would I be able to change set prefix?
- Is there a way to set this prefix before the encoding even starts, e.g. within the initialization parameters to
OneHotEncoder, or - somehow in-line with the
ColumnTransformer, or - without doing some string parsing replacement parsing on the columns after the
fit_transform?