Keras LSTM,批量数据结构差异

时间:2017-11-20 13:44:57

标签: keras lstm

我试图了解构建用于Keras LSTM模型的顺序数据的差异和含义。我想预测电力需求,其具有自然的每日/每周需求形状,例如由温度和工作日以及一小时的时间驱动。假设我有1个月的需求和输入,即阵列形状(30天* 24小时需求,3个功能),我想根据预期的未来输入预测未来30天的需求。以下内容的含义是什么(特别是在有状态方面):

#A. feed in 1 batch of 1 hour at a time. this seems the slowest to train
model.add(LSTM(n_neurons, batch_input_shape=(1, 1, 3), stateful=True))
model.add(Dense(1))
model.compile(loss='mean_squared_error', optimizer='adam')

for i in range(n_epoch):
    model.fit(X, y, epochs=1, batch_size=1, verbose=1, shuffle=False)
    model.reset_states()


#B. feed in 720 batches of 1 hour at a time
#is this the same as A, except I need to forecast 720 hours/timesteps at a time
model.add(LSTM(n_neurons, batch_input_shape=(720, 1, 3), stateful=True))
model.add(Dense(1))
model.compile(loss='mean_squared_error', optimizer='adam')

for i in range(n_epoch):
    model.fit(X, y, epochs=1, batch_size=720, verbose=1, shuffle=False)
    model.reset_states()


#C. feed in 1 batches of 720 hour timesteps at a time
#is this the same as A, except I need to forecast 720 hours/timesteps at a time
model.add(LSTM(n_neurons, batch_input_shape=(1, 720, 3), stateful=True)) #probably dont need stateful=True here (?)
model.add(Dense(720))
model.compile(loss='mean_squared_error', optimizer='adam')

for i in range(n_epoch):
    model.fit(X, y, epochs=1, batch_size=1, verbose=1, shuffle=False)
    model.reset_states()


#D. some variation so that number_of_batches x timesteps = 720 (no overlap of sequences). 
#Timesteps most likely in multiples of 24 timesteps representing hours of the day to capture the profile shape
model.add(LSTM(n_neurons, batch_input_shape=(number_of_batches, timesteps, 3), stateful=True))
model.add(Dense(timesteps))
model.compile(loss='mean_squared_error', optimizer='adam')

for i in range(n_epoch):
    model.fit(X, y, epochs=1, batch_size=number_of_batches, verbose=1, shuffle=False)
    model.reset_states()

我已经阅读了这么多,但仍然没有完全掌握LSTM,所以任何帮助都非常感谢!我们也欢迎任何建议。

0 个答案:

没有答案