预测statsmodel参数错误

时间:2016-04-19 11:53:57

标签: python statsmodels

我正在尝试预测数组的超出样本值。 Python代码:

import pandas as pd
import numpy as np
from statsmodels.tsa.arima_model import ARIMA

    dates = pd.date_range('2012-07-09','2012-07-30')
    series = [43.,32.,63.,98.,65.,78.,23.,35.,78.,56.,45.,45.,56.,6.,63.,45.,64.,34.,76.,34.,14.,54.]
    res = pd.Series(series, index=dates)
    r = ARIMA(res,(1,2,0))
    pred = r.predict(start='2012-07-31', end='2012-08-31')

我收到了这个错误。我看到我已经给出了两个参数但编译器返回我已经给出了3.

Traceback (most recent call last):
  File "XXXXXXXXX/testfile.py", line 12, in <module>
    pred = r.predict(start='2012-07-31', end='2012-08-31')
TypeError: predict() takes at least 2 arguments (3 given)

请帮忙

1 个答案:

答案 0 :(得分:5)

ARIMA.predict的来电签名是

predict(self, params, start=None, end=None, exog=None, dynamic=False)

因此,当您致电r.predict(start='2012-07-31', end='2012-08-31')时,self会绑定到r,并且值会绑定到startend,但必需的位置arument { {1}}没有受到约束。这就是你得到错误的原因

params

不幸的是,错误消息具有误导性。 “给定的3”是指TypeError: predict() takes at least 2 arguments (3 given) rstart。 “2个参数”指的是两个必需参数endself。 问题是没有给出必需位置参数params

要解决此问题,您需要参数。通常您可以通过拟合找到这些参数:

params

之前打电话

r = r.fit()

pred = r.predict(start='2012-07-31', end='2012-08-31') 会返回r.fit() 将参数“烘焙”,以便调用statsmodels.tsa.arima_model.ARIMAResultsWrapper不需要传递ARIMAResultWrapper.fit

params

产量

import pandas as pd
import numpy as np
from statsmodels.tsa.arima_model import ARIMA

dates = pd.date_range('2012-07-09','2012-07-30')
series = [43.,32.,63.,98.,65.,78.,23.,35.,78.,56.,45.,45.,56.,6.,63.,45.,64.,34.,76.,34.,14.,54.]
res = pd.Series(series, index=dates)
r = ARIMA(res,(1,2,0))
r = r.fit()
pred = r.predict(start='2012-07-31', end='2012-08-31')
print(pred)