ValueError: Error when checking target: expected dense_3 to have shape (1,) but got array with shape (2,) 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.add(Dense(50, input_shape=(10000,))) 
model.add(Activation("relu")) 
model.add(Dense(50, activation='softmax')) 
model.add(Dense(1, activation='linear')) 

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.
Problem is in the output layer and you are using categorical_crossentropy for a loss function. Quoting Keras documentation:


  Note: when using the categorical_crossentropy loss, your targets
  should be in categorical format (e.g. if you have 10 classes, the
  target for each sample should be a 10-dimensional vector that is
  all-zeros except for a 1 at the index corresponding to the class of
  the sample). In order to convert integer targets into categorical
  targets, you can use the Keras utility to_categorical:


I would check if the target values are defined consistently. They seem to be defined for sparse_categorical_crossentropy, which requires a dense layer where number of neurons = number of classes of the problem. If they are defined as integers - as required for sparse_categorical_crossentropy, you can convert them to categorical formatting using to_categorical function, also defined in the documentation page linked above; or you can keep them as integers, and change the number of neurons in the final layer to 2, and loss function to sparse_categorical_crossentropy.