Introduction to ARIMA models

ARIMA Models in Python

James Fulton

Climate informatics researcher

Non-stationary time series recap

ARIMA Models in Python

Non-stationary time series recap

ARIMA Models in Python

Forecast of differenced time series

ARIMA Models in Python

Reconstructing original time series after differencing

diff_forecast = results.get_forecast(steps=10).predicted_mean

from numpy import cumsum
mean_forecast = cumsum(diff_forecast)
ARIMA Models in Python

Reconstructing original time series after differencing

diff_forecast = results.get_forecast(steps=10).predicted_mean

from numpy import cumsum
mean_forecast = cumsum(diff_forecast) + df.iloc[-1,0]
ARIMA Models in Python

Reconstructing original time series after differencing

ARIMA Models in Python

The ARIMA model

 

  • Take the difference
  • Fit ARMA model
  • Integrate forecast

Can we avoid doing so much work?

Yes!

ARIMA - Autoregressive Integrated Moving Average

ARIMA Models in Python

Using the ARIMA model

from statsmodels.tsa.arima.model import ARIMA

model = ARIMA(df, order=(p,d,q))
  • p - number of autoregressive lags
  • d - order of differencing
  • q - number of moving average lags

ARIMA$(p,0,q)$ = ARMA$(p,q)$

ARIMA Models in Python

Using the ARIMA model

# Create model
model = ARIMA(df, order=(2,1,1))

# Fit model model.fit()
# Make forecast mean_forecast = results.get_forecast(steps=10).predicted_mean
ARIMA Models in Python

Using the ARIMA model

# Make forecast
mean_forecast = results.get_forecast(steps=steps).predicted_mean

ARIMA Models in Python

Picking the difference order

adf = adfuller(df.iloc[:,0])
print('ADF Statistic:', adf[0])
print('p-value:', adf[1])
ADF Statistic: -2.674
p-value: 0.0784
adf = adfuller(df.diff().dropna().iloc[:,0])
print('ADF Statistic:', adf[0])
print('p-value:', adf[1])
ADF Statistic: -4.978
p-value: 2.44e-05
ARIMA Models in Python

Picking the difference order

model = ARIMA(df, order=(p,1,q))
ARIMA Models in Python

Let's practice!

ARIMA Models in Python

Preparing Video For Download...