I have implemented one pipeline for my categorical features (cat_transformer_ordinal) with an Ordinal Encoder, but when I want get the features names, the method (get_feature_names_out()) doesn't work. I couldn't find why.
SimpleImputer.get_feature_names_out = (lambda self, names=None:self.feature_names_in_)
encoder_ordinal = OrdinalEncoder(
categories=feat_ordinal_values_sorted,
dtype= np.int64,
handle_unknown="use_encoded_value",
unknown_value=-1 # Considers unknown values as worse than "missing"
)
num_transformer = make_pipeline(SimpleImputer(), StandardScaler())
num_col = make_column_selector(dtype_include=['float64', 'int64'])
cat_transformer_ordinal = make_pipeline(SimpleImputer(strategy="constant", fill_value="missing"),
encoder_ordinal,
MinMaxScaler())
cat_col_onehot = list(set(features_categorical_small) - set(feat_ordinal))
preproc_pipeline = make_column_transformer(
(num_transformer, num_col),
(cat_transformer_ordinal, feat_ordinal),
(OneHotEncoder(), cat_col_onehot)
)
X = preproc_pipeline.fit_transform(df_train)
preproc_pipeline.get_feature_names_out()
I get this error :
749 for _, name, transform in self._iter():
750 if not hasattr(transform, "get_feature_names_out"):
--> 751 raise AttributeError(
752 "Estimator {} does not provide get_feature_names_out. "
753 "Did you mean to call pipeline[:-1].get_feature_names_out"
AttributeError: Estimator ordinalencoder does not provide get_feature_names_out. Did you mean to call pipeline[:-1].get_feature_names_out()?
I don't understand why... Because now the get_feature_names_out() is implemented for all the sklearn.preprocessing module