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()
的最後一層當我打電話model.fit它報告以下錯誤:錯誤在神經網絡
ValueError: Error when checking target: expected activation_5 to have shape (None, 2) but got array with shape (3869, 1)
我使用keras與TensorFlow後端。如有需要,請要求進一步澄清。
問題解決了也許https://stackoverflow.com/q/45120429/1741542有點幫助。除此之外,主要觀點似乎是「預期activation_5具有*形狀*(無,2),但是得到*具有形狀的數組*(3869,1)」 –