ARIMA in Python
Order (p, d, q), a fit, and a forecast with an interval.
import numpy as np
import pandas as pd
from statsmodels.tsa.arima.model import ARIMA
rng = np.random.default_rng(14)
values = np.zeros(200)
for i in range(1, 200):
values[i] = 0.6 * values[i - 1] + rng.normal()
series = pd.Series(values + 90)
model = ARIMA(series, order=(1, 0, 0)).fit()
print(model.params.round(4).to_dict())
print(round(model.aic, 2), round(model.bic, 2))
forecast = model.get_forecast(steps=3)
print(forecast.predicted_mean.round(2).tolist())
print(forecast.conf_int(alpha=0.05).round(2).to_numpy()[0])
How it works
dis how many times the series is differenced.get_forecastgives the interval,forecastonly the point.- AIC is what you compare when choosing an order.
Keywords and builtins used here
asforprintrangeround
The run, in numbers
- Lines
- 17
- Characters to type
- 525
- Tokens
- 178
- Three-star pace
- 115 tpm
At the three-star pace of 115 tokens a minute, this run takes about 93 seconds.
Step 4 of 6 in Time series, step 16 of 19 in Statistics with statsmodels.