docstr: This mixer is a wrapper around the popular time series library sktime. It exhibits different behavior compared
  to other forecasting mixers, as it predicts based on indices in a forecasting horizon that is defined with
  respect to the last seen data point at training time.
  
  Due to this, the mixer tries to "fit_on_all" so that the latest point in the validation split marks the 
  difference between training data and where forecasts will start. In practice, you need to specify how much 
  time has passed since the aforementioned timestamp for correct forecasts. By default, it is assumed that
   predictions are for the very next timestamp post-training.
  
  If the task has groups (i.e. 'TimeseriesSettings.group_by' is not empty), the mixer will spawn one forecaster 
  object per each different group observed at training time, plus an additional default forecaster fit with all data.
  
  There is an optuna-based automatic hyperparameter search. For now, it considers selecting the forecaster type
  based on the global SMAPE error across all groups.
  
  :param stop_after: time budget in seconds.
  :param target: column to forecast.
  :param dtype_dict: dtypes of all columns in the data.
  :param horizon: length of forecasted horizon.
  :param sp: seasonality period to enforce (instead of automatic inference done at the `ts_analysis` module)
  :param ts_analysis: dictionary with miscellaneous time series info, as generated by 'lightwood.data.timeseries_analyzer'.
  :param model_path: sktime forecaster to use as underlying model(s). Should be a string with format "$module.$class' where '$module' is inside `sktime.forecasting`. Default is 'arima.AutoARIMA'.
  :param model_kwargs: specifies additional paramters to pass to the model if model_path is provided. 
  :param hyperparam_search: bool that indicates whether to perform the hyperparameter tuning or not.
  :param auto_size: whether to filter out old data points if training split is bigger than a certain threshold (defined by the dataset sampling frequency). Enabled by default to avoid long training times in big datasets.
  :param use_stl: Whether to use de-trenders and de-seasonalizers fitted in the timeseries analysis phase.
docstr_tok: ["This","mixer","is","a","wrapper","around","the","popular","time","series","library","sktime",".","It","exhibits","different","behavior","compared","to","other","forecasting","mixers",",","as","it","predicts","based","on","indices","in","a","forecasting","horizon","that","is","defined","with","respect","to","the","last","seen","data","point","at","training","time",".","Due","to","this",",","the","mixer","tries","to","``","fit_on_all","''","so","that","the","latest","point","in","the","validation","split","marks","the","difference","between","training","data","and","where","forecasts","will","start",".","In","practice",",","you","need","to","specify","how","much","time","has","passed","since","the","aforementioned","timestamp","for","correct","forecasts",".","By","default",",","it","is","assumed","that","predictions","are","for","the","very","next","timestamp","post-training",".","If","the","task","has","groups","(","i.e",".","'TimeseriesSettings.group_by","'","is","not","empty",")",",","the","mixer","will","spawn","one","forecaster","object","per","each","different","group","observed","at","training","time",",","plus","an","additional","default","forecaster","fit","with","all","data",".","There","is","an","optuna-based","automatic","hyperparameter","search",".","For","now",",","it","considers","selecting","the","forecaster","type","based","on","the","global","SMAPE","error","across","all","groups",".",":","param","stop_after",":","time","budget","in","seconds",".",":","param","target",":","column","to","forecast",".",":","param","dtype_dict",":","dtypes","of","all","columns","in","the","data",".",":","param","horizon",":","length","of","forecasted","horizon",".",":","param","sp",":","seasonality","period","to","enforce","(","instead","of","automatic","inference","done","at","the","`","ts_analysis","`","module",")",":","param","ts_analysis",":","dictionary","with","miscellaneous","time","series","info",",","as","generated","by","'lightwood.data.timeseries_analyzer","'",".",":","param","model_path",":","sktime","forecaster","to","use","as","underlying","model","(","s",")",".","Should","be","a","string","with","format","``","$","module.","$","class","'","where","'","$","module","'","is","inside","`","sktime.forecasting","`",".","Default","is","'arima.AutoARIMA","'",".",":","param","model_kwargs",":","specifies","additional","paramters","to","pass","to","the","model","if","model_path","is","provided",".",":","param","hyperparam_search",":","bool","that","indicates","whether","to","perform","the","hyperparameter","tuning","or","not",".",":","param","auto_size",":","whether","to","filter","out","old","data","points","if","training","split","is","bigger","than","a","certain","threshold","(","defined","by","the","dataset","sampling","frequency",")",".","Enabled","by","default","to","avoid","long","training","times","in","big","datasets",".",":","param","use_stl",":","Whether","to","use","de-trenders","and","de-seasonalizers","fitted","in","the","timeseries","analysis","phase","."]
code: def __init__(
      self,
      stop_after: float,
      target: str,
      dtype_dict: Dict[str, str],
      horizon: int,
      ts_analysis: Dict,
      model_path: str = None,
      model_kwargs: Optional[dict] = None,
      auto_size: bool = True,
      sp: int = None,
      hyperparam_search: bool = True,
      use_stl: bool = False,
  ):
      """
      This mixer is a wrapper around the popular time series library sktime. It exhibits different behavior compared
      to other forecasting mixers, as it predicts based on indices in a forecasting horizon that is defined with
      respect to the last seen data point at training time.
  
      Due to this, the mixer tries to "fit_on_all" so that the latest point in the validation split marks the
      difference between training data and where forecasts will start. In practice, you need to specify how much
      time has passed since the aforementioned timestamp for correct forecasts. By default, it is assumed that
       predictions are for the very next timestamp post-training.
  
      If the task has groups (i.e. 'TimeseriesSettings.group_by' is not empty), the mixer will spawn one forecaster
      object per each different group observed at training time, plus an additional default forecaster fit with all data.
  
      There is an optuna-based automatic hyperparameter search. For now, it considers selecting the forecaster type
      based on the global SMAPE error across all groups.
  
      :param stop_after: time budget in seconds.
      :param target: column to forecast.
      :param dtype_dict: dtypes of all columns in the data.
      :param horizon: length of forecasted horizon.
      :param sp: seasonality period to enforce (instead of automatic inference done at the `ts_analysis` module)
      :param ts_analysis: dictionary with miscellaneous time series info, as generated by 'lightwood.data.timeseries_analyzer'.
      :param model_path: sktime forecaster to use as underlying model(s). Should be a string with format "$module.$class' where '$module' is inside `sktime.forecasting`. Default is 'arima.AutoARIMA'.
      :param model_kwargs: specifies additional paramters to pass to the model if model_path is provided.
      :param hyperparam_search: bool that indicates whether to perform the hyperparameter tuning or not.
      :param auto_size: whether to filter out old data points if training split is bigger than a certain threshold (defined by the dataset sampling frequency). Enabled by default to avoid long training times in big datasets.
      :param use_stl: Whether to use de-trenders and de-seasonalizers fitted in the timeseries analysis phase.
      """  # noqa
      super().__init__(stop_after)
      self.stable = False
      self.prepared = False
      self.supports_proba = False
      self.target = target
      self.name = "AutoSKTime"
  
      default_possible_models = [
          "croston.Croston",
          "theta.ThetaForecaster",
          "trend.STLForecaster",
          "trend.PolynomialTrendForecaster",
      ]
  
      self.dtype_dict = dtype_dict
      self.ts_analysis = ts_analysis
      self.horizon = horizon
      self.sp = sp
      self.grouped_by = (
          ["__default"]
          if not ts_analysis["tss"].group_by
          else ts_analysis["tss"].group_by
      )
      self.auto_size = auto_size
      self.cutoff_factor = (
          4  # times the detected maximum seasonal period
      )
      self.use_stl = use_stl
  
      # optuna hyperparameter tuning
      self.models = {}
      self.cutoffs = {}  # last seen timestamp per each model
      self.study = None
      self.hyperparam_dict = {}
      self.model_path = (
          model_path if model_path else "trend.STLForecaster"
      )
      self.model_kwargs = model_kwargs if model_kwargs else {}
      self.hyperparam_search = hyperparam_search
      self.trial_error_fn = MeanAbsolutePercentageError(symmetric=True)
      self.possible_models = (
          default_possible_models if not model_path else [model_path]
      )
      self.n_trials = len(self.possible_models)
      self.freq = self._get_freq(
          self.ts_analysis["deltas"]["__default"]
      )
  
      # sktime forecast horizon object is made relative to the end of the latest data point seen at training time
      # the default assumption is to forecast the next `self.horizon` after said data point
      self.fh = ForecastingHorizon(
          np.arange(1, self.horizon + 1), is_relative=True
      )
  
imports: import importlib
  from copy import deepcopy
  from datetime import datetime
  from typing import Dict, Union, Optional
  import optuna
  import numpy
  import pandas
  from sktime.forecasting.compose import TransformedTargetForecaster
  from sktime.forecasting.base import ForecastingHorizon, BaseForecaster
  from sktime.performance_metrics.forecasting import MeanAbsolutePercentageError
  from sktime.forecasting.statsforecast import StatsForecastAutoARIMA
  from lightwood.helpers.log import log
  from lightwood.helpers.templating import _add_cls_kwarg
  from lightwood.mixer.base import BaseMixer
  from lightwood.api.types import PredictionArguments
  from lightwood.data.encoded_ds import EncodedDs, ConcatedEncodedDs
label_desc: Use image node_id 1 to create a new SkTime object from inherited base classes: BaseMixer with example: obj = SkTime(stop_after, target, dtype_dict, horizon, ts_analysis, model_path, model_kwargs, auto_size, sp, hyperparam_search, use_stl)