我阅读了有关LSTM的这篇文章:
https://machinelearningmastery.com/how-to-develop-lstm-models-for-time-series-forecasting/
第一个基本示例是关于“香草LSTM”的:预测下一个时间序列
其中输入= [10, 20, 30, 40, 50, 60, 70, 80, 90]
在本文中,作者将输入(序列)分成矩阵:
X, y
10, 20, 30 40
20, 30, 40 50
30, 40, 50 60
...
我不明白为什么输入需要重塑:
reshape from [samples, timesteps] into [samples, timesteps, features]
1。我们为什么需要这个?
此外,如果我的输入是喜欢的(基本示例+ ID列:
ID X, y
1 10, 20, 30 40
1 20, 30, 40 50
2 30, 40, 50 60
2 40, 50, 60, 70
...
2。我们如何重塑它?我们将成为什么新维度?
不确定ID的来源,但是对于Keras中的LSTM网络,您需要输入3维数据。
最初,您将二维矩阵作为输入,其中每一行都是一个时间戳,因此[samples, timesteps]
。
但是由于预期输入为3维,因此将其重塑为[samples, timesteps, 1]
。此处1
表示数据中具有的功能或变量的数量。由于这是一个单变量时间序列(您只有1个变量的序列),因此n_features为1。
这可以通过np_array.reshape(np_array_shape[0], np_array.shape[1], 1)
轻松完成