我有一个训练批次600个连续点(x(t),y(t)),x(t)是25维向量,y(t)是我的目标(1暗).我想训练一个LSTM来预测系列如何继续给出一些额外的x(t)[t> 600].我尝试了以下模型:
model = Sequential()
model.add(LSTM(128, input_shape = (600,25), batch_size = 1, activation= 'tanh', return_sequences = True))
model.add(Dense(1, activation='linear'))
model.compile(loss='mean_squared_error', optimizer='adam')
model.fit(trainX, trainY, epochs=20 ,verbose=2) prediction
prediction = model.predict(testX, batch_size = 1)
Run Code Online (Sandbox Code Playgroud)
拟合工作正常,但我在预测步骤中不断收到以下错误:
Error when checking : expected lstm_46_input to have shape (1, 600, 25) but got array with shape (1, 10, 25)
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
这是我的形状:
trainX.shape = (1,600,25)
trainY.shape = (1,600,1)
testX.shape = (1,10,25)
Run Code Online (Sandbox Code Playgroud)
根据Keras文档,LSTM(或任何RNN)层(batch_size, timesteps, input_dim)的输入应该是您输入形状的形状
trainX.shape =(1,600,25)
因此,对于训练而言,您只传递600个时间步长的一个数据和每个时间步长25个特征.但我觉得你实际上有600个训练数据,每个训练数据有25个时间步长,每个时间步长有1个特征.我想你的输入形状(trainX)应该是600 x 25 x 1.列车目标(trainY)应该是 600 x 1如果我的假设是正确的那么你的测试数据应该是合适的10 x 25 x 1.第一个LSTM层应写为
model.add(LSTM(128, input_shape = (25,1), batch_size = 1, activation= 'tanh', return_sequences = False))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3286 次 |
| 最近记录: |