LSTM层期望输入的形状为
(batch_size, timesteps, input_dim)。在keras中,您需要将
(timesteps,input_dim)作为input_shape参数。但是您正在设置input_shape(9,)。此形状不包括时间步长维度。通过为时间维度的input_shape添加额外的维度可以解决该问题。例如,将额外的维度添加为值1可能是简单的解决方案。为此,您必须重塑输入数据集(X训练)和Y形状。但这可能会带来问题,因为时间分辨率为1,并且您要按一个顺序输入长度。使用长度为1的序列作为输入,使用LSTM似乎不是正确的选择。
x_train = x_train.reshape(-1, 1, 9)x_test = x_test.reshape(-1, 1, 9)y_train = y_train.reshape(-1, 1, 5)y_test = y_test.reshape(-1, 1, 5)model = Sequential()model.add(LSTM(100, input_shape=(1, 9), return_sequences=True))model.add(LSTM(5, input_shape=(1, 9), return_sequences=True))model.compile(loss="mean_absolute_error", optimizer="adam", metrics= ['accuracy'])history = model.fit(X_train,y_train,epochs=100, validation_data=(X_test,y_test))



