我已经开发了用于时间序列预测的编解码器模型,但是我不确定如何实现预测过程。
下面是代码示例。
X = tf.placeholder(tf.float32,shape=(None,x_seq_len,n_features),name="X")
y = tf.placeholder(tf.float32,shape=(None,y_seq_len,n_features),name="y")
cells = tf.nn.rnn_cell.MultiRNNCell([ tf.nn.rnn_cell.LSTMCell(n_neurons) for _ in range(n_layers) ])
init_state = cells.zero_state(batch_size, tf.float32)
enc_outputs, enc_states = tf.nn.dynamic_rnn(cells, X, initial_state=init_state)
dec_outputs,dec_states = tf.nn.dynamic_rnn(cells, y, initial_state=enc_states)
loss = tf.reduce_mean(tf.square(dec_outputs - y))
train_op = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(loss)
#Training process
...
#Prediction process
dec_outputs,dec_states = tf.nn.dynamic_rnn(cells, y, initial_state=enc_states)
dec_states_prev = np.zeros((batch_size,seq_len,n_inputs))
for x_test,y_test in test_set:
dec_out,dec_states = sess.run([dec_o,dec_s],feed={y:x_test,dec_state:dec_states_prev})
dec_states_prev = dec_states
pred_arr.append(dec_out)
#compare the predictions with targets(y_test).
谢谢。