LSTM 数据集准备(多变量)

发布于 2025-01-16 01:35:51 字数 1036 浏览 0 评论 0原文

我正在努力概念化为 LSTM 训练准备时间序列数据集的正确方法。我主要关心的是如何训练网络来“记住”之前的 N 个步骤。我脑子里有两种可能的方法,但我不确定哪一种是正确的。 我真的对此感到困惑,我尝试了两种方法(但是对于 1 个变量),它们似乎都提供了一些合理的结果。

1.) 数据集应采用如下张量格式

 X1=[[var1_t_1, var2_t_1, var3_t_1],
     [var1_t_2, var2_t_2, var3_t_2],
      ...] 
    X.shape = [N, 3]

 y=[ [target_t_1],
     [target_t_2],
      ...]
    y.shape = [N, 1]

在训练期间,LSTM 获取 N 个输入,每个时间步一个,并返回 N 个预测,用于计算损失和更新权重。 网络本身通过其单元状态“创建关于先前时间步值的记忆”。但是对于之前的步骤有多少它可以创建内存,有没有什么方法可以定义这个内存(如果可能的话,用 pytorch 的例子来回答)。


2.) 数据集应该已经包含之前的时间步值作为特征,因此第三维是必要的,例如。

X = [ [var1_t_1, var1_t_2,..., var1_t_10], [var2_t_1,..., var2_t_10],  [var3_t_1,..., var3_t_10],
      [var1_t_2, var1_t_3,..., var1_t_11], [var2_t_2,..., var2_t_11],  [var3_t_2,..., var3_t_11],
       ...] 
    X.shape = [N-10, 10, 3]

y = [ [target_t_11],
      [target_t_12],
       ... ]
    y.shape = [N-10, 1]

通过这种方式,我们定义了 LSTM 应尝试记住的先前步骤的数量。对于上面的例子,我们“要求”LSTM 记住至少 10 个之前的价格以便做出预测。

非常感谢任何有助于澄清这个概念的帮助。 Pytorch 代码也将非常受欢迎。

I am struggling to conceptualize the correct way to prepare a timeseries dataset for LSTM training. My main concern is how do I train the network to 'remember' N previous steps. I have two possible ways in my mind but I am not sure which one is the correct.
I am really confused with this, I have tried both approaches (for 1 variable however) and they both seem to provide some plausible results.

1.) The dataset should be in a tensor format like this

 X1=[[var1_t_1, var2_t_1, var3_t_1],
     [var1_t_2, var2_t_2, var3_t_2],
      ...] 
    X.shape = [N, 3]

 y=[ [target_t_1],
     [target_t_2],
      ...]
    y.shape = [N, 1]

During training the LSTM gets N inputs, one for each timestep, and returns back N predictions that are used to compute the loss and update weights.
The network on its own "creates memmory" about previous time step values through its cell states. But for how many previous steps can it create memmory, is there any way to define this memmory (if possible answer with pytorch example).


2.) The dataset should already contain the previous timestep values as features, so a 3rd dimension is neccessary eg.

X = [ [var1_t_1, var1_t_2,..., var1_t_10], [var2_t_1,..., var2_t_10],  [var3_t_1,..., var3_t_10],
      [var1_t_2, var1_t_3,..., var1_t_11], [var2_t_2,..., var2_t_11],  [var3_t_2,..., var3_t_11],
       ...] 
    X.shape = [N-10, 10, 3]

y = [ [target_t_11],
      [target_t_12],
       ... ]
    y.shape = [N-10, 1]

In this way we define the number of previous steps the LSTM should try to remember. For the example above we "ask" the LSTM to remember at least 10 previous prices in order to make predictions.

Any help to clarify the concept is greatly appreciated. Pytorch code would be extremely welcome as well.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文