简体   繁体   中英

AttributeError: 'ColumnTransformer' object has no attribute 'transformers_'

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.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM