关于 LSTM 的 3D 输入形状的快速问题
Quick question about LSTM's 3D input shape
我对 LSTM 的 3D 输入形状很困惑。
根据互联网,它说输入形状是[batchsize, timestep, feature]
。
所以如果我有 1000 timesteps * 10 features
的二维数据,我想预测它的未来。
另外,如果我想让LSTM层读取10个时间步,然后预测下一个时间步,即读取t= 1-10
,预测t=11
.
我的输入形状是 [990,10,10]
还是 [10,990,10]
?
提前致谢。
第一个是正确的。这是一个例子:
import tensorflow as tf
import numpy as np
x = np.random.rand(1000, 10)
y = np.random.rand(1000)
def multivariate_data(dataset, target,
start_index, end_index,
history_size, target_size,
step, single_step=False):
data = []
labels = []
start_index = start_index + history_size
if end_index is None:
end_index = len(dataset) - target_size
for i in range(start_index, end_index):
indices = range(i-history_size, i, step)
data.append(dataset[indices])
if single_step:
labels.append(target[i+target_size])
else:
labels.append(target[i:i+target_size])
return np.array(data), np.array(labels)
x, y = multivariate_data(dataset=x,
target=y,
start_index=0,
end_index=len(x),
history_size=10,
target_size=1,
step=1, single_step=False)
print(x.shape)
(990, 10, 10)
我对 LSTM 的 3D 输入形状很困惑。
根据互联网,它说输入形状是[batchsize, timestep, feature]
。
所以如果我有 1000 timesteps * 10 features
的二维数据,我想预测它的未来。
另外,如果我想让LSTM层读取10个时间步,然后预测下一个时间步,即读取t= 1-10
,预测t=11
.
我的输入形状是 [990,10,10]
还是 [10,990,10]
?
提前致谢。
第一个是正确的。这是一个例子:
import tensorflow as tf
import numpy as np
x = np.random.rand(1000, 10)
y = np.random.rand(1000)
def multivariate_data(dataset, target,
start_index, end_index,
history_size, target_size,
step, single_step=False):
data = []
labels = []
start_index = start_index + history_size
if end_index is None:
end_index = len(dataset) - target_size
for i in range(start_index, end_index):
indices = range(i-history_size, i, step)
data.append(dataset[indices])
if single_step:
labels.append(target[i+target_size])
else:
labels.append(target[i:i+target_size])
return np.array(data), np.array(labels)
x, y = multivariate_data(dataset=x,
target=y,
start_index=0,
end_index=len(x),
history_size=10,
target_size=1,
step=1, single_step=False)
print(x.shape)
(990, 10, 10)