I have create a simple code to implement OneHotEncoder
.
from sklearn.preprocessing import OneHotEncoder
X = [[0, 'a'], [0, 'b'], [1, 'a'], [2, 'b']]
onehotencoder = OneHotEncoder(categories=[0])
X = onehotencoder.fit_transform(X).toarray()
I just want to use method called fit_transform
to the X
for index 0
, so it means for [0, 0, 1, 2]
like what you see in X
. But it causes an error like this :
ValueError: Shape mismatch: if categories is an array, it has to be of shape (n_features,).
Anyone can solve this problem ? I am stuck on it