Statsmodels AR模型预测错误

时间:2016-07-05 23:22:35

标签: python pandas time-series statsmodels

我试图预测时间序列数据并遇到此问题。可重现的代码在这里

import pandas as pd
import statsmodels
import statsmodels.api as sm
print pd.__version__
print statsmodels.__version__
s = pd.Series({'2015-01-04' :2.0,
    '2015-01-11' :2.0,
    '2015-01-18' :4.0,
    '2015-01-25' :8.0,
    '2015-02-08' :4.0,
    '2015-03-01' :6.0,
    '2015-03-08' :2.0,
    '2015-03-15' :6.0})
s.index = pd.DatetimeIndex(s.index)
model = sm.tsa.AR(s, freq='W')
modelResult = model.fit()
prediction = modelResult.predict(start='2015-03-22', end='2015-04-26')
print prediction

输出

0.18.0
0.8.0.dev0+Unknown
Traceback (most recent call last):
  File "question.py", line 17, in <module>
    prediction = modelResult.predict(start='2015-03-22', end='2015-04-26')
  File "/home/xxx/lib/anaconda2/lib/python2.7/site-packages/statsmodels-0.8.0-py2.7-linux-x86_64.egg/statsmodels/base/wrapper.py", line 95, in wrapper
    obj = data.wrap_output(func(results, *args, **kwargs), how)
  File "/home/xxx/lib/anaconda2/lib/python2.7/site-packages/statsmodels-0.8.0-py2.7-linux-x86_64.egg/statsmodels/tsa/ar_model.py", line 800, in predict
    predictedvalues = self.model.predict(params, start, end, dynamic)
  File "/home/xxx/lib/anaconda2/lib/python2.7/site-packages/statsmodels-0.8.0-py2.7-linux-x86_64.egg/statsmodels/tsa/ar_model.py", line 199, in predict
    start = self._get_predict_start(start, dynamic)
  File "/home/xxx/lib/anaconda2/lib/python2.7/site-packages/statsmodels-0.8.0-py2.7-linux-x86_64.egg/statsmodels/tsa/ar_model.py", line 159, in _get_predict_start
    start = _validate(start, k_ar, self.data.dates, method)
  File "/home/xxx/lib/anaconda2/lib/python2.7/site-packages/statsmodels-0.8.0-py2.7-linux-x86_64.egg/statsmodels/tsa/ar_model.py", line 43, in _validate
    start = _index_date(start, dates)
  File "/home/xxx/lib/anaconda2/lib/python2.7/site-packages/statsmodels-0.8.0-py2.7-linux-x86_64.egg/statsmodels/tsa/base/datetools.py", line 57, in _index_date
    "an integer" % date)
ValueError: There is no frequency for these dates and date 2015-03-22 00:00:00 is not in dates index. Try giving a date that is in the dates index or use an integer

我注意到我使用WEEKLY数据进行训练,我的预测日期也是SUNDAY,它应该与训练数据兼容。我不确定是否能解决这个问题。

非常感谢。

0 个答案:

没有答案