[英]What is the correct input shape of multivariate time series for LSTM in keras?
I can not understand what is the right way to input multivariate time series to an LSTM.我不明白将多元时间序列输入到 LSTM 的正确方法是什么。
Let's say i have a dataset with 3 features that vary over time like this:假设我有一个具有 3 个随时间变化的特征的数据集,如下所示:
feat1![]() |
feat2![]() |
feat3![]() |
---|---|---|
1 ![]() |
2 ![]() |
3 ![]() |
4 ![]() |
5 ![]() |
6 ![]() |
7 ![]() |
8 ![]() |
9 ![]() |
should I present this to my LSTM as it is using numpy.vstack() ?我应该将它呈现给我的 LSTM,因为它正在使用numpy.vstack()吗? like this:
像这样:
[[1,2,3],
[4,5,6],
[7,8,9]]
Or should i stack it by columns so that each row is the feature sequence using numpy.column_stack() ?或者我应该按列堆叠它,以便每一行都是使用numpy.column_stack()的特征序列? like this:
像这样:
[[1,4,7],
[2,5,8],
[3,6,9]]
From the keras LSTM API :来自 keras LSTM API :
inputs: A 3D tensor with shape [batch, timesteps, feature].
输入:形状为 [batch, timesteps, feature] 的 3D 张量。
Therefore, the features (multiple variables) should be represented by the last dimension, which means your 1st suggestion is the right one.因此,特征(多个变量)应由最后一个维度表示,这意味着您的第一个建议是正确的。
Obs: The batch
dimension should be only of concern if you aren't using the fit
function for a whole dataset. Obs:只有在您没有对整个数据集使用
fit
function 时,才应该关注batch
维度。 Otherwise, if you are presenting a single example (for instance, in inference), you should also apply the numpy.expand_dims
function in the 0th axis.否则,如果您要呈现单个示例(例如,在推理中),您还应该在第 0 轴上应用
numpy.expand_dims
function。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.