首页 > 解决方案 > 与自己的预测一起使用时,时间序列预测的预测很糟糕

问题描述

抱歉,这里是初学者的问题,但我现在完全迷路了。我遵循了TensorFlow 提供的时间序列预测教程,并让它很好地处理了我的数据。我想将它用于机器人的里程计。因此,该模型应该预测机器人在 t+1 时的位置和速度。

现在让我们看一下简单的“密集模型”:

dense = tf.keras.Sequential([
tf.keras.layers.Dense(units=64, activation='relu'),
tf.keras.layers.Dense(units=64, activation='relu'),
tf.keras.layers.Dense(units=4)])

我适合这样:

MAX_EPOCHS = 1000
def compile_and_fit(model, window, patience=20):
  early_stopping = tf.keras.callbacks.EarlyStopping(monitor='val_loss',
                                                    patience=patience,
                                                    mode='min')
  #tf.losses.MeanAbsoluteError()
  model.compile(loss=tf.losses.MeanSquaredError(),
                optimizer=tf.optimizers.Adam(),
                metrics=[coeff_determination, 'mae'])

  history = model.fit(window.train, epochs=MAX_EPOCHS,
                      validation_data=window.val,
                      callbacks=[early_stopping])
  return history

history = compile_and_fit(dense, wide_window, patience=3)
IPython.display.clear_output()
val_performance['Dense'] = dense.evaluate(wide_window.val)
performance['Dense'] = dense.evaluate(wide_window.test, verbose=0)

经过训练,我得到了很好的结果:

损失:0.0151 - 决定系数:0.9926 - mae:0.0936

未知测试数据的 X 和 Y 预测图:

在此处输入图像描述

现在我们来到我怀疑我的错误的部分。因为机器人无法测量它的当前位置和速度,它只获得第一个位置(它开始的位置),然后我用它自己对之前时间步长的预测来输入模型,并尝试预测下一个位置和速度。我想在训练数据本身上对此进行测试。

我的代码是:

predict= [0 for a in range(len(train_df)-1)]
predict[0] = dense.predict(train_df.iloc[[0]])
for a in range(len(train_df)-1):
  if a > 0:
    sample = train_df.iloc[[a]].copy()
    sample['speed_x'] = predict[a-1][0][0]
    sample['speed_y'] = predict[a-1][0][1]
    sample['X'] = predict[a-1][0][2]
    sample['Y'] = predict[a-1][0][3]
    predict[a]= dense.predict(sample)

如果我现在绘制我的结果,你会发现它是可怕的。当然,我希望它运行的时间越长,它就会变得越不精确,但它在一开始就完全关闭了。

训练集的 X 位置:

在此处输入图像描述

请,如果您对我如何改善正在发生的事情有任何建议,请告诉我,我迷路了。

标签: tensorflowkerastime-seriesregressiontensorflow2.0

解决方案


推荐阅读