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
CodePudding user response:
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())