在 python 中用 statsmodels创建 ARIMA 模型进行预测时间序列:

import pandas as pd
import statsmodels.api as sm df = pd.read_csv("data.csv", index_col=0, parse_dates=True) mod = sm.tsa.statespace.SARIMAX(df['price'], enforce_stationarity=False, enforce_invertibility=False) res = mod.fit()
res.get_prediction(start=pd.to_datetime('2018-1-1'))

运行后报错:

TypeError: int() argument must be a string, a bytes-like object or a number, not 'Timestamp'

这种情况的原因是,读入的时间序列数据的时间没有统一的间隔,例如打印mod._index的结果是

DatetimeIndex(['2016-01-01', '2016-01-08', '2016-01-15', '2016-01-22',
'2016-01-30'],
dtype='datetime64[ns]', name='date', freq=None)

其中2016-01-30是距离前一个时间8天,其它间隔为7天。可以看到这个 DatetimeIndex 的 freq 是 None 类型。

而如果将最后一天修改为2016-01-29,那么mod._index的结果是:

DatetimeIndex(['2016-01-01', '2016-01-08', '2016-01-15', '2016-01-22',
'2016-01-29'],
dtype='datetime64[ns]', freq='W-FRI')

但是此时还会报错

KeyError: 'The `start` argument could not be matched to a location related to the index of the data.'

这是由于get_prediction的 start 参数必须是在时间序列中出现过的时间。

debug 经验++:使用库时,因为层层调用,有时遇上问题光看报错信息解决不了,而调用的代码又没写错,那么很有可能就是数据的问题了。 虽然搜索引擎很好用,但是对于有些小问题来说,可能会变成盲目地在互联网大海捞针。对于开源的库,可以看看有没有类似的别人提过的 issue ,有时候确实是库的bug。自己定位问题还有个办法是对比正确完整的例子,找不同点。

statsmodels.tsa.arima_model预测时报错TypeError: int() argument must be a string, a bytes-like object or a number, not 'Timestamp'的更多相关文章

  1. Python2.7 在使用BSTestRunner.py时报错TypeError: unicode argument expected, got 'str'

    python3往这个库中加入了一些新的内容,使得该库在Python2.7中报错. 解决方法是将导入语句 from io import StringIO as StringIO 更换为: from io ...

  2. Ajax上传文件/照片时报错TypeError :Illegal invocation

    问题 Ajax上传文件/照片时报错TypeError :Illegal invocation 解决 网上搜索问题,错误原因可能有以下几个,依次检查: 请求类型有误,如post请求,但在后台设置的是ge ...

  3. 关于TypeError: strptime() argument 1 must be str, not bytes解析

    关于TypeError: strptime() argument 1 must be str, not bytes解析   在使用datetime.strptime(s,fmt)来输出结果日期结果时, ...

  4. pywinauto: 导入时遇到 "TypeError: LoadLibrary() argument 1 must be string, not unicode"

    pywinauto: 导入时遇到 "TypeError: LoadLibrary() argument 1 must be string, not unicode" 经查询, 看到 ...

  5. 执行python manage.py makemigrations时报错TypeError: __init__() missing 1 required positional argument: 'on_delete'

    在执行python manage.py makemigrations时报错: TypeError: __init__() missing 1 required positional argument: ...

  6. Django :执行 python manage.py makemigrations 时报错 TypeError: __init__() missing 1 required positional argument: 'on_delete'

    原因 执行命令 python manage.py makemigrations 报错 TypeError: __init__() missing 1 required positional argum ...

  7. moviepy执行TextClip.search方法时报错TypeError: a bytes-like object is required, not str

    ☞ ░ 前往老猿Python博文目录 ░ 执行TextClip.search方法时,报错: >>> from moviepy.editor import * >>> ...

  8. Django关联数据库时报错TypeError: __init__() missing 1 required positional argument: 'on_delete'

    sgrade = models.ForeignKey("Grades",) 执行python manage.py makemigrations后出现TypeError: __ini ...

  9. flask渲染模板时报错TypeError: 'UnboundField' object is not callable

    渲染模板时,访问页面提示TypeError: 'UnboundField' object is not callable 检查代码,发现实例化表单类是,没有加括号:form = NewNoteForm ...

随机推荐

  1. Jquer + Ajax 制作上传图片文件

    没什么 说的  直接 上代码 //选择图片并上传 function selectImg(node){ var f = node.value; var file = node.files[0]; if( ...

  2. mysql命令查看表结构及注释

    使用如下命令:select table_schema,table_name,column_name,column_type,column_key,is_nullable,column_default, ...

  3. phpstorm本地怎么上传到服务器

    连接服务器 菜单栏找到[工具/Tools]->[Deployment/部署]->[Confinguration…/配置…]. 点加号(+),添加一台服务器,填写名称,选择类型为SFTP,点 ...

  4. iis读取不到本地证书问题

    导入证书时,通过mmc命令打开控制台->添加管理单元或删除单元->选择本地计算机账号->然后导入证书,解决 ssl证书无法与www.xxx通信. 证书导入后,不能正常读取.有两个问题 ...

  5. 从APP跳转到微信指定联系人聊天页面功能的实现与采坑之旅

    起因: 最近做的APP中有一个新功能:已知用户微信号,可点击直接跳转到当前用户微信聊天窗口页面. 当时第一想法是使用无障碍来做,并且觉得应该不难,只是逻辑有点复杂.没想到最终踩了好多坑,特地把踩过的坑 ...

  6. coreRT 和 Native 编译netcore AOT程序

    AOT是预编译成本地程序,避免JIT动态编译存在的性能问题. netcore一个吸引人的项目,就是基于coreRt 运行时的本地编译技术,下面我来替大家尝试一下它究竟表现如何. <Project ...

  7. Jmeter 接口测试实战-有趣的cookie

    Jmeter 接口测试实战-有趣的cookie 场景: 接口测试时常都需要登录,请求方式(post), 登录常用的方法有通过获取token, 获取session, 获取cookie, 等等. 这几种都 ...

  8. tomat 欢迎页面设置在WEB-INF目录下时不显示问题

    <?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://w ...

  9. 八皇后问题(C#)

    八皇后问题,是一个古老而著名的问题,是回溯算法的典型案例.该问题是国际西洋棋棋手马克斯·贝瑟尔于1848年提出:在8×8格的国际象棋上摆放八个皇后,使其不能互相攻击,即任意两个皇后都不能处于同一行.同 ...

  10. SQLServer修改登陆账户信息

    修改登陆账户信息注意事项 如果 CHECK_POLICY设置为ON,则无法使用 HASHED参数. 如果 CHECK_POLICY更改为ON,则将出现以下行为: 用当前的密码哈希值初始化密码历史记录. ...