我正在构建深度学习lstm时间序列预测模型。我已阅读这篇文章:https://machinelearningmastery.com/how-to-develop-lstm-models-for-time-series-forecasting/
我正在使用单变量数据进行多步输出预测。
对于香草lstm和编码器模型,我尝试过以下代码:
raw_seq = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150]
# split a univariate sequence into samples
def split_sequence(sequence, n_steps_in, n_steps_out):
X, y = list(), list()
for i in range(len(sequence)):
# find the end of this pattern
end_ix = i + n_steps_in
out_end_ix = end_ix + n_steps_out
# check if we are beyond the sequence
if out_end_ix > len(sequence):
break
# gather input and output parts of the pattern
seq_x, seq_y = sequence[i:end_ix], sequence[end_ix:out_end_ix]
X.append(seq_x)
y.append(seq_y)
return array(X), array(y)
# choose a number of time steps
n_steps_in, n_steps_out = 5, 5
# split into samples
X, y = split_sequence(raw_seq, n_steps_in, n_steps_out)
print(X.shape)
print(y.shape)
# reshape from [samples, timesteps] into [samples, timesteps, features]
n_features = 1
X = X.reshape((X.shape[0], X.shape[1], n_features))
例如,对于ConvLSTM模型,我需要根据文章转换我的系列形状:
# reshape from [samples, timesteps] into [samples, timesteps, rows, columns, features]
模型需要这样的输入:
model.add(ConvLSTM2D(filters=64, kernel_size=(1,2), activation='relu', input_shape=(n_seq, 1, n_steps, n_features)))
我可以将我的单变量序列转换为香草lstm,将编码器-解码器模型转换为多输出模型:
# reshape from [samples, timesteps] into [samples, timesteps, features]
但是我无法将我的系列转换为CNN-LSTM和ConvLSTM的多输出模型:
# reshape from [samples, timesteps] into [samples, timesteps, rows, columns, features]
如何为多输出模型重塑CNN-LSTM和ConvLSTM系列?