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 ...
随机推荐
- 你必须知道的.net读书笔记之第二回深入浅出关键字---对抽象编程:接口和抽象类
请记住,面向对象思想的一个最重要的原则就是:面向接口编程. 借助接口和抽象类,23个设计模式中的很多思想被巧妙的实现了,我认为其精髓简单说来就是:面向抽象编程. 抽象类应主要用于关系密切的对象,而接口 ...
- react异步加载组件
1. 创建 asyncComponent 异步加载工具 import React from 'react' function asyncComponent(loadComponent){ class ...
- 使用Huginn抓取Discourse论坛
Hi! I don't know why the xpath does not work, but have an easier solution. Discourse also has a JSON ...
- AngularJS学习之旅—AngularJS 模块(十五)
一.AngularJS 模块 模块定义了一个应用程序. 模块是应用程序中不同部分的容器. 模块是应用控制器的容器. 控制器通常属于一个模块. 1.创建模块 通过 AngularJS 的 angular ...
- var、let 及 const 区别
var console.log(a) // undefined var a = 1 从上述代码中我们可以发现,虽然变量还没有被声明,但是我们却可以使用这个未被声明的变量,这种情况就叫做提升,并且提升的 ...
- 第二课android中activity启动模式
一.标准启动模式可以用函数gettaskid得到任务的idtostring得到地址用textallcaps来设置是否全部大写应用启动自己是在任务栈里创建不同实例可以用返回来返回上一个任务栈在andro ...
- 《JAVA程序设计》_第九周学习总结
一.学习内容 1.数据库的建立.配置 在官网先下载好MySQL.navicat for MySQL.XAMPP.MySQL-connecter 在XAMPP中点击start开启MySQL 在navic ...
- node编写定时任务,for循环只执行一遍的解决办法
在用node编写定时任务时候,发现for循环只执行i=0这一次,就不接着循环执行了,下面贴上代码: exports.task = async function(ctx){ let { app } = ...
- mongoTemplate查询大数据过慢
先上两段代码 代码一 Query query = new Query();queryAfter.addCriteria(Criteria.where("id").in(idList ...
- Airtest自动化测试工具
一开始知道Airtest大概是在年初的时候,当时,看了一下官方的文档,大概是类似Sikuli的一个工具,主要用来做游戏自动化的,通过截图的方式用来解决游戏自动化测试的难题.最近,移动端测试的同事尝试用 ...