8

I am trying to extract the features using the get_feature_names function of the OneHotEncoder object of scikit learn but its is throwing me an error saying "'OneHotEncoder' object has no attribute 'get_feature_names'".

Below is the code snippet

# Creating the object instance for label encoder
encoder = OneHotEncoder(sparse=False)
onehot_encoded = encoder.fit_transform(df[data_column_category])
onehot_encoded_frame = pd.DataFrame(onehot_encoded,columns = encoder.get_feature_names(data_column_category))
Joe
  • 83
  • 1
  • 1
  • 5

2 Answers2

1

That feature was introduced recently, so you might just need to update your sklearn version.

You can do it as follows:

pip install -U scikit-learn
DaveR
  • 1,696
  • 18
  • 24