如何解决-“ ValueError:输入数组应具有与目标数组相同的样本数。找到8个输入样本和33984个目标样本。”

时间:2019-04-25 12:14:54

标签: python deep-learning lstm recurrent-neural-network

我正在尝试在数据之上拟合RNN模型,但它显示输入错误:ValueError:输入数组的样本数应与目标数组相同。找到了8个输入样本和33984个目标样本。

附加屏幕截图以供参考。

https://drive.google.com/open?id=1UjO7yQjD2_52PhTLYAYoZGfQsl1bboSW

https://drive.google.com/open?id=13k2sUvEVYoJGV7bR_dxh25C-sC8Tva0L

def RNN():
inputs = Input(name='inputs',shape=[max_len])
layer = Embedding(max_words,50,input_length=max_len)(inputs)
layer = LSTM(64)(layer)
layer = Dense(256,name='FC1')(layer)
layer = Activation('relu')(layer)
layer = Dropout(0.5)(layer)
layer = Dense(1,name='out_layer')(layer)
layer = Activation('sigmoid')(layer)
model = Model(inputs=inputs,outputs=layer)
return model


model = RNN()
model.summary()

model.compile(loss='binary_crossentropy',optimizer=RMSprop(),metrics=['accuracy'])


model.fit(sequences_matrix,y_train,batch_size=128,epochs=10,
      validation_split=0.2,callbacks=  [EarlyStopping(monitor='val_loss',min_delta=0.0001)])

我要适合运行模型的数据形状:

X_train.shape = (33984, 8)
y_train.shape = (33984,)
X_test.shape =  (14565, 8)
y_test.shape = (14565,)

0 个答案:

没有答案