Sarim Zafar
06/18/2024, 9:03 PMmy_init_config
function, as shown in the example on the website? When I use a simple log-difference combination as I typically do with Cross Validation, the loss function returns NaN. For the loss function, I am using MAE as described here:
def custom_loss(df, train_df): return mae(df, models=["model"])["model"].mean()
Any guidance on these matters would be greatly appreciated.
Thank you!José Morales
06/18/2024, 9:14 PMbest_config = auto_mlf.results_['AutoLightGBM'].best_trial.user_attrs['config']
my_lgb = LGBMRegressor(**best_config['model_params'])
my_mlf = MLForecast(models=my_lgb, freq=my_freq, **best_config['mlf_init_params'])
my_mlf.cross_validation(auto_settings like windows, h, refit)
How do you specify the log difference? As [GlobalSklearnTransformer(FunctionTransformer(np.log1p, np.expm1)), Differences(...)]
?Sarim Zafar
06/18/2024, 10:14 PMtarget_transforms=[GlobalSklearnTransformer(FunctionTransformer(func=np.log1p, inverse_func=np.expm1)),
Differences([season]),]
Sarim Zafar
06/18/2024, 10:17 PMJosé Morales
06/18/2024, 10:30 PMrefit=False
in the cross_validation call?Sarim Zafar
06/19/2024, 7:53 AMSarim Zafar
06/19/2024, 2:46 PMJosé Morales
06/19/2024, 2:54 PMSarim Zafar
06/19/2024, 2:56 PMSarim Zafar
06/19/2024, 2:56 PMJosé Morales
06/19/2024, 3:14 PMimport math
import lightgbm as lgb
from mlforecast import MLForecast
from mlforecast.auto import AutoMLForecast, AutoLightGBM
from mlforecast.utils import generate_series
from utilsforecast.losses import smape
series = generate_series(10, min_length=100)
auto = AutoMLForecast(
models={'lgb': AutoLightGBM()},
freq="D",
season_length=7,
)
auto.fit(series, n_windows=2, h=7, num_samples=5)
best_trial = auto.results_['lgb'].best_trial
auto_res = best_trial.value
best_config = best_trial.user_attrs['config']
mlf = MLForecast(
models={'lgb': lgb.LGBMRegressor(**best_config['model_params'])},
freq="D",
**best_config['mlf_init_params'],
)
cv_res = mlf.cross_validation(series, n_windows=2, h=7, refit=False)
cv_res['id_cutoff'] = cv_res['unique_id'].astype(str) + '_' + cv_res['cutoff'].astype(str)
manual_res = smape(cv_res, models=['lgb'], id_col='id_cutoff')['lgb'].mean()
assert math.isclose(auto_res, manual_res)
José Morales
06/19/2024, 3:16 PMSarim Zafar
06/19/2024, 3:16 PMSarim Zafar
06/19/2024, 3:59 PM