我试图了解 lstm 如何使用 Keras 预测时间序列。 这是我的例子。 我使用加速度计并且有 128.000 个时间序列。我想采取: n_steps_in = 10.000 n_steps_out = 5.000 进行预测。
我将大序列分为 114 个样本、10.000 个时间序列和 1 个特征 X = [114, 10.000, 1] y = [114, 5.000]
我试图了解要使用多少个隐藏层,多少个神经元。 作为一个回归,我想使用
activation=ReLU,
loss = mse
optimizer=adam
问题是很多时候我的损失等于 nan,但我不明白为什么。
这是我的代码示例
model1 = Sequential()
model1.add(LSTM(200, activation='relu', input_shape=(n_steps_in, n_features)))
model1.add(Dense(n_steps_out))
model1.compile(optimizer='adam', loss='mse')
希望有人能给我一些建议,谢谢!!
最佳答案
首先,尝试通过向输出层添加激活函数来修复它:
model.add(Dense(n_steps_out, activation='linear'))
但是
训练时获得 nan 通常意味着梯度爆炸
。
In deep networks or recurrent neural networks, error gradients can accumulate during an update and result in very large gradients. These in turn result in large updates to the network weights, and in turn, an unstable network. At an extreme, the values of weights can become so large as to overflow and result in NaN values.
检查this掌握机器学习的帖子。它可以让您很好地了解问题所在以及一些潜在的解决方案。
关于python - Keras LSTM 问题,如何正确设置时间序列的神经网络?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56275128/