module statsforecast.feature_engineering


function mstl_decomposition

mstl_decomposition(
    df: Union[DataFrame, DataFrame],
    model: MSTL,
    freq: str,
    h: int
) → Tuple[Union[DataFrame, DataFrame], Union[DataFrame, DataFrame]]
Decompose the series into trend and seasonal using the MSTL model. Args:
  • df (pandas or polars DataFrame): DataFrame with columns [unique_id, ds, y].
  • model (statsforecast MSTL): Model to use for the decomposition.
  • freq (str): Frequency of the data (pandas alias).
  • h (int): Forecast horizon.
Returns:
  • Tuple[DataFrame, DataFrame]: A tuple containing:
    • train_df (pandas or polars DataFrame): Original dataframe with the ‘trend’ and ‘seasonal’ columns added.
    • X_df (pandas or polars DataFrame): Future dataframe to be provided to the predict method through X_df.