简体   繁体   English

Keras LSTM网络预测更新

[英]Keras LSTM Network Prediction update

I have been following along with various tutorials from https://machinelearningmastery.com/blog/ using Keras with great success. 我一直在跟随https://machinelearningmastery.com/blog/中使用Keras编写的各种教程取得巨大成功。 Recently I have been experimenting with deep LSTM networks for times series sequence prediction problems. 最近,我一直在用深度LSTM网络进行实验,以解决时间序列预测问题。 The network is training well and producing an acceptable amount of error. 网络训练得很好,并产生可接受的错误量。 In real world application, there is no data point to sub in to produce the next prediction like you can do with the test dataset, so I want to be able to sub in the last prediction. 在现实世界的应用程序中,没有数据点可以像生成测试数据集一样进行细分以生成下一个预测,因此我希望能够对最后的预测进行细分。

For the real world application of this network, I need to be able to use my initial data to make prediction t+1, add the result to the input data, predict t+2, add the result to the input data, etc. until I am able to predict a particular amount of time steps into the future. 对于该网络的实际应用,我需要能够使用初始数据进行预测t + 1,将结果添加到输入数据,预测t + 2,将结果添加到输入数据,等等,直到我能够预测未来的特定时间步长。

I initially started with: 我最初以:

start = len(testX)-15
pattern = testX[start]

for i in range(200):
    x = numpy.reshape(testX, (testX.shape[0], testX.shape[1], 1))
    prediction = model.predict(testX[i:i+15], batch_size=batch_size)
    pattern.append(prediction)

print "\nDone."

This method runs into issues with the pattern.append(prediction) line producing the error: AttributeError: 'numpy.ndarray' object has no attribute 'append'. 此方法会遇到pattern.append(prediction)行产生错误的问题:AttributeError:'numpy.ndarray'对象没有属性'append'。 This is not updating the inputs with the last prediction, thus breaking the continuous cycle. 这不会用最后的预测更新输入,从而破坏了连续周期。

I have not been able to find any ANN models that utilize this type of feed method to be able to predict out in time based on latest data. 我还没有找到任何利用这种类型的feed方法的ANN模型能够根据最新数据及时进行预测。

Use numpy.append() to append values to the end of an array. 使用numpy.append()将值附加到数组的末尾。

For your code, it should be pattern = numpy.append(pattern,prediction) . 对于您的代码,它应该是pattern = numpy.append(pattern,prediction)

Good luck. 祝好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM