简体   繁体   English

使用 Statsmodel 和 ARIMA model 进行预测但遇到问题

[英]Using Statsmodel and the ARIMA model to forecast but running into issues

I'm trying to learn how to forecast data based on the ARIMA model that is in the library Statsmodel, but I keep running into issues.我正在尝试学习如何根据 Statsmodel 库中的 ARIMA model 预测数据,但我一直遇到问题。 Currently i'm just trying to line up my prediction next to the actual to test my model but i cant get the ARIMA model results to cooperate目前我只是试图将我的预测与实际情况对齐以测试我的 model 但我无法让 ARIMA model 结果合作

import statsmodels.api as sm

model = sm.tsa.arima.ARIMA(train, order=(4,1,2))
result = model.fit()

result.summary()

step = 10

fc, se, conf = result.forecast(step)

This all works but the last step is throwing this error这一切都有效,但最后一步是抛出此错误

 ValueError                                Traceback (most recent call last)
Input In [57], in <module>
      1 step = 10
----> 3 fc, se, conf = result.forecast(step)

ValueError: too many values to unpack (expected 3)

I've been reading the documentation for hours but I cant get anywhere with it.我已经阅读了几个小时的文档,但我无法使用它。 Any help would be greatly appreciated任何帮助将不胜感激

First of all, you try to save what a function is returning, in this case you expect three values.首先,您尝试保存 function 返回的内容,在这种情况下,您需要三个值。 One for fc , one for se and one for conf .一个用于fc ,一个用于se ,一个用于conf The problem is that the function .forecast() returns the prediction as a single object.问题是 function .forecast()将预测返回为单个 object。 You try to unpack a single object, but Python expects three.您尝试解压缩单个 object,但 Python 需要三个。 Therefore, “too many values to unpack…”.因此,“太多的值无法解压……”。 You can read the documentation of the function here to check what it returns:您可以在此处阅读 function 的文档以检查它返回的内容:

https://www.statsmodels.org/dev/generated/statsmodels.tsa.arima.model.ARIMAResults.forecast.html#statsmodels.tsa.arima.model.ARIMAResults.forecast https://www.statsmodels.org/dev/generated/statsmodels.tsa.arima.model.ARIMAResults.forecast.html#statsmodels.tsa.arima.model.ARIMAResults.forecast

在此处输入图像描述

https://www.statsmodels.org/dev/generated/statsmodels.tsa.arima.model.ARIMAResults.html https://www.statsmodels.org/dev/generated/statsmodels.tsa.arima.model.ARIMAResults.html

If you try this it will save all predictions in the object “preds” as a pandas Series:如果你尝试这个,它会将 object “preds”中的所有预测保存为 pandas 系列:

preds = result.forecast(step)

Secondly, if you want to know what a function is returning, you can simply write only the function (without … = function()) as the last line of a cell, then you can see what the function returns.其次,如果你想知道 function 返回什么,你可以只写 function (不带 ... = function())作为单元格的最后一行,然后你可以看到 ZC1C425268E68384F145A 返回什么。 Or you can check the documentation.或者您可以查看文档。 You can print the object's type with print(type(result)) , it will return “statsmodels.tsa.arima.model.ARIMAResultsWrapper” and if you google you get to the documentation above.你可以用print(type(result))打印对象的类型,它会返回“statsmodels.tsa.arima.model.ARIMAResultsWrapper”,如果你用谷歌搜索,你会得到上面的文档。

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

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