层sequencial_2的输入0与层不兼容:预期ndim=3,实际ndim=2.收到完整形状:(无,1)


model = Sequential()
model.add(LSTM(100, input_shape = [X_sequence.shape[1], X_sequence.shape[2]]))
model.add(Dropout(0.5))
model.add(Dense(1, activation="sigmoid"))
model.compile(loss="binary_crossentropy"
, metrics=[binary_accuracy]
, optimizer="adam")
model.summary()
training_size = int(len(X_sequence) * 0.7)
X_train, y_train = X_sequence[:training_size], y[:training_size]
X_test, y_test = X_sequence[training_size:], y[training_size:]
model.fit(X_train, y_train, batch_size=64, epochs=10)
y_test_pred = model.predict(X_test)
def create_dataset(dataset, time_step=1):
dataX = []
for i in range(len(dataset)-time_step-1):
a = dataset[i:(i+time_step), 0]
dataX.append(a)
return np.array(dataX)
x_final=create_dataset(test.loc[:, "sensor_00":"sensor_12"].values)
y_final=model.predict(x_final)

最后一行有错误。我已经成功地训练了数据,但同时预测了测试数据。出现错误。

我使用了这里的数据集来重现这个问题。

请扩展x_final的尺寸以解决错误,如下所示

x_final=create_dataset(test.loc[:, "sensor_00":"sensor_12"].values)

#Expand dimensions    
x_final=tf.expand_dims(x_final,axis=1)
y_final=model.predict(x_final)

如果问题仍然存在,请告诉我们。谢谢

相关内容

  • 没有找到相关文章

最新更新