0
#10-Fold split
seed = 7
kfold = StratifiedKFold(n_splits=10, shuffle=True, random_state=seed)
np.random.seed(seed)
cvscores = []

    act = 'relu'
    for train, test in kfold.split(X, Y):

        model = Sequential()

        model.add(Dense(43, input_shape=(8,)))
        model.add(Activation(act))

        model.add(Dense(500))
        model.add(Activation(act))
    #model.add(Dropout(0.4))

        model.add(Dense(1000))
        model.add(Activation(act))
    #model.add(Dropout(0.4))

        model.add(Dense(1500))
        model.add(Activation(act))
    #model.add(Dropout(0.4))


        model.add(Dense(2))
        model.add(Activation('softmax'))

        model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
        hist = model.fit(X[train], Y[train],
                    epochs=500,
                    shuffle=True,
                    batch_size=100,
                    validation_data=(X[test], Y[test]), verbose=2)
    #model.summary()

When I call model.fit it reports the following error :

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

I am using keras with TensorFlow backend. Please ask for any further clarification if needed.

Jefferson
  • 794
  • 10
  • 24
  • Maybe https://stackoverflow.com/q/45120429/1741542 helps a bit. Beyond that, the main point seems to be "expected activation_5 to have *shape* (None, 2) but got *array with shape* (3869, 1)" – Olaf Dietsche Aug 14 '17 at 16:35

1 Answers1

0

The problem was solved when we used this statement

y = to_categorical(Y[:])
Tanmay Bhatnagar
  • 2,330
  • 4
  • 30
  • 50