python Statsmodels SARIMAX KeyError:';“start”参数无法与数据索引相关的位置匹配;

python Statsmodels SARIMAX KeyError:';“start”参数无法与数据索引相关的位置匹配;,python,statsmodels,Python,Statsmodels,我的第一篇堆栈溢出文章,我正在兼职学习数据科学资格证书,我一直在学习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

我的第一篇堆栈溢出文章,我正在兼职学习数据科学资格证书,我一直在学习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
我运行以下命令

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”。

很抱歉,这是一个输入错误,因为我在玩弄日期-我已经更正了上面的pred=results。predict(start='2019-06-10',end='2020-08-17')[1:]这两个日期肯定都在我的数据集中-我可以看到它们抱歉,无法重现。请用可复制的示例创建代码/Colab笔记本。
start='2019-06-10',end='2019-06-10'