我的时间序列数据有两个特征:
0 11/22/20 555.0 17.01/23/20 654.0 18.01/24/20 941.0 26.01/25/20 1434.0 42.01/26/20 2118.0 56.0... ... ...5/3/20 3506729.0 247470.05/4/20 3583055.0 251537.05/5/20 3662691.0 257239.05/6/20 3755341.0 263831.05/7/20 3845718.0 269567.0[107 rows x 2 columns]
我试图创建一个多变量LSTM模型来对每个列进行预测。在处理数据后,训练和测试数组的形状如下:
Legend: (samples, time steps, features)x_train: (67, 4, 2)y_train: (67, 2)x_test: (26, 4, 2)y_test: (26, 2)
以下是模型定义:
forecast_horizon = 4feature_n = 2early_stopping = EarlyStopping(patience=50, restore_best_weights=True)model = Sequential()model.add(LSTM(5, input_shape=(forecast_horizon, feature_n)))model.add(Activation("relu"))model.add(Dropout(0.1))model.add(Dense(feature_n))model.add(Activation("relu"))model.compile(loss="mean_squared_error", optimizer="adam")history = model.fit(x_train, y_train, epochs=1000, batch_size=1, verbose=0, callbacks=[early_stopping], validation_split=0.2)
预测结果全是零。 test_predictions = model.predict(x_test)
的输出是:
[[0.00839295 0.007538 ] [0. 0. ] [0.00946797 0.00663883] [0. 0. ] [0. 0. ] ... ... [0.0007435 0. ] [0.00116019 0.00032421] [0. 0. ] [0. 0. ] [0. 0. ]]
这只是简单地需要更长时间训练模型和调整超参数的问题,还是有其他因素在影响?如何实现一个正确的多变量LSTM模型?
回答:
批量大小为1意味着您的模型权重是基于单个观察值进行调整的,而不是针对一组观察值进行优化。常见的批量大小在16到32之间,但可以根据模型进行调整。
LSTM模型还需要数千个观察值,因此如果可能的话,获取更多的训练数据。
模型架构也可以有所不同,因此最好尝试多种不同的方法,看看哪种效果最好。您可以在这里找到更多信息: https://machinelearningmastery.com/how-to-develop-lstm-models-for-time-series-forecasting/