statsmodels.tsa.arima_model预测时报错TypeError: int() argument must be a string, a bytes-like object or a number, not 'Timestamp'
在 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'的更多相关文章
- Python2.7 在使用BSTestRunner.py时报错TypeError: unicode argument expected, got 'str'
python3往这个库中加入了一些新的内容,使得该库在Python2.7中报错. 解决方法是将导入语句 from io import StringIO as StringIO 更换为: from io ...
- Ajax上传文件/照片时报错TypeError :Illegal invocation
问题 Ajax上传文件/照片时报错TypeError :Illegal invocation 解决 网上搜索问题,错误原因可能有以下几个,依次检查: 请求类型有误,如post请求,但在后台设置的是ge ...
- 关于TypeError: strptime() argument 1 must be str, not bytes解析
关于TypeError: strptime() argument 1 must be str, not bytes解析 在使用datetime.strptime(s,fmt)来输出结果日期结果时, ...
- pywinauto: 导入时遇到 "TypeError: LoadLibrary() argument 1 must be string, not unicode"
pywinauto: 导入时遇到 "TypeError: LoadLibrary() argument 1 must be string, not unicode" 经查询, 看到 ...
- 执行python manage.py makemigrations时报错TypeError: __init__() missing 1 required positional argument: 'on_delete'
在执行python manage.py makemigrations时报错: TypeError: __init__() missing 1 required positional argument: ...
- 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 ...
- moviepy执行TextClip.search方法时报错TypeError: a bytes-like object is required, not str
☞ ░ 前往老猿Python博文目录 ░ 执行TextClip.search方法时,报错: >>> from moviepy.editor import * >>> ...
- Django关联数据库时报错TypeError: __init__() missing 1 required positional argument: 'on_delete'
sgrade = models.ForeignKey("Grades",) 执行python manage.py makemigrations后出现TypeError: __ini ...
- flask渲染模板时报错TypeError: 'UnboundField' object is not callable
渲染模板时,访问页面提示TypeError: 'UnboundField' object is not callable 检查代码,发现实例化表单类是,没有加括号:form = NewNoteForm ...
随机推荐
- InnoSetup 脚本打包及管理员权限设置
InnoSetup使用教程:InnoSetup打包安装 脚本详细 1. 定义变量 #define MyAppName "TranslationTool" #define MyApp ...
- 关于jQuery中的选择器
1:选择器的作用 获取网页的上面的标签元素等等,然后对他进行一些列的操作(添加样式,添加行为...) 2:选择器有哪些 基本选择器,层次选择器,过滤选择器,表单选择器 一:基本选择器 基本选择器是jq ...
- SAP MM 采购ERP顾问咨询费限制总金额的框架协议实现方案
SAP MM 采购ERP顾问咨询费限制总金额的框架协议实现方案 [业务场景] 采购部门与ERP咨询公司签订了一个框架协议,只规定不同级别顾问的人天费用,不限定这些不同级别咨询顾问的具体采购的人天数,但 ...
- Android应用跳转到微信和支付宝扫一扫
新版的微信已经把微信功能的schema都禁掉了,意味着我们无法打开微信的扫一扫等功能,目前正常的只能先进入微信(我测试的时候是微信版本7.0.3)已经是很新的版本了 具体调起微信扫一扫代码如下,测试后 ...
- 微信小程序中通过腾讯地图进行逆地址解析报错message: "请求来源未被授权, 此次请求来源域名:servicewechat.com"
在小程序中获取定位具体信息时,不要配置腾讯地图中的WebServiceAPI中的域名白名单什么的,域名配置直接在小程序后台中配置(就是这个货https://apis.map.qq.com), 千万千万 ...
- linux添加crontab定时任务
1.crontab -e命令进入linux定时任务编辑界面,举个简单的例子,比如我要定时往txt文件写入 */ * * * * .txt */1就是每隔一分钟像文件写入,其他一些详细的操作大家可以去网 ...
- 分布式系统CAP理论
在单机的数据库系统之中,我们很容易实现一套满足ACID 特性的 事务处理系统, 事务的一致性不存在问题. 但是在分布式系统之中,由于数据分布在不同的主机结点上,如何对着些数据进行分布式的事务处理就具有 ...
- 51Nod 1004 n^n的末位数字
思路:首先将0~9的平方的尾数放在一个数组a里面,方便后面直接调用,因为不论多大的数做什么运算,得到的结果的最后一位数只和运算前所有数的最后一位数有关系.新建变量d,z一个是底数,一个是幂次.循环判断 ...
- Django学习笔记(1)--第一个项目
操作系统:Windows Python版本:python3.6 前置工作: pip install virtualenvwrapper #安装虚拟环境管理包 1.创建虚拟环境 mkvirtualenv ...
- Linux新增和删除环境变量
vi ~/.bashrc 添加 export 变量名=值 使环境变量生效 source ~/.bashrc