所以我的任务是预测序列。我在时间 t 有 x,y,z 值,它们是浮点型。我必须预测在时间 (t + 1) 具有值 x,y,z 的序列。
TIME_STEP = 10
N_FEATURES = N_CLASSES = 3
LEARNING_RATE = 0.01
EPOCHS = 50
BATCH_SIZE = 10
x = tf.placeholder(tf.float32, shape = [None, N_FEATURES], name = 'name')
y = tf.placeholder(tf.float32, shape = [N_CLASSES], name = 'labels')
然后我有我的 lstm 模型,它看起来像:
x = tf.transpose(x, [1, 0])
x = tf.reshape(x, [-1, num_features])
hidden = tf.nn.relu(tf.matmul(x, self.h_W) + self.h_biases)
hidden = tf.split(hidden, self.time_step)
lstm_layers = [tf.contrib.rnn.BasicLSTMCell(self.hidden_units, forget_bias=1.0) for _ in range(2)]
lstm_layers = tf.contrib.rnn.MultiRNNCell(lstm_layers)
outputs, _ = tf.contrib.rnn.static_rnn(lstm_layers, hidden, dtype = tf.float32)
lstm_output = outputs[-1]
最后我定义了损失函数和优化器
loss = tf.reduce_mean(tf.square(y - y_pred))
opt = tf.train.AdamOptimizer(learning_rate = LEARNING_RATE).minimize(loss)
现在我想用前 10 个值来预测第 11 个值。所以我运行会话
for time in range(0, len(X)):
sess.run(opt, feed_dict = {x : X[time: time + TIME_STEP ],
y : Y[time + TIME_STEP + 1]})
但是当我检查这个函数的损失时,它有很大的价值,比如 99400290.0,它会随着时间的推移而增加。这是我第一次预测序列,所以我想我一定遗漏了一些重要的东西
莫回无
相关分类