python 3.x - Error in last layer of neural network -
#10-fold split seed = 7 kfold = stratifiedkfold(n_splits=10, shuffle=true, random_state=seed) np.random.seed(seed) cvscores = [] act = 'relu' 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 call model.fit it reports following error :
valueerror: error when checking target: expected activation_5 have shape (none, 2) got array shape (3869, 1)
i using keras tensorflow backend. please ask further clarification if needed.
the problem solved when used statement
y = to_categorical(y[:])
Comments
Post a Comment