ValueError: Error when checking target: expected dense_3 to have shape (1,) but got array with shape (2,) [closed]

I am trying to build a CNN model on Keras. The data has a dimension of 921 rows × 10000 columns.

Here is the code:

import numpy as np
import keras
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten, Activation
from keras.optimizers import SGD

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(merge.iloc[:,166:10166], merge[['Result_cat','Result_cat1']].values, test_size=0.2)

model = Sequential()

model.compile(loss=keras.losses.categorical_crossentropy,
optimizer=keras.optimizers.SGD(lr=0.01),
metrics=['accuracy'])

model.fit(X_train, y_train, batch_size=100, epochs=10)
score = model.evaluate(X_test, y_test, batch_size=32)


Then I encountered error

ValueError: Error when checking target: expected dense_3 to have shape (1,) but got array with shape (2,)

I am new to Keras and CNN. Can someone please explain to me what this means and how I can fix this? Thanks.

• thank you! The data has a temperature time series data in each row for each observation, and classification labelling Y/N in the last two columns. It worked after changing the number of neurones in the final layer to 2. However, after making the change to batch_size=1000, epochs=1000, I experienced a repeated loss/ accuracy level for each Epoch:736/736 [==============================] - 0s 563us/step - loss: 1.9146 - acc: 0.5584. Is there a way I can fix this? Nov 18 '19 at 12:31