Python ARIMA exogenous variable out of sample

后端 未结 3 2153
广开言路
广开言路 2021-02-14 13:04

I am trying to predict a time series in python statsmodels ARIMA package with the inclusion of an exogenous variable, but cannot figure out the correct way to insert the exogeno

相关标签:
3条回答
  • 2021-02-14 13:33

    while fiting fit2 you already mentionned exog variables, so no need to repeat it:

    exogx = np.array(range(1,5)) # I think you will need 4 exegeneous variables to perform an ARIMAX(0,0,0) since you want out of sample forecast with 4 steps ahead
    fit2 = sm.tsa.ARIMA(df, (0,0,0),exog = exogx).fit()
    # if you want to do an out-of-sample-forecast use fit2.forecast(steps) instead
    #I would do this
    pred = fit2.forecast(steps = 4)
    fcst_index = pd.date_range(start = df.shift(1,'10T').index[-1]  , periods = 4, freq = '10T')
    fcst_serie = pd.Series(data = pred1[0], index = fcst_index)
    print fcst_serie
    

    Hope that it will help! This is a great post.I have never tried exogeneous variables on ARIMA before but papers are saying it's not really relevant whatever the field you are using it (will search for the papers if needed or you can google it)

    0 讨论(0)
  • 2021-02-14 13:43

    If any one is using forecast function this worked for me for one step prediction.

    history is training array

    exog is external variable array

    Y_exog_test is out of sample corresponding external variable. Change it to ARIMAX and it should work

    model = sm.tsa.statespace.SARIMAX(history, trend='c', order=(1,1,1),seasonal_order=(0,1,0,24),exog=yexog)
    
    model_fit = model.fit()
    
    predicted = model_fit.forecast(step=1,exog=[[Y_exog_test]], dynamic=True)
    
    0 讨论(0)
  • 2021-02-14 13:45

    This is probably better posted on the github issue tracker. I filed a ticket though.

    It's best to file a ticket there, if not I might forget it. Quite busy these days.

    There was a bug in the logic for the special case of k_ar == 0. Should be fixed. Let me know if you can/cannot give that patch a spin. If not, I can do some more rigorous testing and merge it.

    Statsmodels on top of spark? I'm intrigued.

    0 讨论(0)
提交回复
热议问题