简体   繁体   English

Keras LSTM 训练和验证数据中的时间步长顺序

[英]Order of timesteps in Keras LSTM training and validation data

When using Keras recurrent layers, such as an LSTM layer, your input data is supposed to be in the 3-dimensional form of [samples,timesteps,features].当使用 Keras 循环层(例如 LSTM 层)时,您的输入数据应该是 [样本、时间步长、特征] 的 3 维形式。 The problem here is that I can't get any reliable information on the order of the timesteps dimension in the input matrices.这里的问题是我无法获得有关输入矩阵中时间步长维度顺序的任何可靠信息。 As a concrete example, would the first element/row, for a given sample, be the most recent known row of features or the most distant row of features?作为一个具体的例子,对于给定的样本,第一个元素/行是最近的已知特征行还是最远的特征行?

I would suspect that the order would matter since the model is recurrent, and indeed when flipping the order of the timesteps column you end of getting different training results (when you have appropriately set seeds which would yield reproducibility.)我怀疑顺序会很重要,因为模型是循环的,并且确实在翻转 timesteps 列的顺序时,您最终会得到不同的训练结果(当您适当地设置会产生可重复性的种子时。)

If someone would force me to guess, I would assume that the first row (for one sample) would be the most distant features in the sequence, but is there a definite answer here?如果有人强迫我猜测,我会假设第一行(对于一个样本)将是序列中最远的特征,但这里有明确的答案吗?

It's easier to picture 3D arrays in Keras as an array of 2D arrays.将 Keras 中的 3D 数组描绘为 2D 数组的数组更容易。 The first dimension is the samples.第一个维度是样本。

Your array must be of the shape [samples, timesteps, features] .您的数组的形状必须为[samples, timesteps, features] Picture this as an array of length samples, where each element is itself a 2D array of shape [timesteps, features] .把它想象成一个长度样本数组,其中每个元素本身就是一个形状为[timesteps, features]的二维数组。 So, to be clear, each element in this array is a 2D array with timesteps number of rows and features number of columns.因此,需要明确的是,该数组中的每个元素都是一个二维数组,具有timesteps的行数和features的列数。

The first row (index 0) in each of these 2D arrays is the first timestep, ie, oldest as you say.这些二维数组中的每一个中的第一行(索引 0)是第一个时间步长,即如您所说的最旧。 The last row in each of these 2D arrays is the last timestep, ie, most recent.这些二维数组中的每一个中的最后一行是最后一个时间步,即最近的。 For each timestep row, you have features along the columns.对于每个timestep行,您都有沿列的特征。

It helps to unroll the array as done above to picture it easily and with more clarity.它有助于按上述方式展开阵列,以便轻松、更清晰地描绘它。

Hope this helped.希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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