简体   繁体   中英

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

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())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM