Minimal example of MLForecast
Main concepts
The main component of mlforecast is theMLForecast class, which
abstracts away:
- Feature engineering and model training through
MLForecast.fit - Feature updates and multi step ahead predictions through
MLForecast.predict
Data format
The data is expected to be a pandas dataframe in long format, that is, each row represents an observation of a single series at a given time, with at least three columns:id_col: column that identifies each series.target_col: column that has the series values at each timestamp.time_col: column that contains the time the series value was observed. These are usually timestamps, but can also be consecutive integers.
unique_id column has the same value for all rows because this
is a single time series, you can have multiple time series by stacking
them together and having a column that differentiates them.
We also have the ds column that contains the timestamps, in this case
with a monthly frequency, and the y column that contains the series
values in each timestamp.
Modeling

mlforecast.target_transforms.Differences([1]) instance to
target_transforms.
We can then train a linear regression using the value from the same
month at the previous year (lag 12) as a feature, this is done by
passing lags=[12].
Forecasting
Compute the forecast for the next 12 monthsVisualize the results
We can visualize what our prediction looks like.

