pythonstatsmodelsarimasarimax

Can not plot predictedvalues with SARIMA


I am bulding SARIMA time series with statsmodels.tsa.statespace.sarimax beacuse pmdarima doesn't install. My data has 44 observation 10 years every quarter. My target is to predict next 1 or 2 years. Could anyone give idea what I need to pot the prediction. I am not proficient in Python but I think there is kinf of missunderstanding between my quarterly data and the desired prediction. I compile algorityhm from towardsdatascience, articles from here and youtube. After evaluating P,D,Q, m parameters with min AIC and fit the model this is the result - can't plot the predict steps predicted values missing I made 2 columns - dates and GVA - gross added value I am looking for Data set is here

If someone could help..

Google collab notebook is here Dataset I have collected is here


Solution

  • When the data is prepared (setting index right, stationarizing etc.), I usually do as follows:

    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()