简体   繁体   English

keras 中 LSTM 的多元时间序列的正确输入形状是什么?

[英]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专长1 feat2壮举2 feat3壮举3
1 1 2 2 3 3
4 4 5 5 6 6
7 7 8 8 9 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM