John
John

Reputation: 81

SKLEARN: TypeError: __init__() got an unexpected keyword argument 'categorical_features'

working with sklearn and getting an error on categorical_features. I understand that it's deprecated, but I really don't know who to rework this to use ColumnTransformer. Any help much appreciated.

from sklearn.preprocessing import LabelEncoder, OneHotEncoder
y = houses_df['house_type'].values
y_labelencoder = LabelEncoder()
y = y_labelencoder.fit_transform(y)

y=y.reshape(-1,1)
onehotencoder = OneHotEncoder(categorical_features=[0])
Y = onehotencoder.fit(y)
Y.shape

Upvotes: 1

Views: 1207

Answers (1)

Prakash Dahal
Prakash Dahal

Reputation: 4875

OneHotEncoder do not take any parameter called categorical_features. If you do not specify any parameter, it will take categories as auto. If you want specific categories to be one hot encoded, use categories parameter.

Use this.

onehotencoder = OneHotEncoder()
new_y = onehotencoder.fit_transform(y)
print(new_y.shape)
print(new_y.toarray())

Upvotes: 1

Related Questions