Python 如何使用多个时间序列数据集训练LSTM模型?

Python 如何使用多个时间序列数据集训练LSTM模型?,python,neural-network,dataset,lstm,predict,Python,Neural Network,Dataset,Lstm,Predict,我有多个时间序列数据集,我将其格式化为下一种方式: +-----------------+------------------+ | X | Y | +-----------------+------------------+ | [0.1, 0.3, 0.4] | [0.5, 0.8, 0.9] | +-----------------+------------------+ | [0.3, 0.4, 0.5] | [0.8, 0.9

我有多个时间序列数据集,我将其格式化为下一种方式:

+-----------------+------------------+
|         X       |        Y         |
+-----------------+------------------+
| [0.1, 0.3, 0.4] | [0.5, 0.8, 0.9]  |
+-----------------+------------------+
| [0.3, 0.4, 0.5] | [0.8, 0.9, 0.91] |
+-----------------+------------------+
| [0.4, 0.5, 0.8] | [0.9, 0.91, 0.93]|
+-----------------+------------------+
|       ...       |       ...        |
+-----------------+------------------+
对于每个数据集,X包含要检查以执行预测的值向量(预测下3个值),Y包含要预测的下3个值的向量

我有多个像上面提到的那样的数据集,还有许多只包含X部分的其他数据集

我的问题是,如何适应LSTM网络,以便使用所有训练数据集的信息进行训练?我可以一方面连接它们的X值,另一方面连接它们的Y值吗

我有以下代码,但我不确定它是否得到了很好的实现

# listadx and listady are lists containing the concatenation of X and Y vectors of all the datasets, respectively.

# split into train and test sets
train_size = int(len(listadx) * 0.67)
test_size = len(listadx) - train_size

trainx, testx = listadx[0:train_size,:], listadx[train_size:len(listadx),:]
trainy, testy = listady[0:train_size,:], listady[train_size:len(listady),:]



# reshape input to be [samples, time steps, features]
trainx = numpy.reshape(trainx, (trainx.shape[0], 1, trainx.shape[1]))
testx = numpy.reshape(testx, (testx.shape[0], 1, testx.shape[1]))



# create and fit the LSTM network
model = Sequential()
model.add(LSTM(4, input_shape=(trainx.shape[1], trainx.shape[2])))
model.add(Dense(outputs))
model.compile(loss='mean_squared_error', optimizer='adam')
model.fit(trainx, trainy, epochs=100, batch_size=1, verbose=2)


# make predictions
trainPredict = model.predict(trainx)
testPredict = model.predict(testx)

trainPredict返回一个包含3个值的向量。这些是Y的值吗?

嗨,你找到这个问题的答案了吗?