Issue
I get this error when trying to get the list of transformers for a ColumnTransformer like this after the fit has been called via GridSearchCV. My ultimate goal is to get the feature names after the preprocessor step:
clf.named_steps['preprocessor'].transformers_
Calling the get_feature_names_out() on the clf (the pipeline) doesn't work because it ways the ColumnTransformer hasn't been fitted yet.
Solution
It's because of the grid search. That clones the estimator for each candidate fit including the final refit, so the original estimator you passed never gets fit. The final (re)fitted model lives in the grid search object's best_estimator_
attribute, so something like grid_search.best_estimator_.named_steps['preprocessor'].transformers_
should work (and indeed, get_feature_names_out()
should work on this object as well).
Answered By - Ben Reiniger
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.