statsmodel 预测开始和结束索引 [英] statsmodel predict start and end indices

查看:31
本文介绍了statsmodel 预测开始和结束索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 statsmodel 包中实现预测功能

I am trying to implement the prediction function from statsmodel package

prediction = results.predict(start=1,end=len(test),exog=test)

输入、测试和输出预测的日期不一致.我得到 1/4/2012 到 7/25/2012 前者和 4/26/2013 到 11/13/2013 后者.部分困难在于我没有完全重复的频率 - 我每天都有不包括周末和假期的值.设置索引的合适方法是什么?

The dates of the input, test, and the output prediction are inconsistent. I get 1/4/2012 to 7/25/2012 for the former and 4/26/2013 to 11/13/2013 for the latter. Part of the difficulty is that I don't have a completely recurring frequency - I have daily values excluding weekends and holidays. What is the appropriate way to set the indices?

x = psql.frame_query(query,con=db)
x = x.set_index('date')

train = x[0:len(x)-50]
test = x[len(x)-50:len(x)]

arima = tsa.ARIMA(train['A'], exog=train, order = (2,1,1))
results = arima.fit()
prediction = results.predict(start=test.index[0],end=test.index[-1],exog=test)

我收到错误

There is no frequency for these dates and date 2013-04-26 00:00:00 is not in dates index. Try giving a date that is in the dates index or use an integer

这是第一组数据

2013-04-26   -0.9492
2013-04-29    2.2011
...
2013-11-12    0.1178
2013-11-13    2.0449

推荐答案

索引应该是任何类似日期时间的值,包括 pandas 的时间戳.如果您使用 Pandas 的工作日频率,那么这应该可以工作,尽管假期可能会出现问题,因为它没有标准化.不过,您可以使用他们的自定义假期日历支持并获得您想要的.

The indices should be any datetime-like values, including pandas' timestamps. If you use a business-day frequency from pandas then this should work, though holidays may present a problem here given that it's not standardized. You may be able to use their custom holiday calendar support though and get what you want.

正如我在您的其他问题中所提到的,如果没有完全可重复的示例,我无法就您投入的内容所获得的内容发表太多看法,尽管如果您提供正确的索引,这应该可行.如果日期没有周期性频率.例如,周末和节假日被排除在外而没有告诉索引,那么就无法预测您希望从样本中取出哪些日期.

As I've mentioned in your other questions, without a fully reproducible example, there's not much I can say about what you get given what you put in, though this should work if you give the correct index. If there's no periodic frequency to the dates. E.g., weekends and holidays are excluded without telling the index that, then there's no way to predict what dates you'll want out of sample.

这篇关于statsmodel 预测开始和结束索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆