tensorflow - 与自己的预测一起使用时,时间序列预测的预测很糟糕
问题描述
抱歉,这里是初学者的问题,但我现在完全迷路了。我遵循了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 位置:
请,如果您对我如何改善正在发生的事情有任何建议,请告诉我,我迷路了。
解决方案
推荐阅读
- google-app-engine - PhpPathError: 对于 php72,必须在 Google App Engine 项目中指定 --php_executable_path
- c# - 在 csproj 中,我可以有条件地包含基于运行时标识符的文件吗?
- python - 通过比较不同数据框中的其他两列来连接一列
- redis - 较低的redis哨兵可以与较高的redis实例对话吗?
- java - 如何打印没有方括号的列表?
- python - Python列表理解语法将输出表达式显示为“可选”?
- elasticsearch - Elasticsearch 混合数字和字符串 multi_match 查询失败
- java - 单链表 - 获取和添加方法
- php - 为什么不在 php 中使用 Google_Oauth2Service 接收电子邮件地址?
- python - 程序通过连接两个字符串都不包含的字符从两个给定的字符串创建一个字符串