开发者

Get feature names after OneHotEncoder through ColumnTransformer

I want to get feature names after I fit the pipeline.

cat_attribs = ['isveteran','isgreenliving','dwelling_type_desc',
               'cat_owner','dog_owner','sports_grouping','outdoors_grouping',
               'reading_grouping','cooking_food_grouping','exercise_health_grouping',
               'movie_music_grouping','electronics_computers_grouping','home_improvement_grouping','investing_finance_grouping',
               'collectibles_and_antiques_grouping','paymentmethodsource',
               'marital_status_desc','household_income_class','household_composition','household_education','home_exterior_desc',
               'home_heat_source_desc','home_heating_cooling_desc','children_number_in_household_desc','household_age_range',
               'gender','grandchildren','career','education_online']

# 'sqft_desc','lot_sqft_desc',

#set the numerical attributes
num_attribs = list( Exelon.drop(cat_attri开发者_StackOverflowbs, axis=1) )

num_attribs

num_pipeline = Pipeline( [
  ('imputer', SimpleImputer(strategy="median")),
  ('std_scaler', StandardScaler()), 
])

#define the pipeline process for the data set
full_pipeline = ColumnTransformer( [
    ('num', num_pipeline, num_attribs),
    ('cat', OneHotEncoder(sparse=False), cat_attribs)      
])

Finally

X = Exelon.sample(n=20000)
X_set = pd.DataFrame(full_pipeline.fit_transform(X))

df_sample = full_pipeline.get_feature_names(X_set)

After fitting with dataframe, I was trying to gather feature names but I end up getting an error:

TypeError: get_feature_names() takes 1 positional argument but 2 were given

Please advise on how I can column names after going through the pipeline.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜