python - Keras LSTM 问题,如何正确设置时间序列的神经网络?

标签 python keras time-series lstm recurrent-neural-network

我试图了解 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/

相关文章:

python - 手工 C++ 名称修改

python - 检测图中的高振幅

Python:处理临时文件夹中的_MEIPASS文件夹

python-3.x - 使用 statsmodel 中的 arma_order_select_ic 选择 ARMA 模型订单

python - 如何将 "show details"按钮添加到 tkinter 消息框?

keras - 将 model.fit_generator 转换为 model.fit

python - 如何解释 keras "predict_generator "输出?

python - Call 函数何时以及如何在 Keras 的模型子类化中工作?

r - Arima 和 lm 在 R 中没有给出相同的系数

r - 使用 data.table 汇总每月序列(统计特定事件)