Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python statsmodels ARIMA Forecast

I am trying to do out of sample forecasting using python statsmodels. I do not want to just forecast the next x number of values from the end of the training set but I want to forecast one value at a time and take in consideration the actual values when forecasting. In other words I want to do rolling 1-period forecasts, but I don't want to recalibrate the model every time. The closest post I could find was here:

ARMA out-of-sample prediction with statsmodels

However, this uses ARMA not ARIMA. How can I achieve this with ARIMA or is there a better method? I know I could actually pull the coefficients and apply a function myself but in my code the ARIMA model I am using is dynamic over time, therefore the number of coefficients and lagged values used is not constant. Any help would be greatly appreciated.

like image 596
klib Avatar asked Nov 11 '15 23:11

klib


People also ask

Is ARIMA Good for forecasting?

It is widely used in demand forecasting, such as in determining future demand in food manufacturing. That is because the model provides managers with reliable guidelines in making decisions related to supply chains. ARIMA models can also be used to predict the future price of your stocks based on the past prices.

How can I make my ARIMA more accurate?

1- Check again the stationarity of the time series using augmented Dickey-Fuller (ADF) test. 2- Try to increase the number of predictors ( independent variables). 3- Try to increase the sample size (in case of monthly data, to use at least 4 years data.

How does ARIMA forecasting work?

ARIMA forecasting is achieved by plugging in time series data for the variable of interest. Statistical software will identify the appropriate number of lags or amount of differencing to be applied to the data and check for stationarity.


1 Answers

If I am right, I had the very similar problem: basically I wanted to split my time series into training and test set, train the model, and then predict arbitrarily any element of the test set given its past history. I did not manage to achieve it using the ARIMA statsmodels class though.

That's how I did it using statsmodels: I've applied a first order difference to the series to achieve stationarity, and computed an arma model:

model = sm.tsa.ARMA(fitting_data, order=(p, q), dates=fitting_dates).fit()

I've converted the arma model into a pure-ar one:

ar_params = model.arparams
ma_params = model.maparams

ar_coefficients = arma2ar(ar_params, ma_params, nobs=final_ar_coeff)

The nobs parameters influences the number of auto-regressive coefficients you will get. I tried several values, increasing it until no significant change in the predictions was observed. Once you get your predictions w.r.t. the differenced series, you want to bring back them to the original one. I implemented a method which, given one or a chain of predictions and the last known element before your forecasts, computes the predictions in the original series:

def differenced_series_to_original(values, starting_value):

    original_series = [starting_value]
    [original_series.append(original_series[-1]+i) for i in values]

    return original_series[1:]

Obviously values is the list of your predictions, starting_value the last known element. Hope it helps with your problem.

like image 140
riccamini Avatar answered Sep 20 '22 19:09

riccamini