繁体   English   中英

如何重塑keras LSTM的输入?

[英]How to reshape input for keras LSTM?

我有一个约5000行和4列(温度,压力,速度,成本)的numpy数组。 因此,它的形状为(5000,4)。 每行都是按固定间隔进行的观察,这是我第一次进行时间序列预测,并且卡在输入形状上。 我正在尝试从最后一个数据点开始预测1个时间步长的值。 如何在keras中将其重塑为LSTM模型的3D形式?

如果编写一个小的示例程序,它也将更加有用。 似乎没有任何示例/教程中的输入具有多个功能(也没有NLP)。

您应该问自己的第一个问题是:

  • 输入要素对要预测的值的相关信息进行编码的时间范围是什么?

让我们把这个时间表prediction_context

您现在可以创建数据集:

import numpy as np

recording_length = 5000
n_features = 4
prediction_context = 10  # Change here
# The data you already have
X_data = np.random.random((recording_length, n_features))
to_predict = np.random.random((5000,1))
# Make lists of training examples
X_in = []
Y_out = []
# Append examples to the lists (input and expected output)
for i in range(recording_length - prediction_context):
    X_in.append(X_data[i:i+prediction_context,:])
    Y_out.append(to_predict[i+prediction_context])

# Convert them to numpy array
X_train = np.array(X_in)
Y_train = np.array(Y_out)

在末尾 :
X_train.shape = (recording_length - prediction_context, prediction_context, n_features)
因此,您将需要在预测上下文的长度和训练网络的示例数量之间进行权衡。

暂无
暂无

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

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