module mlforecast.optimization


function mlforecast_objective

mlforecast_objective(
    df: Union[DataFrame, pl_DataFrame],
    config_fn: Callable[[Trial], Dict[str, Any]],
    loss: Callable,
    model: BaseEstimator,
    freq: Union[int, str],
    n_windows: int,
    h: int,
    step_size: Optional[int] = None,
    input_size: Optional[int] = None,
    refit: Union[bool, int] = False,
    id_col: str = 'unique_id',
    time_col: str = 'ds',
    target_col: str = 'y'
) → Callable[[Trial], float]
optuna objective function for the MLForecast class Args:
  • df (DataFrame): Series data in long format.
  • config_fn (callable): Function that takes an optuna trial and produces a configuration with the following keys:
    • model_params
    • mlf_init_params
    • mlf_fit_params
  • loss (callable): Function that takes the validation and train dataframes and produces a float.
  • model (BaseEstimator): scikit-learn compatible model to be trained
  • freq (str or int): pandas’ or polars’ offset alias or integer denoting the frequency of the series.
  • n_windows (int): Number of windows to evaluate.
  • h (int): Forecast horizon.
  • step_size (int, optional): Step size between each cross validation window. If None it will be equal to h. Defaults to None.
  • input_size (int, optional): Maximum training samples per serie in each window. If None, will use an expanding window. Defaults to None.
  • refit (bool or int): Retrain model for each cross validation window. If False, the models are trained at the beginning and then used to predict each window. If positive int, the models are retrained every refit windows. Defaults to False.
  • id_col (str): Column that identifies each serie. Defaults to ‘unique_id’.
  • time_col (str): Column that identifies each timestep, its values can be timestamps or integers. Defaults to ‘ds’.
  • target_col (str): Column that contains the target. Defaults to ‘y’.
Returns:
  • (Callable[[optuna.Trial], float]): optuna objective function