Keras LSTM 问题,如何正确设置时间序列的神经网络?
Keras LSTM problem, how set up correctly a neural network for time series?
我想了解 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通常意味着Exploding Gradient
。
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 post 机器学习掌握情况。它会让您很好地了解问题是什么以及一些可能的解决方案。
虽然 LSTM 被广泛用于顺序数据表示,但在 non-deep-learning 个分类器中,XGBoost 取得了最好的结果
我想了解 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通常意味着Exploding Gradient
。
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 post 机器学习掌握情况。它会让您很好地了解问题是什么以及一些可能的解决方案。
虽然 LSTM 被广泛用于顺序数据表示,但在 non-deep-learning 个分类器中,XGBoost 取得了最好的结果