docstr: Extension of `RegressionModel` for regression models that support categorical covariates.
  
  Parameters
  ----------
  lags
      Lagged target values used to predict the next time step. If an integer is given the last `lags` past lags
      are used (from -1 backward). Otherwise, a list of integers with lags is required (each lag must be < 0).
  lags_past_covariates
      Number of lagged past_covariates values used to predict the next time step. If an integer is given the last
      `lags_past_covariates` past lags are used (inclusive, starting from lag -1). Otherwise a list of integers
      with lags < 0 is required.
  lags_future_covariates
      Number of lagged future_covariates values used to predict the next time step. If a tuple (past, future) is
      given the last `past` lags in the past are used (inclusive, starting from lag -1) along with the first
      `future` future lags (starting from 0 - the prediction time - up to `future - 1` included). Otherwise a list
      of integers with lags is required.
  output_chunk_length
      Number of time steps predicted at once (per chunk) by the internal model. It is not the same as forecast
      horizon `n` used in `predict()`, which is the desired number of prediction points generated using a
      one-shot- or auto-regressive forecast. Setting `n <= output_chunk_length` prevents auto-regression. This is
      useful when the covariates don't extend far enough into the future, or to prohibit the model from using
      future values of past and / or future covariates for prediction (depending on the model's covariate
      support).
  add_encoders
      A large number of past and future covariates can be automatically generated with `add_encoders`.
      This can be done by adding multiple pre-defined index encoders and/or custom user-made functions that
      will be used as index encoders. Additionally, a transformer such as Darts' :class:`Scaler` can be added to
      transform the generated covariates. This happens all under one hood and only needs to be specified at
      model creation.
      Read :meth:`SequentialEncoder <darts.dataprocessing.encoders.SequentialEncoder>` to find out more about
      ``add_encoders``. Default: ``None``. An example showing some of ``add_encoders`` features:
  
      .. highlight:: python
      .. code-block:: python
  
          def encode_year(idx):
              return (idx.year - 1950) / 50
  
          add_encoders={
              'cyclic': {'future': ['month']},
              'datetime_attribute': {'future': ['hour', 'dayofweek']},
              'position': {'past': ['relative'], 'future': ['relative']},
              'custom': {'past': [encode_year]},
              'transformer': Scaler(),
              'tz': 'CET'
          }
      ..
  model
      Scikit-learn-like model with ``fit()`` and ``predict()`` methods. Also possible to use model that doesn't
      support multi-output regression for multivariate timeseries, in which case one regressor
      will be used per component in the multivariate series.
      If None, defaults to: ``sklearn.linear_model.LinearRegression(n_jobs=-1)``.
  multi_models
      If True, a separate model will be trained for each future lag to predict. If False, a single model is
      trained to predict at step 'output_chunk_length' in the future. Default: True.
  use_static_covariates
      Whether the model should use static covariate information in case the input `series` passed to ``fit()``
      contain static covariates. If ``True``, and static covariates are available at fitting time, will enforce
      that all target `series` have the same static covariate dimensionality in ``fit()`` and ``predict()``.
  categorical_past_covariates
      Optionally, component name or list of component names specifying the past covariates that should be treated
      as categorical.
  categorical_future_covariates
      Optionally, component name or list of component names specifying the future covariates that should be
      treated as categorical.
  categorical_static_covariates
      Optionally, string or list of strings specifying the static covariates that should be treated as
      categorical.
docstr_tok: ["Extension","of","`","RegressionModel","`","for","regression","models","that","support","categorical","covariates",".","Parameters","--","--","--","--","--","lags","Lagged","target","values","used","to","predict","the","next","time","step",".","If","an","integer","is","given","the","last","`","lags","`","past","lags","are","used","(","from","-1","backward",")",".","Otherwise",",","a","list","of","integers","with","lags","is","required","(","each","lag","must","be","<","0",")",".","lags_past_covariates","Number","of","lagged","past_covariates","values","used","to","predict","the","next","time","step",".","If","an","integer","is","given","the","last","`","lags_past_covariates","`","past","lags","are","used","(","inclusive",",","starting","from","lag","-1",")",".","Otherwise","a","list","of","integers","with","lags","<","0","is","required",".","lags_future_covariates","Number","of","lagged","future_covariates","values","used","to","predict","the","next","time","step",".","If","a","tuple","(","past",",","future",")","is","given","the","last","`","past","`","lags","in","the","past","are","used","(","inclusive",",","starting","from","lag","-1",")","along","with","the","first","`","future","`","future","lags","(","starting","from","0","-","the","prediction","time","-","up","to","`","future","-","1","`","included",")",".","Otherwise","a","list","of","integers","with","lags","is","required",".","output_chunk_length","Number","of","time","steps","predicted","at","once","(","per","chunk",")","by","the","internal","model",".","It","is","not","the","same","as","forecast","horizon","`","n","`","used","in","`","predict","(",")","`",",","which","is","the","desired","number","of","prediction","points","generated","using","a","one-shot-","or","auto-regressive","forecast",".","Setting","`","n","<","=","output_chunk_length","`","prevents","auto-regression",".","This","is","useful","when","the","covariates","do","n't","extend","far","enough","into","the","future",",","or","to","prohibit","the","model","from","using","future","values","of","past","and","\/","or","future","covariates","for","prediction","(","depending","on","the","model","'s","covariate","support",")",".","add_encoders","A","large","number","of","past","and","future","covariates","can","be","automatically","generated","with","`","add_encoders","`",".","This","can","be","done","by","adding","multiple","pre-defined","index","encoders","and\/or","custom","user-made","functions","that","will","be","used","as","index","encoders",".","Additionally",",","a","transformer","such","as","Darts","'",":","class",":","`","Scaler","`","can","be","added","to","transform","the","generated","covariates",".","This","happens","all","under","one","hood","and","only","needs","to","be","specified","at","model","creation",".","Read",":","meth",":","`","SequentialEncoder","<","darts.dataprocessing.encoders.SequentialEncoder",">","`","to","find","out","more","about","``","add_encoders","``",".","Default",":","``","None","``",".","An","example","showing","some","of","``","add_encoders","``","features",":","..","highlight",":",":","python","..","code-block",":",":","python","def","encode_year","(","idx",")",":","return","(","idx.year","-","1950",")","\/","50","add_encoders=","{","'cyclic","'",":","{","'future","'",":","[","'month","'","]","}",",","'datetime_attribute","'",":","{","'future","'",":","[","'hour","'",",","'dayofweek","'","]","}",",","'position","'",":","{","'past","'",":","[","'relative","'","]",",","'future","'",":","[","'relative","'","]","}",",","'custom","'",":","{","'past","'",":","[","encode_year","]","}",",","'transformer","'",":","Scaler","(",")",",","'tz","'",":","'CET'","}","..","model","Scikit-learn-like","model","with","``","fit","(",")","``","and","``","predict","(",")","``","methods",".","Also","possible","to","use","model","that","doesn't","support","multi-output","regression","for","multivariate","timeseries",",","in","which","case","one","regressor","will","be","used","per","component","in","the","multivariate","series",".","If","None",",","defaults","to",":","``","sklearn.linear_model.LinearRegression","(","n_jobs=-1",")","``",".","multi_models","If","True",",","a","separate","model","will","be","trained","for","each","future","lag","to","predict",".","If","False",",","a","single","model","is","trained","to","predict","at","step","'output_chunk_length","'","in","the","future",".","Default",":","True",".","use_static_covariates","Whether","the","model","should","use","static","covariate","information","in","case","the","input","`","series","`","passed","to","``","fit","(",")","``","contain","static","covariates",".","If","``","True","``",",","and","static","covariates","are","available","at","fitting","time",",","will","enforce","that","all","target","`","series","`","have","the","same","static","covariate","dimensionality","in","``","fit","(",")","``","and","``","predict","(",")","``",".","categorical_past_covariates","Optionally",",","component","name","or","list","of","component","names","specifying","the","past","covariates","that","should","be","treated","as","categorical",".","categorical_future_covariates","Optionally",",","component","name","or","list","of","component","names","specifying","the","future","covariates","that","should","be","treated","as","categorical",".","categorical_static_covariates","Optionally",",","string","or","list","of","strings","specifying","the","static","covariates","that","should","be","treated","as","categorical","."]
code: def __init__(
      self,
      lags: Union[int, list] = None,
      lags_past_covariates: Union[int, List[int]] = None,
      lags_future_covariates: Union[Tuple[int, int], List[int]] = None,
      output_chunk_length: int = 1,
      add_encoders: Optional[dict] = None,
      model=None,
      multi_models: Optional[bool] = True,
      use_static_covariates: bool = True,
      categorical_past_covariates: Optional[
          Union[str, List[str]]
      ] = None,
      categorical_future_covariates: Optional[
          Union[str, List[str]]
      ] = None,
      categorical_static_covariates: Optional[
          Union[str, List[str]]
      ] = None,
  ):
      """
      Extension of `RegressionModel` for regression models that support categorical covariates.
  
      Parameters
      ----------
      lags
          Lagged target values used to predict the next time step. If an integer is given the last `lags` past lags
          are used (from -1 backward). Otherwise, a list of integers with lags is required (each lag must be < 0).
      lags_past_covariates
          Number of lagged past_covariates values used to predict the next time step. If an integer is given the last
          `lags_past_covariates` past lags are used (inclusive, starting from lag -1). Otherwise a list of integers
          with lags < 0 is required.
      lags_future_covariates
          Number of lagged future_covariates values used to predict the next time step. If a tuple (past, future) is
          given the last `past` lags in the past are used (inclusive, starting from lag -1) along with the first
          `future` future lags (starting from 0 - the prediction time - up to `future - 1` included). Otherwise a list
          of integers with lags is required.
      output_chunk_length
          Number of time steps predicted at once (per chunk) by the internal model. It is not the same as forecast
          horizon `n` used in `predict()`, which is the desired number of prediction points generated using a
          one-shot- or auto-regressive forecast. Setting `n <= output_chunk_length` prevents auto-regression. This is
          useful when the covariates don't extend far enough into the future, or to prohibit the model from using
          future values of past and / or future covariates for prediction (depending on the model's covariate
          support).
      add_encoders
          A large number of past and future covariates can be automatically generated with `add_encoders`.
          This can be done by adding multiple pre-defined index encoders and/or custom user-made functions that
          will be used as index encoders. Additionally, a transformer such as Darts' :class:`Scaler` can be added to
          transform the generated covariates. This happens all under one hood and only needs to be specified at
          model creation.
          Read :meth:`SequentialEncoder <darts.dataprocessing.encoders.SequentialEncoder>` to find out more about
          ``add_encoders``. Default: ``None``. An example showing some of ``add_encoders`` features:
  
          .. highlight:: python
          .. code-block:: python
  
              def encode_year(idx):
                  return (idx.year - 1950) / 50
  
              add_encoders={
                  'cyclic': {'future': ['month']},
                  'datetime_attribute': {'future': ['hour', 'dayofweek']},
                  'position': {'past': ['relative'], 'future': ['relative']},
                  'custom': {'past': [encode_year]},
                  'transformer': Scaler(),
                  'tz': 'CET'
              }
          ..
      model
          Scikit-learn-like model with ``fit()`` and ``predict()`` methods. Also possible to use model that doesn't
          support multi-output regression for multivariate timeseries, in which case one regressor
          will be used per component in the multivariate series.
          If None, defaults to: ``sklearn.linear_model.LinearRegression(n_jobs=-1)``.
      multi_models
          If True, a separate model will be trained for each future lag to predict. If False, a single model is
          trained to predict at step 'output_chunk_length' in the future. Default: True.
      use_static_covariates
          Whether the model should use static covariate information in case the input `series` passed to ``fit()``
          contain static covariates. If ``True``, and static covariates are available at fitting time, will enforce
          that all target `series` have the same static covariate dimensionality in ``fit()`` and ``predict()``.
      categorical_past_covariates
          Optionally, component name or list of component names specifying the past covariates that should be treated
          as categorical.
      categorical_future_covariates
          Optionally, component name or list of component names specifying the future covariates that should be
          treated as categorical.
      categorical_static_covariates
          Optionally, string or list of strings specifying the static covariates that should be treated as
          categorical.
      """
      super().__init__(
          lags=lags,
          lags_past_covariates=lags_past_covariates,
          lags_future_covariates=lags_future_covariates,
          output_chunk_length=output_chunk_length,
          add_encoders=add_encoders,
          model=model,
          multi_models=multi_models,
          use_static_covariates=use_static_covariates,
      )
      self.categorical_past_covariates = (
          [categorical_past_covariates]
          if isinstance(categorical_past_covariates, str)
          else categorical_past_covariates
      )
      self.categorical_future_covariates = (
          [categorical_future_covariates]
          if isinstance(categorical_future_covariates, str)
          else categorical_future_covariates
      )
      self.categorical_static_covariates = (
          [categorical_static_covariates]
          if isinstance(categorical_static_covariates, str)
          else categorical_static_covariates
      )
  
imports: from collections import OrderedDict
  from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
  import numpy
  import pandas
  from sklearn.linear_model import LinearRegression
  from darts.logging import get_logger, raise_if, raise_if_not, raise_log
  from darts.models.forecasting.forecasting_model import GlobalForecastingModel
  from darts.timeseries import TimeSeries
  from darts.utils.data.tabularization import add_static_covariates_to_lagged_data, create_lagged_component_names, create_lagged_training_data
  from darts.utils.historical_forecasts import _check_optimizable_historical_forecasts_global_models, _optimized_historical_forecasts_all_points, _optimized_historical_forecasts_last_points_only, _process_historical_forecast_input
  from darts.utils.multioutput import MultiOutputRegressor
  from darts.utils.utils import _check_quantiles, get_single_series, seq2series, series2seq
label_desc: Use image node_id 1 to create a new RegressionModelWithCategoricalCovariates object from inherited base classes: RegressionModel with example: obj = RegressionModelWithCategoricalCovariates(lags, lags_past_covariates, lags_future_covariates, output_chunk_length, add_encoders, model, multi_models, use_static_covariates, categorical_past_covariates, categorical_future_covariates, categorical_static_covariates)