Step-by-step guide on using the ADIDA Model
with Statsforecast
.
Tip Statsforecast will be needed. To install, see instructions.Next, we import plotting libraries and configure the plotting style.
semanas | malaria_falciparum | |
---|---|---|
0 | 2007-12-31 | 50.0 |
1 | 2008-01-07 | 62.0 |
2 | 2008-01-14 | 76.0 |
3 | 2008-01-21 | 64.0 |
4 | 2008-01-28 | 38.0 |
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 | 2007-12-31 | 50.0 | 1 |
1 | 2008-01-07 | 62.0 | 1 |
2 | 2008-01-14 | 76.0 | 1 |
3 | 2008-01-21 | 64.0 | 1 |
4 | 2008-01-28 | 38.0 | 1 |
object
types to datetime and numeric.
ADIDA Model
. 2.
Data to test our model
For the test data we will use the last 25 week to test and evaluate the
performance of our model.
ADIDA Model
with StatsForecast ADIDA Model
, they are listed below. For more information, visit the
documentation.
season_length
.
StatsForecast
object with the following parameters:
models: a list of models. Select the models you want from models and
import them.
freq:
a string indicating the frequency of the data. (See pandas’
available
frequencies.)
n_jobs:
n_jobs: int, number of jobs used in the parallel
processing, use -1 for all cores.
fallback_model:
a model to be used if a model fails.
fit()
method to fit the model.
ADIDA Model
. We can observe it with the
following instruction:
StatsForecast.forecast
method instead of .fit
and .predict
.
The main difference is that the forecast()
method does not store the
fitted values and is highly scalable in distributed environments.
The forecast method takes two arguments: forecasts next h
(horizon)
and level
.
h (int):
represents the forecast h steps into the future. In this
case, 25 week ahead.unique_id | ds | ADIDA | |
---|---|---|---|
0 | 1 | 2022-07-11 | 336.747375 |
1 | 1 | 2022-07-18 | 336.747375 |
2 | 1 | 2022-07-25 | 336.747375 |
… | … | … | … |
22 | 1 | 2022-12-12 | 336.747375 |
23 | 1 | 2022-12-19 | 336.747375 |
24 | 1 | 2022-12-26 | 336.747375 |
h
(for
horizon) and level
.
h (int):
represents the forecast h steps into the future. In this
case, 25 week ahead.unique_id | ds | ADIDA | |
---|---|---|---|
0 | 1 | 2022-07-11 | 336.747375 |
1 | 1 | 2022-07-18 | 336.747375 |
2 | 1 | 2022-07-25 | 336.747375 |
3 | 1 | 2022-08-01 | 336.747375 |
4 | 1 | 2022-08-08 | 336.747375 |
(n_windows=)
, forecasting every second months
(step_size=12)
. Depending on your computer, this step should take
around 1 min.
The cross_validation method from the StatsForecast class takes the
following arguments.
df:
training data frame
h (int):
represents h steps into the future that are being
forecasted. In this case, 12 months ahead.
step_size (int):
step size between each window. In other words:
how often do you want to run the forecasting processes.
n_windows(int):
number of windows used for cross validation. In
other words: what number of forecasting processes in the past do you
want to evaluate.
unique_id:
series identifierds:
datestamp or temporal indexcutoff:
the last datestamp or temporal index for the n_windows
.y:
true valuemodel:
columns with the model’s name and fitted value.unique_id | ds | cutoff | y | ADIDA | |
---|---|---|---|---|---|
0 | 1 | 2020-03-23 | 2020-03-16 | 317.0 | 251.901505 |
1 | 1 | 2020-03-30 | 2020-03-16 | 332.0 | 251.901505 |
2 | 1 | 2020-04-06 | 2020-03-16 | 306.0 | 251.901505 |
… | … | … | … | … | … |
122 | 1 | 2022-12-12 | 2022-07-04 | 151.0 | 336.747375 |
123 | 1 | 2022-12-19 | 2022-07-04 | 97.0 | 336.747375 |
124 | 1 | 2022-12-26 | 2022-07-04 | 42.0 | 336.747375 |
unique_id | metric | ADIDA | |
---|---|---|---|
0 | 1 | mae | 114.527585 |
1 | 1 | mape | 0.820029 |
2 | 1 | mase | 0.874115 |
3 | 1 | rmse | 129.749320 |
4 | 1 | smape | 0.221878 |