我正在尝试建立一个多元时间序列预测模型。我按照以下教程进行温度预测。http://nbviewer.jupyter.org/github/addfor/tutorials/blob/master/machine_learning/ml16v04_forecasting_with_LSTM.ipynb
我想通过使用以下代码将他的模型扩展到多层 LSTM 模型:
cell = tf.contrib.rnn.LSTMCell(hidden, state_is_tuple=True)
cell = tf.contrib.rnn.MultiRNNCell([cell] * num_layers,state_is_tuple=True)
output, _ = tf.nn.dynamic_rnn(cell=cell, inputs=features, dtype=tf.float32)
但我有一个错误说:
ValueError:尺寸必须相等,但对于 'rnn/while/rnn/multi_rnn_cell/cell_0/cell_0/lstm_cell/MatMul_1'(操作:'MatMul'),尺寸必须是 256 和 142,输入形状:[?,256], [142,512] .
当我尝试这个时:
cell = []
for i in range(num_layers):
cell.append(tf.contrib.rnn.LSTMCell(hidden, state_is_tuple=True))
cell = tf.contrib.rnn.MultiRNNCell(cell,state_is_tuple=True)
output, _ = tf.nn.dynamic_rnn(cell=cell, inputs=features, dtype=tf.float32)
我没有这样的错误,但预测真的很糟糕。
我定义 hidden=128
.
features = tf.reshape(features, [-1, n_steps, n_input])
(?,1,14)
具有单层外壳的形状。
我的数据看起来像这样x.shape=(594,14), y.shape=(591,1)
我很困惑如何在张量流中堆叠 LSTM 单元。我的张量流版本是 0.14。