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 core 使用MD5加密解密字符串
/// <summary> /// 加密 /// </summary> /// <param name="Text">要加密的文本</pa ...
- @Data注解使用后在eclipse中get/set报错解决方法
Maven项目中已经导入相关的lombok.jar包但是使用后仍提示无set/get方法 安装完成之后,请确认eclipse安装路径下是否多了一个lombok.jar包,并且其 配置文件eclipse ...
- nginx系列8:反向代理和负载均衡原理
反向代理是nginx的一个非常重要的功能. 反向代理 nginx支持四层反向代理和七层反向代理,如下图. 负载均衡 负载均衡是实现服务高性能和高可用的重要手段,而nginx是实现负载均衡的重要工具.
- 你真的懂JavaScript基础类型吗
夯实Javascript基础. 基本类型有六种: null,undefined,boolean,number,string,symbol. 基本类型的值是保存在栈内存中的简单数据段 基础类型特性 基础 ...
- Gulp 前端优化
使用方法: 下载 node.js , https://nodejs.org/en/,并安装 msi 一下命令都属于 dos 命令 node -v,npm -v,检验是否下载成功(出现版本号) 将 np ...
- WebGL或OpenGL关于模型视图投影变换的设置技巧
目录 1. 具体实例 2. 解决方案 1) Cube.html 2) Cube.js 3) 运行结果 3. 详细讲解 1) 模型变换 2) 视图变换 3) 投影变换 4) 模型视图投影矩阵 4. 存在 ...
- 超大文本文件浏览器Snaptext,支持不限制大小的文本文件浏览
文本文件超过1G就很少有软件可以打开了,超过10G就只有有限的几个可以打开了,那20G.30G.100G呢? Snaptext超大文本浏览器,应该是世界上最快速的文本文件浏览器,它支持基本不限制大小的 ...
- Java初学习-常见单词
implements 实行/实现 用于实现接口(interface) extends 延伸/扩展 用于类的继承 container 容 ...
- Redis笔记-Sentinel哨兵模式
Redis以主从的模式搭建集群后,如果主节点Master挂掉,虽然可以实现将备用节点Slave切换成主节点,但是Redis本身并没有自动监控机制,需要借助Sentinel哨兵模式,实现监控并实现自动切 ...
- iOS 多线程 NSOperation、NSOperationQueue
1. NSOperation.NSOperationQueue 简介 NSOperation.NSOperationQueue 是苹果提供给我们的一套多线程解决方案.实际上 NSOperation.N ...