4
votes

I am forecasting time series data using the ARIMA model. I have found the ARIMA model with the best fit using the following code:

def run_arima_model(df, ts, p,d,q):
from statsmodels.tsa.arima_model import ARIMA
model=ARIMA(df[ts], order=(p,d,q))
results_=model.fit(disp=-1)
len_results = len(results_.fittedvalues)
ts_modified = df[ts][-len_results:]

# calculate root mean square error (RMSE) and residual sum of squares (RSS)
rss = sum((results_.fittedvalues - ts_modified)**2)
rmse = np.sqrt(rss / len(df[ts]))

# plot fit
plt.plot(df[ts])
plt.plot(results_.fittedvalues, color = 'red')
plt.title('For ARIMA model (%i, %i, %i) for ts %s, RSS: %.4f, RMSE: %.4f' %(p, d, q, ts, rss, rmse))

plt.show()
plt.close()

return results_
model_AR = run_arima_model(df, 
                       ts = 'I', 
                       p = 1, 
                       d = 0, 
                       q = 0)

# MA model with 1st order differencing - ARIMA (0,0,1)
model_MA = run_arima_model(df, 
                       ts = 'I', 
                       p = 0, 
                       d = 0, 
                       q = 1)

# ARMA model with 1st order differencing - ARIMA (1,0,1)
model_MA = run_arima_model(df, 
                       ts = 'I', 
                       p = 1, 
                       d = 0, 
                       q = 1)

The ARIMA(1,0,1) is the best fit for my current data, how do I get it to forecast future points?

2

2 Answers

2
votes

The simplest way to do it:

model00 = ARIMA(np.array(dataframe.ix[:,4]), dates=None,order=(2,1,0))
model11 = model00.fit(disp=1)
model11.forecast()
model11.summary()

You will get your prediction plus:

enter image description here

2
votes

you can get the 3 future point using below code

 fcast<-forecast(fit,h=3)
 fcast<-data.frame(fcast)