I am using a simple ColumnTransformer with StandardScaler and OneHotEncoder like:
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import StandardScaler
from sklearn.preprocessing import OneHotEncoder
num_features = ['num_feat_1',
'num_feat_2',
'num_feat_3']
cat_features = ['cat_feat_1',
'cat_feat_2',
'cat_feat_3']
ct = ColumnTransformer([
("scaler", StandardScaler(), num_features),
("onehot", OneHotEncoder(sparse=False,
handle_unknown='ignore'), cat_features)],
remainder='passthrough')
ct.fit(X_train)
X_train_trans = ct.transform(X_train)
X_test_trans = ct.transform(X_test)
To map the coefficients of a LinearRegression, I need ct.get_feature_names(), but I get the error Transformer scaler (type StandardScaler) does not provide get_feature_names. Why is that and how can I solve this?