Step-by-step guide on using the ARIMA Model
with Statsforecast
.
p
is the order of the Auto Regressive (AR) term. It refers to
the number of lags of Y to be used as predictors.p | order of the autoregressive part |
d | degree of first differencing involved |
q | order of the moving average part |
Model | p d q | Differenced | Method |
---|---|---|---|
Arima(0,0,0) | 0 0 0 | White noise | |
ARIMA (0,1,0) | 0 1 0 | Random walk | |
ARIMA (0,2,0) | 0 2 0 | Constant | |
ARIMA (1,0,0) | 1 0 0 | AR(1): AR(1): First-order regression model | |
ARIMA (2, 0, 0) | 2 0 0 | AR(2): Second-order regression model | |
ARIMA (1, 1, 0) | 1 1 0 | Differenced first-order | |
autoregressive model | |||
ARIMA (0, 1, 1) | 0 1 1 | Simple exponential | |
smoothing | |||
ARIMA (0, 0, 1) | 0 0 1 | MA(1): First-order | |
regression model | |||
ARIMA (0, 0, 2) | 0 0 2 | MA(2): Second-order | |
regression model | |||
ARIMA (1, 0, 1) | 1 0 1 | ARMA model | |
ARIMA (1, 1, 1) | 1 1 1 | ARIMA model | |
ARIMA (1, 1, 2) | 1 1 2 | Damped-trend linear Exponential smoothing | |
ARIMA (0, 2, 1) OR (0,2,2) | 0 2 1 | Linear exponential smoothing |
Tip Statsforecast will be needed. To install, see instructions.Next, we import plotting libraries and configure the plotting style.
year | value | |
---|---|---|
0 | 1960-01-01 | 69.123902 |
1 | 1961-01-01 | 69.760244 |
2 | 1962-01-01 | 69.149756 |
3 | 1963-01-01 | 69.248049 |
4 | 1964-01-01 | 70.311707 |
unique_id
(string, int or category) represents an identifier
for the series.
ds
(datestamp) column should be of a format expected by
Pandas, ideally YYYY-MM-DD for a date or YYYY-MM-DD HH:MM:SS for a
timestamp.
y
(numeric) represents the measurement we wish to forecast.
ds | y | unique_id | |
---|---|---|---|
0 | 1960-01-01 | 69.123902 | 1 |
1 | 1961-01-01 | 69.760244 | 1 |
2 | 1962-01-01 | 69.149756 | 1 |
3 | 1963-01-01 | 69.248049 | 1 |
4 | 1964-01-01 | 70.311707 | 1 |
ds
from the object
type to datetime.
ds | y | unique_id | y_diff | |
---|---|---|---|---|
1 | 1961-01-01 | 69.760244 | 1 | 0.636341 |
2 | 1962-01-01 | 69.149756 | 1 | -0.610488 |
3 | 1963-01-01 | 69.248049 | 1 | 0.098293 |
4 | 1964-01-01 | 70.311707 | 1 | 1.063659 |
5 | 1965-01-01 | 70.171707 | 1 | -0.140000 |
statsforecast
package.
The parameters found are: * For the autoregressive model, * for
the moving average model * and for the stationarity of the model
with a differential with an order
Therefore, the model that we are going to test is the ARIMA(1,1,1)
model.
unique_id | ds | ARIMA | |
---|---|---|---|
0 | 1 | 2020-01-01 | 83.206903 |
1 | 1 | 2021-01-01 | 83.203508 |
2 | 1 | 2022-01-01 | 83.204742 |
3 | 1 | 2023-01-01 | 83.204293 |
4 | 1 | 2024-01-01 | 83.204456 |
5 | 1 | 2025-01-01 | 83.204397 |
unique_id | ds | ARIMA | ARIMA-lo-95 | ARIMA-hi-95 | |
---|---|---|---|---|---|
0 | 1 | 2020-01-01 | 83.206903 | 82.412336 | 84.001469 |
1 | 1 | 2021-01-01 | 83.203508 | 82.094625 | 84.312391 |
2 | 1 | 2022-01-01 | 83.204742 | 81.848344 | 84.561139 |
3 | 1 | 2023-01-01 | 83.204293 | 81.640430 | 84.768156 |
4 | 1 | 2024-01-01 | 83.204456 | 81.457145 | 84.951767 |
5 | 1 | 2025-01-01 | 83.204397 | 81.291297 | 85.117497 |
unique_id | ds | ARIMA | ARIMA-lo-95 | ARIMA-hi-95 | |
---|---|---|---|---|---|
0 | 1 | 2020-01-01 | 83.206903 | 82.412336 | 84.001469 |
1 | 1 | 2021-01-01 | 83.203508 | 82.094625 | 84.312391 |
2 | 1 | 2022-01-01 | 83.204742 | 81.848344 | 84.561139 |
3 | 1 | 2023-01-01 | 83.204293 | 81.640430 | 84.768156 |
4 | 1 | 2024-01-01 | 83.204456 | 81.457145 | 84.951767 |
5 | 1 | 2025-01-01 | 83.204397 | 81.291297 | 85.117497 |
unique_id | metric | ARIMA | |
---|---|---|---|
0 | 1 | mse | 0.184000 |
1 | 1 | mae | 0.397932 |
2 | 1 | rmse | 0.428952 |
3 | 1 | mape | 0.004785 |