python - 用于初始状态的每日天气预报的 LSTM 网络

标签 python tensorflow machine-learning lstm

对于两个天气值的预测,我有一个数据集,其中包含分辨率为 15 分钟的一年数据。因此,每天 96 个时间点的数据和总共 365 * 96 可用。

每当我在 LSTM 网络中输入一天的数据进行训练时,我也想给出输出状态 h 的真实测量数据。

# tensor for setting output state h
init_state = tf.reshape(init_state, [1, 2])
init_state = tf.nn.rnn_cell.LSTMStateTuple(tf.constant([[0, 0]], tf.float32), init_state)

# tensor placeholder for input data with 2 inputs
train_placeholder = tf.placeholder(tf.float32, [1, 96, 2])

# hidden size equals 2, because LSTM output and output state h have 2 values
cell = tf.contrib.rnn.LSTMCell(2)
rnn_outputs_ts, state = tf.nn.dynamic_rnn(cell, train_placeholder,
                                          dtype=tf.float32, initial_state=init_state) 

培训每天循环进行:

# daily training of the weather data
for step in len(train_data):
    sess.run(train_lstm, {train_placeholder: train_data[step].reshape(1, 96, 2),
                          init_state: init_data[step].reshape(1, 2) })

如果我按照所述在每次迭代中设置输出状态 h,与默认情况下输出状态 h 始终设置为零相比,我会得到更好的结果。

由于输出状态 h 包含两个值,我为其输入真实测量值,因此 LSTM 单元的隐藏大小也限制为 2。 然而,在不手动设置输出状态 h 的情况下,我注意到如果 LSTM 单元的隐藏大小大于 2 并且输出扁平化为 2,则可能获得更好的结果。 MultiRNNCell 也是如此,由于输出状态 h,我也不使用它。

一方面我想要一个更大的 LSTM 网络,但另一方面我也想用真实的测量数据设置输出状态h

对于我的情况,您将如何处理?

最佳答案

我认为你需要另一层 - 网络通常有一个输入层、一些中间层和一个执行最终分类的输出层。在你的例子中,你可以在 LSTM 层之后添加一个带有 2 个神经元的 Dense() 层。

此外,LSTMCell 已弃用 ( https://www.tensorflow.org/api_docs/python/tf/nn/rnn_cell/LSTMCell ),并将在 TensorFlow 2.0 中删除。我建议使用 Keras( tensorflow 的包装器)来设置您的网络 - 它提供了许多便利的功能并有助于分析您的模型。请在此处查看如何设置 LSTM 模型的说明:https://adventuresinmachinelearning.com/keras-lstm-tutorial/

关于python - 用于初始状态的每日天气预报的 LSTM 网络,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55436488/

相关文章:

python - Keras 中 TimeDistributed 层的作用是什么?

machine-learning - Rasa NLU - 理解训练数据

python - Flask Flatpages 文件夹列表。构建错误

python - Twitter API 返回 401(未经授权),处理您的请求时发生错误

python - IPython (Jupyter) 笔记本中的交互式调试

python - 通过 tensorflow 对整数数据进行分类

python - 将 CSV 文件转换为 TF 记录

tensorflow - 从 tensorflow_cc 和 tensorflow_framework 生成静态库

machine-learning - 低估和高估的不同成本

python - 如何访问 Robot Framework 中的对象变量?