Data setup

import numpy as np
from mlforecast.utils import generate_daily_series
series = generate_daily_series(2)
series['weight'] = np.random.default_rng(seed=0).random(series.shape[0])
series.head(2)
unique_iddsyweight
0id_02000-01-010.3575950.636962
1id_02000-01-021.3013820.269787

Creating forecast object

import lightgbm as lgb
from sklearn.linear_model import LinearRegression

from mlforecast import MLForecast
fcst = MLForecast(
    models={
        'lr': LinearRegression(),
        'lgbm': lgb.LGBMRegressor(verbosity=-1),
    },
    freq='D',
    lags=[1],
    date_features=['dayofweek'],
)

Forecasting

You can provide the weight_col argument to MLForecast.fit to indicate which column should be used as the sample weights.

fcst.fit(series, weight_col='weight').predict(1)
unique_iddslrlgbm
0id_02000-08-103.3360195.283677
1id_12000-04-073.3007864.230655

Cross validation

You can provide the weight_col argument to MLForecast.cross_validation to indicate which column should be used as the sample weights.

fcst.cross_validation(series, n_windows=2, h=1, weight_col='weight')
unique_iddscutoffylrlgbm
0id_02000-08-082000-08-073.4363252.7707173.242790
1id_12000-04-052000-04-042.4302762.6879322.075247
2id_02000-08-092000-08-084.1367713.0951404.239010
3id_12000-04-062000-04-053.3635223.0166613.436962