为什么我的多变量LSTM一直预测零?

问题描述 投票:0回答:1

我的时间序列数据有2个特征。

                 0         1
1/22/20      555.0      17.0
1/23/20      654.0      18.0
1/24/20      941.0      26.0
1/25/20     1434.0      42.0
1/26/20     2118.0      56.0
...            ...       ...
5/3/20   3506729.0  247470.0
5/4/20   3583055.0  251537.0
5/5/20   3662691.0  257239.0
5/6/20   3755341.0  263831.0
5/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 = 4
feature_n = 2
early_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.        ]]

从训练损失来看,模型的学习效果似乎不太好。enter image description here

这是一个简单的模型训练时间较长,调整其超参数的问题,还是有其他的原因会影响这个问题?如何实现一个正确的多变量LSTM?

python tensorflow machine-learning keras lstm
1个回答
1
投票

批量大小为1意味着您的模型权重正在基于1个观测值进行调整,而不是针对少数观测值进行优化。常见的批次大小在16到32之间,但可以根据模型的情况进行调整。

LSTM模型也需要数千个观测值,所以如果可能的话,要获得更多的训练数据。

架构也会有所不同,所以最好尝试一些不同的方法,看看什么是最有效的。你可以在这里找到更多信息。https:/machinelearningmastery.com如何开发lstm模型进行时间序列预测。

© www.soinside.com 2019 - 2024. All rights reserved.