Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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())
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading