Forecasting

ARIMA Models in Python

James Fulton

Climate informatics researcher

Predicting the next value

Take an AR(1) model

$y_t = a_1 y_{t-1} + \epsilon_t$

Predict next value

$y_t = 0.6\; \text{x} \; 10 + \epsilon_t$

$y_t = 6.0 + \epsilon_t$

Uncertainty on prediction

$ 5.0 < y_t < 7.0$

ARIMA Models in Python

One-step-ahead predictions

ARIMA Models in Python

Making one-step-ahead predictions

# Make predictions for last 25 values
results = model.fit()

# Make in-sample prediction forecast = results.get_prediction(start=-25)
ARIMA Models in Python

Making one-step-ahead predictions

# Make predictions for last 25 values
results = model.fit()

# Make in-sample prediction forecast = results.get_prediction(start=-25)
# forecast mean mean_forecast = forecast.predicted_mean

Predicted mean is a pandas series

2013-10-28    1.519368
2013-10-29    1.351082
2013-10-30    1.218016
ARIMA Models in Python

Confidence intervals

# Get confidence intervals of forecasts
confidence_intervals = forecast.conf_int()

Confidence interval method returns pandas DataFrame

                                 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
ARIMA Models in Python

Plotting predictions

plt.figure()

# Plot prediction
plt.plot(dates, 
         mean_forecast.values, 
         color='red', 
         label='forecast')

# Shade uncertainty area plt.fill_between(dates, lower_limits, upper_limits, color='pink') plt.show()
ARIMA Models in Python

Plotting predictions

ARIMA Models in Python

Dynamic predictions

ARIMA Models in Python

Making dynamic predictions

results = model.fit()
forecast = results.get_prediction(start=-25, dynamic=True)
# forecast mean
mean_forecast = forecast.predicted_mean

# Get confidence intervals of forecasts
confidence_intervals = forecast.conf_int()
ARIMA Models in Python

Forecasting out of sample

forecast = results.get_forecast(steps=20)
# forecast mean
mean_forecast = forecast.predicted_mean

# Get confidence intervals of forecasts
confidence_intervals = forecast.conf_int()
ARIMA Models in Python

Forecasting out of sample

forecast = results.get_forecast(steps=20)

ARIMA Models in Python

Let's practice!

ARIMA Models in Python

Preparing Video For Download...