Python 为LSTM生成输入和输出

Python 为LSTM生成输入和输出,python,jupyter-notebook,lstm,Python,Jupyter Notebook,Lstm,我想使用LSTM进行时间序列预测,我已经有了我的训练、测试和验证数据,形状为:训练:(13,6000,6)-测试:(7,6000,6)-验证:(3,6000,6)。>>13天,6000个时间步,6列 n_input = 14 n_out = 7 # convert history into inputs and outputs def to_supervised(data, n_input, n_out): # flatten data data = data.reshape((

我想使用LSTM进行时间序列预测,我已经有了我的训练、测试和验证数据,形状为:训练:(13,6000,6)-测试:(7,6000,6)-验证:(3,6000,6)。>>13天,6000个时间步,6列
n_input = 14
n_out = 7
# convert history into inputs and outputs
def to_supervised(data, n_input, n_out):
    # flatten data
    data = data.reshape((data.shape[0]*data.shape[1], data.shape[2]))
    X, y = list(), list()
    in_start = 0
    # step over the entire history one time step at a time
    for _ in range(len(data)):
        # define the end of the input sequence
        in_end = in_start + n_input
        out_end = in_end + n_out
        # ensure we have enough data for this instance
        if out_end < len(data):
            X.append(data[in_start:in_end, :])
            y.append(data[in_end:out_end, 0])
        # move along one time step
        in_start += 1
    return np.array(X), np.array(y)
def process(data, n_input, n_out):
    x = []
    y = []
    for i in range(data.shape[0]):
        x_temp, y_temp = to_supervised(data[i:(i+1)], n_input, n_out)
        x.append(x_temp)
        y.append(y_temp)
    x = np.array(x)
    x = x.reshape(x.shape[0]*x.shape[1], x.shape[2], x.shape[3])
    y = np.array(y)
    y = y.reshape(y.shape[0]*y.shape[1]* y.shape[2],)
    return x, y