python - 在 Keras 中构建简单的前馈神经网络时遇到关键错误

标签 python pandas keras neural-network

这是我的数据集的快照,包括其形状: dataset

现在,这是我用来构建神经网络的代码:

# 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/

相关文章:

python - 在帕斯卡三角形中使用 raw_input

java - 如何在从keras导出的java中加载tensorflow .pb模型

python - Tensorflow 2.0 结合 CNN + LSTM

Python:关闭终端窗口后,带有 'print' 的 GUI 函数不再有效

python - pyfftw 释放对数组的引用而不破坏计划

python - 使用 IDLE 时的工作目录是什么?

python - pandas 数据透视函数中索引的重复条目

python - 是否有一种简洁的方法可以仅针对当前命令显示 pandas 中的所有行?

python - Pandas 数据透视表上的行总和

tensorflow - 如何修复错误 "object has no attribute ' _output_tensor_cache'"?