如何将每个时间戳的表格提供给 LSTM 神经网络?

数据挖掘 神经网络 时间序列 lstm rnn
2022-02-25 22:32:03

我有一个像这样的时间序列数据框

         feat1  feat2  target
date id                      
0    1      12     16     192
     2      15      6      90
     3       2      9      18
1    1       0      3       0
     2       0      9       0
     3      56      9     504
2    1       5      9      45
     2       6      9      54
     3       5      8      40

我的问题是回归。

我对 LSTM 序列的了解通常row_id是日期,因此您可以构建 n 行的序列。

如您所见,在我的数据中,情况有所不同。在引用日期的每一行中,我还有 3 行代表一个产品。

我的想法是对我的问题进行排序,我的sequence意愿是 2 天:

sequence = [day0,day1],[day1,day2]

对于每一个date,我都有

date0 = [id1,id2,id3].

对于每个 id,我有:

id = [feat1,feat2].

sequence[0]它会是这样的

[
    [
        [12,16],
        [15,6],
        [2,9]
    ],[
        [0,3],
        [0.9],
        [56,9]
    ]
]

这是有效的吗?

LSTM 层会理解这一点吗?还是我必须做一些额外的改造?

1个回答

你的数据格式是

                         feature1   feature2   target
             product1    1          12         2
 timestamp   product2    2          6          3
             product3    4          3          4

针对两个假设有两种设计:

  1. 产品彼此不相关。因此,每个产品都可以单独建模。也就是说,每个时间戳都是X(t) = [feature1, feature2]或,包括目标,X(t)|y(t) = [feature1, feature2, target]我们分别为每个产品建立模型。总之,LSTM 接收 和 的两个 1 x 3 序列,t-1t输出 1 x 1 的目标t + 1表示法:

    (Xt1|yt11×3,Xt|yt1×3)yt+11×1

  2. 产品是相互关联的,意义product1可以帮助product2预测其目标。为此,我们只需要将 3 x 2 矩阵展平为 1 x 6 向量,其中值的顺序无关紧要。那是,

    X(t) = [product1_feature1, product1_feature2, ..., product3_feature2]
    

    或者

    X(t) = [product1_feature1, product2_feature1, ..., product3_feature2]
    

    我们还可以添加目标,例如

    X(t)|y(t) = [product1_feature1, product2_feature1, ..., product3_feature2, target1, ..., target3]
    

    这样,每个时间戳的维度将是 9 (6 + 3),两个时间戳的序列将是

    [
      [product1_feature1, product2_feature1, ..., product3_feature2, target1, ..., target3], # t-1
      [product1_feature1, product2_feature1, ..., product3_feature2, target1, ..., target3]  # t
    ]
    

    [target1, ..., target3]对应于处的三维目标t + 1

    总之,LSTM 接收 和 的两个 1 x 9 序列,t-1t输出 1 x 3 的目标t + 1表示法:

    (Xt1|yt11×9,Xt|yt1×9)yt+11×3