首页 > 解决方案 > 使用 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()

在此处输入图像描述

告诉我出了什么事。我如何获得预测?

标签: pythonmachine-learningtime-seriesprediction

解决方案


推荐阅读