python - 使用 SARIMA 进行时间序列预测
问题描述
我是时间序列预测和机器学习的新手。
有一个数据框
在注册列中 - 以每小时频率进行的对象注册数量
我试图预测未来几天的值,但没有任何正常结果。我用 SARIMA 做了预测。我检查了平稳性 - 该行是静止的。
我的代码:
import pandas as pd
import numpy as np
import statsmodels.api as sm
import matplotlib.pyplot as plt
from pylab import rcParams
rcParams['figure.figsize'] = 11, 9
df=pd.read_csv('mt_resample.csv',index_col=[0],parse_dates=[0])
Data Registration
2021-03-25 15:00:00 22
2021-03-25 16:00:00 16
2021-03-25 17:00:00 22
2021-03-25 18:00:00 16
2021-03-25 19:00:00 10
... ...
2021-07-22 07:00:00 4
2021-07-22 08:00:00 11
2021-07-22 09:00:00 15
2021-07-22 10:00:00 8
2021-07-22 11:00:00 17
decomposition = sm.tsa.seasonal_decompose(y, model='additive')
fig = decomposition.plot()
plt.show()
mod = sm.tsa.statespace.SARIMAX(df,
order=(1, 1, 1),
seasonal_order=(1, 1, 1, 12),
enforce_stationarity=True,
enforce_invertibility=False)
results = mod.fit()
# Get forecast 500 steps ahead in future
pred_uc = results.get_forecast(steps=100)
# Get confidence intervals of forecasts
pred_ci = pred_uc.conf_int()
ax = y.plot(label='observed', figsize=(20, 15))
pred_uc.predicted_mean.plot(ax=ax, label='Forecast')
ax.fill_between(pred_ci.index,
pred_ci.iloc[:, 0],
pred_ci.iloc[:, 1], color='k', alpha=.25)
ax.set_xlabel('Date')
ax.set_ylabel('Registration')
plt.legend()
plt.show()
告诉我出了什么事。我如何获得预测?
解决方案
推荐阅读
- r - 在R中将XY转换为纬度
- node.js - NodeJS POST 表单总是返回 404
- mongodb - 查询没有数组的嵌套字段
- java - 如何在休眠中具有一对多或多对一关系的两个表中一一插入数据(每次程序运行)
- firebase - Firestore 操作挂起
- makefile - 如何在 Makefile 中获取父目录
- python - 安装 pip Python
- javascript - 将 PHP 与 Javascript 结合使用以从购物车中删除商品
- javascript - 无法通过 unpkg 使用 MATERIAL-UI & React
- python - 使用 matplotlib 绘制 pandas DataFrame