ARIMA Models in Python Chapter2
ARIMA Models in Python Chapter2
models
A RIMA MODELS IN P YTH ON
James Fulton
Climate informatics researcher
Creating a model
from statsmodels.tsa.arima_model import ARMA
results = model.fit()
print(results.summary())
==============================================================================
coef std err z P>|z| [0.025 0.975]
------------------------------------------------------------------------------
const -0.0017 0.012 -0.147 0.883 -0.025 0.021
ar.L1.y 0.5253 0.054 9.807 0.000 0.420 0.630
ar.L2.y -0.2909 0.042 -6.850 0.000 -0.374 -0.208
ma.L1.y 0.3679 0.052 7.100 0.000 0.266 0.469
Roots
=============================================================================
Real Imaginary Modulus Frequency
-----------------------------------------------------------------------------
AR.1 0.9029 -1.6194j 1.8541 -0.1690
AR.2 0.9029 +1.6194j 1.8541 0.1690
MA.1 -2.7184 +0.0000j 2.7184 0.5000
-----------------------------------------------------------------------------
ARMAX(1,1) model :
yt = x1 zt + a1 yt−1 + m1 ϵt−1 + ϵt
James Fulton
Climate informatics researcher
Predicting the next value
Take an AR(1) model
yt = a1 yt−1 + ϵt
yt = 0.6 x 10 + ϵt
yt = 6.0 + ϵt
Uncertainty on prediction
# forecast mean
mean_forecast = forecast.predicted_mean
2013-10-28 1.519368
2013-10-29 1.351082
2013-10-30 1.218016
lower y upper y
2013-09-28 -4.720471 -0.815384
2013-09-29 -5.069875 0.112505
2013-09-30 -5.232837 0.766300
2013-10-01 -5.305814 1.282935
2013-10-02 -5.326956 1.703974
# Plot prediction
plt.plot(dates,
mean_forecast.values,
color='red',
label='forecast')
plt.show()
# forecast mean
mean_forecast = forecast.predicted_mean
# forecast mean
mean_forecast = forecast.predicted_mean
James Fulton
Climate informatics researcher
Non-stationary time series recap
mean_forecast = cumsum(diff_forecast)
Integrate forecast
Yes!
d - order of differencing
ARMA(p, 0, q) = ARMA(p, q)
# Fit model
model.fit()
# Make forecast
mean_forecast = results.get_forecast(steps=10).predicted_mean
adf = adfuller(df.diff().dropna().iloc[:,0])
print('ADF Statistic:', adf[0])
print('p-value:', adf[1])