- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的第一个堆栈溢出帖子,我正在兼职学习数据科学资格,我坚持使用 Statsmodels SARIMAX 预测
我的时间序列数据如下所示
ts_log.head()
Calendar Week
2016-02-22 8.168486
2016-02-29 8.252707
2016-03-07 8.324821
2016-03-14 8.371474
2016-03-21 8.766238
Name: Sales Quantity, dtype: float64
ts_log.tail()
Calendar Week
2020-07-20 8.326759
2020-07-27 8.273847
2020-08-03 8.286521
2020-08-10 8.222822
2020-08-17 8.011687
Name: Sales Quantity, dtype: float64
我运行以下命令
train = ts_log[:'2019-07-01'].dropna()
test = ts_log['2020-08-24':].dropna()
model = SARIMAX(train, order=(2,1,2), seasonal_order=(0,1,0,52)
,enforce_stationarity=False, enforce_invertibility=False)
results = model.fit()
总结展示
results.summary()
Dep. Variable: Sales Quantity No. Observations: 175
Model: SARIMAX(2, 1, 2)x(0, 1, 0, 52) Log Likelihood 16.441
Date: Mon, 21 Sep 2020 AIC -22.883
Time: 22:32:28 BIC -8.987
Sample: 0 HQIC -17.240
- 175
Covariance Type: opg
coef std err z P>|z| [0.025 0.975]
ar.L1 1.3171 0.288 4.578 0.000 0.753 1.881
ar.L2 -0.5158 0.252 -2.045 0.041 -1.010 -0.022
ma.L1 -1.5829 0.519 -3.048 0.002 -2.601 -0.565
ma.L2 0.5093 0.502 1.016 0.310 -0.474 1.492
sigma2 0.0345 0.011 3.195 0.001 0.013 0.056
Ljung-Box (Q): 30.08 Jarque-Bera (JB): 2.55
Prob(Q): 0.87 Prob(JB): 0.28
Heteroskedasticity (H): 0.54 Skew: -0.02
Prob(H) (two-sided): 0.05 Kurtosis: 3.72
但是,当我尝试预测时,我收到一个关键错误,表明我的开始日期不正确,但我看不出它有什么问题
pred = results.predict(start='2019-06-10',end='2020-08-17')[1:]
KeyError: 'The `start` argument could not be matched to a location related to the index of the data.'
我可以看到这两个日期都是有效的:
ts_log['2019-06-10']
8.95686647085414
ts_log['2020-08-17']
8.011686729127847
如果我改为使用数字运行,则效果很好
pred = results.predict(start=175,end=200)[1:]
我喜欢使用日期,这样我就可以在我的时间序列图中与其他日期一起使用它
最佳答案
艾玛特,
您的开始和结束日期似乎相同。
start='2019-06-10',end='2019-06-10'
请仔细检查这是否是您想要的。还要检查数据集中是否存在“2019-06-10”。
关于python Statsmodels SARIMAX KeyError : 'The ` start` argument could not be matched to a location related to the index of the data.',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64000289/
对于我的家庭作业,如果用户输入的键(文本)包含任何非字母字符并重新提示,我被告知要引发一个键错误。到目前为止,我有这个似乎有效但显然没有使用预期的 try/except 结构 key=input("P
编写try/except语句时,是否使用 except KeyError: 或 except KeyError as e: 我得到了相同的结果。 两者有什么区别? KeyError as e 只是更具
我在使用 Python Flask 和 Flask-Mail 库时遇到问题。 我收到一个错误: KeyError: 'mail' 谁能帮我解决这个问题? 我的代码是: # -*- coding: ut
我正在尝试获取 Twitter 登录页面中的隐藏元素。我遵循的过程只是获取该页面中的隐藏元素。但问题是,当我尝试获取这些元素的值时,我遇到了关键错误。代码是: import requests,
我正在尝试将 atexit 处理程序添加到我的代码中。但我发现如果我导入了线程模块,它会给我一个 KeyError 异常。这是 python 线程模块中的错误吗? #!/usr/bin/python2
我正在从 Python2.7 numba 代码转换为 Python3.4。此函数pairwise_distance 将多维数组X 和Y 转换为距离矩阵。 但是,我使用 numba 装饰器 @jit 来
我有 2 个用于生产和开发的独立设置文件以及一个通用的 base.py 设置文件 base.py SECRET_KEY = r"!@#$%^&123456" prod.py from .base im
下面的代码 for k in list(g_score.keys()): print(g_score[k]) 返回 KeyError对我来说: Traceback (most recent c
我收到了一份。在Spyder中第二次从子文件夹导入库时出错,但第一次(重新启动Spyder后)或在Spyder外导入时工作正常。。代码是:。其中,test_lib.py只是。输出结果为:。当库不在子文
我希望以下列方式获取一个对象: Collection.objects.get(name='name', type='library', owner=owner, parent=parent) 不幸的是
如何加入这两个文本文档? 文档 1: 1000001 10:0.471669 250:0.127552 30:0.218773 64:0.249413 1000002 130:0.0839656 10
这段代码有什么问题? 这是我的 HTML: File: 这是我的 Python 脚本: #! /usr/bin/env python import os, sys; from mod_py
我正在尝试在 Linux 中使用 cron 运行一个 Python 脚本,它应该构建一个数据字典。我正在尝试使用 datetime().now().time() 作为字典中的键,但它似乎会引发错误。
我正在尝试更改列或处理列,但出现一些 keyError 错误。从事芝加哥犯罪数据分析工作。 例如当我尝试运行时 ds["DATE OF OCCURRENCE"] = pd.to_datetime([d
我有一个包含以下列的数据框,我只是想通过转换现有列来添加新列。我不明白为什么我会收到此错误,特别是考虑到数据框很好并且我可以在 Zip 上使用 groupby 而不会出现任何索引问题。 print(d
我正在尝试使用 ffmpeg 从视频文件中获取分辨率高度和音频比特率,但出现以下错误,但并不能告诉我太多信息: File "/home/user/code/python/reduce_video_si
我正在为每个单独的州分配区域。我的代码从一个 excel 文件中读取,大约有 30k 行。我建立了一个字典,将每个州分配给一个地区,并为每个州名称分配州缩写。我正在尝试创建一个列来填充每个行项目的区域
我仍在努力学习 Python 词典的来龙去脉。当我运行这个: #!/usr/bin/env python3 d = {} d['foo']['bar'] = 1 我收到 KeyError: 'foo'
我正在尝试使用 Tensorflow 训练线性回归器。 如果我通过自动确定实值列来实例化学习器,则拟合工作正常。 auto_feature_columns = tf.contrib.learn
我正在尝试编写一个可以从YouTube下载整个播放列表的代码。它适用于某些播放列表,但不适用于少数播放列表。我在下面的代码中显示的播放列表之一。也可以随时在此代码上添加更多功能。 如果已有下载该播放列
我是一名优秀的程序员,十分优秀!