[英]Running into key error when building simple feedforward neural network in Keras
Here is a snapshot of my dataset, including its shape: 这是我的数据集的快照,包括其形状:
Now, here is the code I am using to build the NN: 现在,这是我用来构建NN的代码:
# 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)
When I do this, I get the following error: 当我这样做时,出现以下错误:
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'
I haven't been able to find a solution to this. 我还没有找到解决方案。 Any help would be much appreciated. 任何帮助将非常感激。
I believe that the input is not a numpy array as described in this github issue on the keras page 我相信输入不是keras页上的github问题中所述的numpy数组
Try fitting the model using this: 尝试使用以下方法拟合模型:
model.fit(np.array(X_train), np.array(Y_train), epochs=50, batch_size=128,
verbose=1)
Which will cast the arrays as numpy arrays when fitting the data. 拟合数据时,会将数组转换为numpy数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.