Sarimax 模型优化

问题描述 投票:0回答:0

我已经研究这个 sarimax 模型一段时间了,但对结果仍然不满意,我将代码 bfr 分享为图片,显然这是一种亵渎 hh 所以这次是脚本:

`order_aic_bic = []
for p in range(9):
    # Loop over q values from
    for q in range(9):
        # create and fit ARMA(p,q) model
        model = SARIMAX(y, order=(p, 0, q), freq="M")  # because adf test showed that d=1
        results = model.fit()
        order_aic_bic.append((p, q, results.aic, results.bic))
        order_df = pd.DataFrame(order_aic_bic,
                        columns=['p', 'q', 'AIC', 'BIC'])
mod = sm.tsa.statespace.SARIMAX(y,
order=(3,0,3), seasonal_order= (5,0,5,4),
                                enforce_stationarity=False,
                                enforce_invertibility=False)
results = mod.fit()
print(results.summary().tables[1])
results.plot_diagnostics(figsize=(18, 8))
plt.show()
mae = np.mean(np.abs(results.resid))
print('MAE: %.3f' % mae)
pred = results.get_prediction(start=pd.to_datetime('2022-01-01'), dynamic=False, full_results = True)
pred_ci = pred.conf_int()
ax = y['2018':].plot(label='observed')
pred.predicted_mean.plot(ax=ax, label='One-step ahead Forecast', alpha=.7, figsize=(14, 4))
ax.fill_between(pred_ci.index,
                pred_ci.iloc[:, 0],
                pred_ci.iloc[:, 1], color='k', alpha=.2)
ax.set_xlabel('Date')
ax.set_ylabel('vlm')
plt.legend()
plt.show()
forecast = pred.predicted_mean
print(forecast)`

我试图通过更改 p q d 参数并选择 AIC 最低的参数来增强我的模型,但如果有人能提出更好的销售预测模型,我将不胜感激。

python numpy pycharm regression arima
© www.soinside.com 2019 - 2024. All rights reserved.