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)

onehotencoder = OneHotEncoder(categorical_features=[0])
Y =

>Solution :

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)

Leave a Reply