Skip to content

Add method for generating ARMA predictions for new data, unrelated to training data #2577

Open

Description

@eraoul

It seems that the only way to use a trained ARMA model on new data is to use this internal function: _arma_predict_out_of_sample. Furthermore, it's not obvious how to do so.

I would assume that for an ARMA(p,q) model, there are max(p.q) previous datapoints required to generate a new prediction. So If I had an AR(2,3) model I'd need to pass in 3 datapoints to get one new output sample. There is also some information about past "residuals" that is not completely clear how to generate. An API like the following (perhaps with extra required parameters such as residuals....) would be quite useful to me:

def arma_model.predict_new_data(prev_datapoints, num_samples_to_generate=1)

where prev_datapoints would be a list of length 3, and if num_samples_to_generate > 1: then the "dynamic" stuff would be turned on automatically.

See:
http://stackoverflow.com/questions/18616588/arma-out-of-sample-prediction-with-statsmodels
http://stats.stackexchange.com/questions/76160/im-not-sure-that-statsmodels-is-predicting-out-of-sample

Activity

  1. josef-pkt commented on Aug 7, 2015

    @josef-pkt
    Member

    The problem is that a ARMA(p,q) in it's basic prediction form needs to use the q past residuals for prediction. Those are usually obtained from fitting the model the the previous data points.

    With a standalone function the user would need to provide the previous residuals, either from a filter operation or by assumption. so we would have two possibilities

    • require users to provide q residuals
    • allow users to provide a long time series of the data (endog y), and run the filter over the entire sample to estimate the residuals from zero initial conditions without reestimating the parameters.

    The statespace model might provide something like the corresponding filter. @ChadFulton

  2. added this to the 0.8 milestone on Aug 7, 2015
  3. josef-pkt commented on Aug 7, 2015

    @josef-pkt
    Member

    milestone 0.8 if someone wants to give it a try.

  4. josef-pkt commented on Aug 7, 2015

    @josef-pkt
    Member

    I don't remember what the requirements are for calculating prediction intervals.

  5. ChadFulton commented on Aug 7, 2015

    @ChadFulton
    Member

    I have a longer comment that I'll post in a moment, but there's a quick solution that you may be interested in. Suppose that you have a training dataset X and a new unrelated dataset Y. As I understand it, you want to do the following:

    1. Estimate parameters using dataset X
    2. Get out-of-sample predictions conditional on the observations in Y.

    One way to do that is the following; let's suppose you want to fit an ARIMA(4,1,1) model and you want 5 out-of-sample forecasts.

    mod1 = sm.tsa.SARIMAX(X, order=(4,1,1))
    res1 = mod1.fit()
    
    mod2 = sm.tsa.SARIMAX(Y, order=(4,1,1))
    res2 = mod2.filter(res1.params)
    print(res2.forecast(5))
  6. ChadFulton commented on Aug 7, 2015

    @ChadFulton
    Member

    I was going to post something else, but on reflection the above is almost certainly what you want. And it will work no matter how many data points are in Y.

  7. eraoul commented on Aug 7, 2015

    @eraoul
    Author

    Thanks Josef and Chad.

    Josef, how many previous points are required to compute the q residuals? Is
    there a simple formula giving this?

    Chad, sorry for the naive question, but what is SARIMAX? Seasonal ARIMA I
    guess... but what is the "X"? Also teh switch from AMIRA(4,1,1) to SARIMAX
    in your solution surprises me...

    Thanks!

    On Fri, Aug 7, 2015 at 12:36 PM, ChadFulton [email protected]
    wrote:

    I was going to post something else, but on reflection the above is almost
    certainly what you want. And it will work no matter how many data points
    are in Y.

    —
    Reply to this email directly or view it on GitHub
    #2577 (comment)
    .

  8. ChadFulton commented on Aug 7, 2015

    @ChadFulton
    Member

    SARIMAX stands for Seasonal Autoregressive Integrated Moving-average with eXogenous regressors. It is just a very generic class that allows more general models than just ARIMA. So in the example I gave, it does not use the seasonal component or the exogenous regressors component, and so is just estimating an ARIMA(4,1,1) model as you would expect.

    I should note, I guess, that SARIMAX is part of the state space package which is in master, but has not yet been released (it will be in statsmodels 0.7.0).

  9. josef-pkt commented on Aug 7, 2015

    @josef-pkt
    Member

    the documentation for SARIMAX is at http://www.statsmodels.org/dev/statespace.html#seasonal-autoregressive-integrated-moving-average-with-exogenous-regoressors-sarimax

    ARMA also supports the explanatory, exogenous variables X, but the name is from before it did.

    how many previous points are required to compute the q residuals? Is
    there a simple formula giving this?

    That depends on the persistence of the process. Unless persistence is very high, the filtered series can be short and we can just assume that the residuals are zero before a few periods ago.
    I never tried out any experiments for this.
    I think the impulse response function could be used to see how long lasting shocks are.
    (For ARMA there is a ArmaProcess class that takes the arma parameters/lag polynomials and can calculate the impulse response function. http://www.statsmodels.org/dev/generated/statsmodels.tsa.arima_process.arma_impulse_response.html )

  10. hanhanzhai commented on Feb 15, 2017

    @hanhanzhai

    Hi @ChadFulton ! It's really great to see the new released! Would you mind explain more about when adding exog variables in the scenario above? Thanks much!!! How many data points required for exog?

    mod1 = sm.tsa.SARIMAX(X, order=(4,1,1))
    res1 = mod1.fit()

    mod2 = sm.tsa.SARIMAX(Y, order=(4,1,1))
    res2 = mod2.filter(res1.params)
    print(res2.forecast(5))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions