In this example, we’ll implement time series cross-validation to evaluate model’s performance.
Prerequesites
This tutorial assumes basic familiarity with
MLForecast
.
For a minimal example visit the Quick Start
Tip You can use Colab to run this Notebook interactively![]()
MLForecast
already installed. If not, check this guide for instructions on how to
install MLForecast.
Install the necessary packages with pip install mlforecast
.
pandas
.
unique_id | ds | y | |
---|---|---|---|
0 | H1 | 1 | 605.0 |
1 | H1 | 2 | 586.0 |
2 | H1 | 3 | 586.0 |
3 | H1 | 4 | 559.0 |
4 | H1 | 5 | 511.0 |
MLForecast
is a data frame in long
format with
three columns: unique_id
, ds
and y
:
unique_id
(string, int, or category) represents an identifier
for the series.ds
(datestamp or int) column should be either an integer
indexing time or a datestamp in format YYYY-MM-DD or YYYY-MM-DD
HH:MM:SS.y
(numeric) represents the measurement we wish to forecast.differences
and lags
to produce
features. See the full
documentation to see all available
features.
Any settings are passed into the constructor. Then you call its fit
method and pass in the historical data frame df
.
MLForecast
object has been instantiated, we can use the cross_validation
method.
For this particular example, we’ll use 3 windows of 24 hours.
unique_id
: identifies each time series.ds
: datestamp or temporal index.cutoff
: the last datestamp or temporal index for the n_windows
.y
: true value"model"
: columns with the model’s name and fitted value.unique_id | ds | cutoff | y | LGBMRegressor | |
---|---|---|---|---|---|
0 | H1 | 677 | 676 | 691.0 | 673.703191 |
1 | H1 | 678 | 676 | 618.0 | 552.306270 |
2 | H1 | 679 | 676 | 563.0 | 541.778027 |
3 | H1 | 680 | 676 | 529.0 | 502.778027 |
4 | H1 | 681 | 676 | 504.0 | 480.778027 |
y
before said period.
utilsforecast
, a Python library developed by Nixtla
that includes a function to compute the RMSE.