Minimal example of MLForecast
MLForecast
class, which abstracts away:
MLForecast.fit
MLForecast.predict
id_col
: column that identifies each serie.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 | ds | y | |
---|---|---|---|
0 | AirPassengers | 1949-01-01 | 112 |
1 | AirPassengers | 1949-02-01 | 118 |
2 | AirPassengers | 1949-03-01 | 132 |
3 | AirPassengers | 1949-04-01 | 129 |
4 | AirPassengers | 1949-05-01 | 121 |
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.
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]
.
unique_id | ds | LinearRegression | |
---|---|---|---|
0 | AirPassengers | 1961-01-01 | 444.656555 |
1 | AirPassengers | 1961-02-01 | 417.470734 |
2 | AirPassengers | 1961-03-01 | 446.903046 |
3 | AirPassengers | 1961-04-01 | 491.014130 |
4 | AirPassengers | 1961-05-01 | 502.622223 |
5 | AirPassengers | 1961-06-01 | 568.751465 |
6 | AirPassengers | 1961-07-01 | 660.044312 |
7 | AirPassengers | 1961-08-01 | 643.343323 |
8 | AirPassengers | 1961-09-01 | 540.666687 |
9 | AirPassengers | 1961-10-01 | 491.462708 |
10 | AirPassengers | 1961-11-01 | 417.095154 |
11 | AirPassengers | 1961-12-01 | 461.206238 |