python - tensorflow 预测序列

标签 python python-3.x tensorflow neural-network sequence

所以我的任务是预测序列。我在时间 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 个值。所以我像

一样运行 session
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 这样巨大的值,并且它会随着时间的推移而增加。这是我第一次预测序列,所以我想我一定错过了一些巨大的东西

最佳答案

是的,您应该规范化您的现实世界输入数据,并且它应该使用与您在训练集上使用的相同的缩放比例(相同的参数)。

原因是,现在您的模型已经过训练,可以接受特定形状和比例的输入,并且为了使其按预期执行,您必须将测试输入扩展到它。

(很抱歉将此作为答案发布,没有足够的代表进行评论)

关于python - tensorflow 预测序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53572980/

相关文章:

tensorflow - Variable_scope 的值参数

tensorflow - tf keras SparseCategoricalCrossentropy 和 sparse_categorical_accuracy 在训练期间报告错误值

python - 如何使用 SQLAlchemy 重新插入一行?

python - 将列表从文本文件转换为Python列表

python - 使用scrapy,如何获取部分xpath解析结果?

python - 使用 Python driver.current_url 语句获取 Selenium Automation 的完整 URL

python - 无法导入 pygal_maps_world.World

python-3.x - 写入 ConfigObj 时出现 Ascii 编解码器错误

python - 无法在 python 中完全下载 nltk 包。停在 omw

tensorflow 优化器 : loss sum vs mean