【问题标题】:Forecasting new value using LSTM python使用 LSTM python 预测新值
【发布时间】:2018-11-29 01:31:18
【问题描述】:

我已经建立了一个可以预测未来价格的 LSTM 模型。我已经用已经存在的地面真值进行了测试,以了解模型的准确性。现在我想使用相同的模型来预测我们不知道基本事实的值。我执行以下代码来对 449 条新记录进行预测。

Test = Stock_AREIT[len(Stock_AREIT)-60:]
Test=Test['1. open']
inputs=Test.values
inputs = inputs.reshape(-1,1)

# Scale inputs but not actual test values
inputs = sc.transform(inputs)
for test in range(0,449):
inputs=np.append(inputs,predicted_stock_price)
inputs=inputs.reshape(-1,1)
print(inputs.shape)
X_test=[]
for i in range(60, 61):
    X_test.append(inputs[test:i+test,0])
# make list to array
X_test = np.array(X_test)
X_test = np.reshape(X_test,(X_test.shape[0], X_test.shape[1],1))
predicted_stock_price = regressor.predict(X_test)
inputs=np.delete(inputs,len(inputs)-1,axis=0)
inputs=np.append(inputs,predicted_stock_price)
inputs=inputs.reshape(-1,1)
print("currently running {}".format(test))

模型的实际预测应该如下图

但是对于上面的代码,我得到了下图

你能告诉我哪里出错了吗?如果您需要更多详细信息,请告诉我

【问题讨论】:

  • 我想我想通了。实际的图表(图 1)实际上使用了正确的基本事实,这使得预测更加准确。而我的结果实际上在其时间步中使用了预测值。我认为我的理解是正确的。但也请告诉我您的意见

标签: python pandas keras lstm


【解决方案1】:

您还没有转换回这些值。预测值基于变换数据。

这应该可行:

predicted_stock_price_orig = inputs.inverse_transform(predicted_stock_price)

更多帮助请参考这个问题:scikit-learn: how to scale back the 'y' predicted result

【讨论】:

    猜你喜欢
    • 2021-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-24
    • 2020-08-25
    • 1970-01-01
    相关资源
    最近更新 更多