【问题标题】:Can not plot predictedvalues with SARIMA无法使用 SARIMA 绘制预测值
【发布时间】:2021-10-17 19:32:36
【问题描述】:

我正在使用 statsmodels.tsa.statespace.sarimax 构建 SARIMA 时间序列,因为没有安装 pmdarima。我的数据每季度有 10 年的 44 次观察。我的目标是预测未来 1 或 2 年。谁能告诉我我需要什么来预测预测。我不精通 Python,但我认为我的季度数据和期望的预测之间存在误解。我从面向数据科学、来自这里的文章和 youtube 编译算法。 在使用 min AIC 评估 P、D、Q、m 参数并拟合模型后,这是结果 - 无法绘制预测步骤 我做了 2 列 - 日期和 GVA - 我正在寻找的总附加值 Data set is here

如果有人可以帮忙..

Google collab notebook is here Dataset I have collected is here

【问题讨论】:

    标签: python statsmodels arima sarimax


    【解决方案1】:

    当数据准备好(设置正确的索引,平稳化等)时,我通常会这样做:

    model2 = sm.tsa.statespace.SARIMAX(df['x'], order=(0, 1, 3), seasonal_order=(0, 1, 1, 4))
    res2 = model2.fit()
    pred_uc2 = res2.get_forecast(steps=12) # note here the usage of steps ahead and get_forecast
    pred_ci2 = pred_uc2.conf_int()
    ax = df['x'].plot(label = OB, figsize=(14, 8)) # test data
    pred_uc2.predicted_mean.plot(ax=ax, label=FC) $ prediction
    ax.fill_between(pred_ci2.index, # confidence intervals
                    pred_ci2.iloc[:, 0],
                    pred_ci2.iloc[:, 1], color='k', alpha=.25)
    ax.set_xlabel('Date')
    ax.set_ylabel('Price')
    plt.legend()
    plt.show()
    

    【讨论】:

    • 我会接受你的建议! [0,24,3] 范围内的数字 3 也有助于遵循 new_dates=[df.index[-1]+DateOffset(months=x) for x in range(0,24,3)] 我可以问你我是否不遵守规则 - 你是否为我的模型推荐这些数字(0、1、3),seasonal_order= (0, 1, 1, 4) 因为我真的在找人来批准它
    • 对不起,这只是我最近做的一个代码 sn-p,让您了解它是如何工作的。 ARIMA 模型不适合您的特定数据。对于参数搜索,您可以使用pmdarima 包或网格搜索,前提是您有足够的theory background
    • 没关系。我无法安装 pmdarima - 我重新安装了 jupyter NB 两次更新了所有库 - 但没有。我将再次阅读您之前提出的理论,我一直使用到现在。如果你只有时间,我的模型看起来合理吗G collab
    猜你喜欢
    • 1970-01-01
    • 2018-09-10
    • 1970-01-01
    • 1970-01-01
    • 2018-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-21
    相关资源
    最近更新 更多