Reputation: 5031
I am new to Python. I am using statsmodels for predicting through ARIMA. I have 3 questions. First of all, I am writing the following code
dates = pd.date_range('2012-07-09','2012-07-30')
series = [43.,32.,63.,98.,65.,78.,23.,35.,78.,56.,45.,45.,56.,6.,63.,45.,64.,34.,76.,34.,14.,54.]
res = Series(series, index=dates)
r = ARIMA(res,(1,2,0))
pred = r.predict(params = ? , start = ?, end = ? , typ='levels')
Here, what would be the params, start and end ? In the documentation I understood that start and end means the start and end of the predicting values but what about params. I do not know what i have to put in params.
Secondly, I have almost 1000 time series of items. So, for each item i want to recognize optimal (p,d,q) values and apply ARIMA each time in a loop so that at the end I get the result in a dictionary containing item name and its predicted value.Please help me how can do this ?
Third, Now If I am able to get ARIMA forecast for each time series it will not be just a forecast, instead it will contain lots of values like coeff, p-values, etc so how can I directly access the coeffients only and use them somewhere as values.
I'll be extremely thankful If someone can help me out in this. Many Thanks in advance.
Upvotes: 2
Views: 2486
Reputation: 1
# -*- coding: utf-8 -*-
import pandas as pd
from statsmodels.tsa.arima_model import ARIMA
import warnings
warnings.filterwarnings('ignore')
dates = pd.date_range('2012-07-09','2012-07-19')
series = [20,22,25,30,40,50,65,88,112,120,115]
res = pd.Series(series, index=dates)
print(res)
r = ARIMA(res,(2,1,0))
model_fit = r.fit(disp=0)
print(model_fit.summary())
pred = model_fit.predict(start ='2012-07-20', end ='2012-07-20', typ='levels')
print(pred)
Upvotes: 0
Reputation: 1515
Start and end are the starting and ending points you wish to forecast. So this might be start = '2012-07-31'
and end = '2012-09-01'
.
Regarding params
- when .fit()
is called, an ARIMAResults class is returned. This class' predict
method does not require the params
argument: start
and end
should be all that's needed.
For your second question, this answer should help. I was not actually able to get that code to work for myself, but I'm sure you could get a AIC/BIC grid search to work in that or a similar way. An alternative would be switching to R and using the auto.arima
function, which also selects the best (p,d,q) order based on AIC/BIC (which is definitely more advisable than selecting based on p-values).
You should be able to get the coefficients from your fitted model using r.params
Upvotes: 1