import optuna
from mlforecast.optimization import mlforecast_objective
import mlforecast
from mlforecast.distributed.models.spark.lgb import SparkLGBMForecast
optuna.logging.set_verbosity(optuna.logging.WARNING)
objective = mlforecast_objective(
df=SparkDataFrame,
config_fn=config_fn,
loss=loss,
model=SparkLGBMForecast(),
freq='D',
n_windows=4,
h=7
)
study = optuna.create_study(
direction='minimize', sampler=optuna.samplers.TPESampler(seed=0)
)
study.optimize(objective, n_trials=2)
best_cfg = study.best_trial.user_attrs['config']