Feature names from OneHotEncoder

后端 未结 3 1185
我寻月下人不归
我寻月下人不归 2021-02-05 03:46

I am using OneHotEncoder to encode few categorical variables (eg - Sex and AgeGroup). The resulting feature names from the encoder are like - \'x0_female\', \'x0_male\', \'x1_0.

3条回答
  •  無奈伤痛
    2021-02-05 04:22

    Thanks for a nice solution. @Nursnaaz The sparse matrix needs to convert into a dense matrix.

    column_name = encoder.get_feature_names(['Sex', 'AgeGroup'])
    one_hot_encoded_frame =  pd.DataFrame(train_X_encoded.todense(), columns= column_name)
    

提交回复
热议问题