【发布时间】:2019-07-11 01:33:44
【问题描述】:
我的数据(时间序列)包含两年的数据。(一个值/天,行=360*2)
现在,我尝试使用来自 statsmodels 的 SARIMA 模型。 我随机选择了参数(订单和季节性订单)。 order=(1,0,1),seasonal_order=(0,1,0,360) 它非常适合我的数据。
但我本质上并没有被理解。 我应该如何选择参数(p,d,q)? order=(P,D,Q),seasonal_order=(p,d,q,s=360?) 我可以从 ACF 或 PACF 图中读取它吗?还是 AIC,BIC 来自摘要?
(我尝试从“最小AIC模型”中选择它。但效果不佳)
import statsmodels.api as sm
SARIMA_1_0_1_010 = sm.tsa.SARIMAX(t3, order=(1,0,1), seasonal_order=(0,1,0,300)).fit()
print(SARIMA_1_0_1_010.summary())
residSARIMA = SARIMA_1_0_1_010.resid
fig = plt.figure(figsize=(12,8))
ax1 = fig.add_subplot(211)
fig = sm.graphics.tsa.plot_acf(residSARIMA.values.squeeze(), lags=100, ax=ax1)
ax2 = fig.add_subplot(212)
fig = sm.graphics.tsa.plot_pacf(residSARIMA, lags=100, ax=ax2)
pred = SARIMA_1_0_1_010.predict(700, 1200)
plt.figure(figsize=(22,10))
plt.plot(t3)
plt.plot(pred, "r")
和
max_p = 3
max_q = 3
max_d = 1
max_sp = 0
max_sq = 0
max_sd = 0
pattern = max_p*(max_q + 1)*(max_d + 1)*(max_sp + 1)*(max_sq + 1)*(max_sd + 1)
modelSelection = pd.DataFrame(index=range(pattern), columns=["model", "aic"])
season = 360
num = 0
for p in range(1, max_p + 1):
for d in range(0, max_d + 1):
for q in range(0, max_q + 1):
for sp in range(0, max_sp + 1):
for sd in range(0, max_sd + 1):
for sq in range(0, max_sq + 1):
sarima = sm.tsa.SARIMAX(
t3, order=(p,d,q),
seasonal_order=(sp,sd,sq,360),
enforce_stationarity = False,
enforce_invertibility = False
).fit()
modelSelection.ix[num]["model"] = "order=(" + str(p) + ","+ str(d) + ","+ str(q) + "), season=("+ str(sp) + ","+ str(sd) + "," + str(sq) + ")"
modelSelection.ix[num]["aic"] = sarima.aic
modelSelection.ix[num]["bic"] = sarima.bic
num = num + 1
modelSelection[modelSelection.aic == min(modelSelection.aic)]
预测不好……
【问题讨论】:
标签: python-3.x time-series statsmodels arima