ar模型python,statsmodels中的AR模型

在尝试使用Python的AR模型对时间序列数据进行拟合时,遇到了TypeError。问题出现在将'last_hour'(类型为int)与'Timestamp'对象相减时。错误提示表明需要一个'datetime.datetime'对象,但接收到的是一个'int'。解决这个问题可能需要确保'last_hour'被正确地转换为datetime对象。
摘要由CSDN通过智能技术生成

我试图在Python中拟合时间序列自回归模型

输入数据框:code test_col

2018-09-20 18:00:00 10

2018-09-20 19:00:00 20

2018-09-20 20:00:00 21

2018-09-20 21:00:00 17

2018-09-20 22:00:00 7

测向索引:

^{pr2}$

型号:mod = AR(DF[test_col])

res = mod.fit(maxlag= 20, ic= 'aic')

last_hour = df.index[[len(df)-1]]

pred = res.predict(start=last_hour[0],end = last_hour[0] )

last\u hour=>从要预测的索引中获取最新的时间戳

错误:File "pandas/tslib.pyx", line 1280, in pandas.tslib._Timestamp.__sub__ (pandas/tslib.c:23914)

TypeError: descriptor '__sub__' requires a 'datetime.datetime' object but received a 'int'

我查过“最后一小时”的类型print (type(last_hour))

关于如何纠正这个问题有什么建议吗。在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值