【问题标题】:statsmodel predict start and end indicesstatsmodel 预测开始和结束索引
【发布时间】:2013-12-11 05:28:42
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: python statsmodels


    【解决方案1】:

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

    正如我在您的其他问题中提到的那样,如果没有完全可重复的示例,对于您输入的内容,我无话可说,尽管如果您提供正确的索引,这应该可以工作。如果日期没有周期性频率。例如,在不告诉索引的情况下排除周末和节假日,那么就无法预测您希望从样本中删除哪些日期。

    【讨论】:

    • 那么ints不会工作吗?我应该使用日期时间对象吗?
    • 我用代码编辑了我的原始帖子。如果有任何其他相关信息我应该发布,请告诉我。
    • 整数会起作用。请参阅文档字符串和邮件列表讨论。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-07
    • 1970-01-01
    • 1970-01-01
    • 2020-01-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多