I have 4 classes which I need to predict, am using keras' to_categorical
to achieve that, I expected to get a 4 one-hot-encoded
array, but it seems I get 5 values instead, an additional [0]
value appears for all rows
dict = {'word': 1, 'feature_name': 2, 'feature_value': 3, 'part_number': 4}
Y = dataset['class'].apply(lambda label: dict[label])
print(Y.unique()) #prints [1 4 2 3]
train_x, test_x, train_y, test_y = model_selection.train_test_split(X, Y, test_size=0.2, random_state=0)
train_y = to_categorical(train_y)
print(train_y[0])# prints [0. 0. 1. 0. 0.]
the model am trying to build is as follows
model = Sequential()
model.add(Dense(10, input_dim=input_dim, activation='relu'))
model.add(Dense(10, activation='relu'))
model.add(Dense(10, activation='relu'))
model.add(Dense(10, activation='relu'))
model.add(Dense(4, activation='softmax'))
but then it keeps throwing
ValueError: Error when checking target: expected dense_5 to have shape (4,) but got array with shape (5,)