首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >时间序列预测开始

时间序列预测开始
EN

Stack Overflow用户
提问于 2020-10-19 02:55:12
回答 1查看 114关注 0票数 0

我用.head()编写了这个系列的hospitalization_diff

代码语言:javascript
复制
date
2020-10-16    347.0
2020-10-15    149.0
2020-10-14    530.0
2020-10-13   -489.0
2020-10-12   -859.0
Name: hospitalizedIncrease, dtype: float64

我想使用ARIMA模型预测时间序列(已经测试了平稳性、差异化和优化参数)。我从here那里拿到了代码。

代码语言:javascript
复制
# split into train-test set
size = int(len(X) * 0.75)
train, test = hospitalization_diff[:size], hospitalization_diff[size:]

# Build Model
model = ARIMA(train, order=(0, 0, 1))  
fitted = model.fit(disp=-1)  

# Forecast
fc, se, conf = fitted.forecast(len(test), alpha=0.05)  # 95% conf

# Make as pandas series
fc_series = pd.Series(fc, index=test.index)
lower_series = pd.Series(conf[:, 0], index=test.index)
upper_series = pd.Series(conf[:, 1], index=test.index)

# Plot
plt.figure(figsize=(12,5), dpi=100)
plt.plot(train, label='training')
plt.plot(test, label='actual')
plt.plot(fc_series, label='forecast')
plt.fill_between(lower_series.index, lower_series, upper_series, 
                 color='k', alpha=.15)
plt.title('Forecast vs Actuals')
plt.legend(loc='upper left', fontsize=8)
plt.show()

然而,作为输出,我得到了

我不明白为什么它会预测这个系列的开始,我做错了什么?

EN

回答 1

Stack Overflow用户

发布于 2020-10-19 04:52:24

因为您的数据集( traintest)按相反的时间顺序排列,这必须在一开始就纠正。

代码语言:javascript
复制
# apply at the beginning of your code
hospitalization_diff.sort_index(inplace=True)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64417149

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档