简体   繁体   English

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

[英]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.

相关问题 PyTorch:简单的前馈神经网络在没有 retain_graph=True 的情况下无法运行 - PyTorch: Simple feedforward neural network not running without retain_graph=True 无法修复 ValueError:在 Keras 中构建简单的神经网络 model - Can't fix ValueError: Building a simple neural network model in Keras 为什么前馈神经网络中的简单二元分类会失败? - Why is a simple Binary classification failing in a feedforward neural network? 为什么我的简单前馈神经网络发散(pytorch)? - why is my simple feedforward neural network diverging (pytorch)? 使用TensorFlow的简单前馈神经网络将无法学习 - Simple Feedforward Neural Network with TensorFlow won't learn Keras,简单神经网络错误代码(model.predict) - Keras, simple neural network Error Code (model.predict) Keras:具有简单数据的简单神经网络无法正常工作 - Keras: simple neural network with simple data not working 使用Keras和Librosa运行Python神经网络进行音乐识别时出错 - Error in Running Python Neural Network for Music Recognition with Keras and Librosa 运行 Keras 神经网络时出现结果形状问题 - Problem with result shape when running Keras Neural Network ValueError 在 Keras 中构建具有 2 个输出的神经网络 - ValueError building a neural network with 2 outputs in Keras
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM