2017-08-29 100 views
1

我:LSTM-Keras是否考虑了时间序列之间的依赖关系?

  • 多个时间序列作为输出输入
  • 预测时间序列点

如何能够确保该模型通过使用输入的所有时间序列之间的相关预测数据?

编辑1
我的当前模型:

model = Sequential() 
model.add(keras.layers.LSTM(hidden_nodes, input_dim=num_features, input_length=window, consume_less="mem")) 
model.add(keras.layers.Dense(num_features, activation='sigmoid')) 
optimizer = keras.optimizers.SGD(lr=learning_rate, decay=1e-6, momentum=0.9, nesterov=True) 
+0

你可以添加你当前的模型? – DJK

回答

1

通过keras默认LSTM层(以及任何其他类型的经常性层的)是无状态的,因此,状态复位每次一个新的输入被馈入网络。你的代码使用这个默认版本。如果需要,可以通过在LSTM层中指定stateful=True来使其成为有状态,然后状态不会被重置。您可以阅读关于相关语法here的更多信息,并且this blog post提供有关有状态模式的更多信息。

下面是相应的语法的一个例子,从here采取:

trainX = numpy.reshape(trainX, (trainX.shape[0], trainX.shape[1], 1)) 
testX = numpy.reshape(testX, (testX.shape[0], testX.shape[1], 1)) 
# create and fit the LSTM network 
batch_size = 1 
model = Sequential() 
model.add(LSTM(4, batch_input_shape=(batch_size, look_back, 1), stateful=True)) 
model.add(Dense(1)) 
model.compile(loss='mean_squared_error', optimizer='adam') 
for i in range(100): 
    model.fit(trainX, trainY, epochs=1, batch_size=batch_size, verbose=2, shuffle=False) 
    model.reset_states() 
# make predictions 
trainPredict = model.predict(trainX, batch_size=batch_size) 
model.reset_states() 
testPredict = model.predict(testX, batch_size=batch_size) 
+0

如果我使用有状态,那么如何管理批量大小? – Ghemon

+0

@Ghemon看到我更新的答案。 –

+0

在这种情况下,batch_size等于1,但我认为不适合我的问题。你怎么看? – Ghemon