[英]Input 0 of layer sequential_2 is incompatible with the layer: expected ndim=3, found ndim=2. Full shape received: (None, 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)
There is error in last line.最后一行有错误。 I have successfully trained the data but while predicting for test data.
我已经成功地训练了数据,但同时预测了测试数据。 There is error.
有错误。
I've used the dataset from here to reproduce the issue.我已经使用此处的数据集来重现该问题。
Please expand the dimensions of x_final to solve the error as follows请扩大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)
Let us know if the issue still persists.让我们知道问题是否仍然存在。 Thanks!
谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.