现在,这是我用来构建神经网络的代码:
# define the architecture of the network
model = Sequential()
model.add(Dense(50, input_dim=X_train.shape[1], init="uniform", activation="relu"))
model.add(Dense(38, activation="relu", kernel_initializer="uniform"))
model.add(Dense(1, activation = 'sigmoid'))
print("[INFO] compiling model...")
adam = Adam(lr=0.01)
model.compile(loss="binary_crossentropy", optimizer=adam,
metrics=["accuracy"])
model.fit(X_train, Y_train, epochs=50, batch_size=128,
verbose=1)
当我这样做时,我收到以下错误:
KeyError: '[233946 164308 296688 166151 276165 88219 117980 163503 182033 164328\n 188083 30380 37984 245771 308534 6215 181186 307488 172375 60446\n 29397 166681 5587 243263 103579 262182 107823 234790 258973 116433\n 199283 86118 172148 257334 286452 248407 81280 ...] not in index'
我还没有找到解决这个问题的方法。任何帮助将非常感激。
最佳答案
我相信输入不是 numpy 数组,如 github issue 中所述。在 keras 页面上
尝试使用以下方法拟合模型:
model.fit(np.array(X_train), np.array(Y_train), epochs=50, batch_size=128,
verbose=1)
在拟合数据时会将数组转换为 numpy 数组。
关于python - 在 Keras 中构建简单的前馈神经网络时遇到关键错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55909129/