docstr: Facebook Prophet
  
  This class provides a basic wrapper around `Facebook Prophet <https://github.com/facebook/prophet>`_.
  It supports adding country holidays as well as custom seasonalities and adds support for stochastic
  forecasting and future covariates.
  
  Parameters
  ----------
  add_seasonalities
      Optionally, a dict or list of dicts with custom seasonality/ies to add to the model.
      Each dict takes the following mandatory and optional data:
  
      .. highlight:: python
      .. code-block:: python
  
          dict({
          'name': str  # (name of the seasonality component),
          'seasonal_periods': Union[int, float]  # (nr of steps composing a season),
          'fourier_order': int  # (number of Fourier components to use),
          'prior_scale': Optional[float]  # (a prior scale for this component),
          'mode': Optional[str]  # ('additive' or 'multiplicative')
          })
      ..
  
      An example for `seasonal_periods`: If you have hourly data (frequency='H') and your seasonal cycle repeats
      after 48 hours then set `seasonal_periods=48`. Notice that this value will be multiplied by the inferred
      number of days for the TimeSeries frequency (1 / 24 in this example) to be consistent with the
      `add_seasonality()` method of Facebook Prophet, where the `period` parameter is specified in days.
  
      Apart from `seasonal_periods`, this is very similar to how you would call Facebook Prophet's
      `add_seasonality()` method.
      Alternatively, you can add seasonalities after model creation and before fitting with
      :meth:`add_seasonality() <Prophet.add_seasonality()>`.
  country_holidays
      An optional country code, for which holidays can be taken into account by Prophet.
  
      See: https://github.com/dr-prodigy/python-holidays
  
      In addition to those countries, Prophet includes holidays for these
      countries: Brazil (BR), Indonesia (ID), India (IN), Malaysia (MY), Vietnam (VN),
      Thailand (TH), Philippines (PH), Turkey (TU), Pakistan (PK), Bangladesh (BD),
      Egypt (EG), China (CN), and Russia (RU).
  suppress_stdout_stderror
      Optionally suppress the log output produced by Prophet during training.
  add_encoders
      A large number of 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': {'future': ['relative']},
              'custom': {'future': [encode_year]},
              'transformer': Scaler(),
              'tz': 'CET'
          }
      ..
  cap
      Parameter specifiying the maximum carrying capacity when predicting with logistic growth.
      Mandatory when `growth = 'logistic'`, otherwise ignored.
      See <https://facebook.github.io/prophet/docs/saturating_forecasts.html> for more information
      on logistic forecasts.
      Can be either
  
      - a number, for constant carrying capacities
      - a function taking a DatetimeIndex or RangeIndex and returning a corresponding a Sequence of numbers,
      where each number indicates the carrying capacity at this index.
  floor
      Parameter specifiying the minimum carrying capacity when predicting logistic growth.
      Optional when `growth = 'logistic'` (defaults to 0), otherwise ignored.
      See <https://facebook.github.io/prophet/docs/saturating_forecasts.html> for more information
      on logistic forecasts.
      Can be either
  
      - a number, for constant carrying capacities
      - a function taking a DatetimeIndex or RangeIndex and returning a corresponding a Sequence of numbers,
      where each number indicates the carrying capacity at this index.
  prophet_kwargs
      Some optional keyword arguments for Prophet.
      For information about the parameters see:
      `The Prophet source code <https://github.com/facebook/prophet/blob/master/python/prophet/forecaster.py>`_.
  
  Examples
  --------
  >>> from darts.datasets import AirPassengersDataset
  >>> from darts.models import Prophet
  >>> from darts.utils.timeseries_generation import datetime_attribute_timeseries
  >>> series = AirPassengersDataset().load()
  >>> # optionally, use some future covariates; e.g. the value of the month encoded as a sine and cosine series
  >>> future_cov = datetime_attribute_timeseries(series, "month", cyclic=True, add_length=6)
  >>> # adding a seasonality (daily, weekly and yearly are included by default) and holidays
  >>> model = Prophet(
  >>>     add_seasonalities={
  >>>         'name':"quarterly_seasonality",
  >>>         'seasonal_periods':4,
  >>>         'fourier_order':5
  >>>         },
  >>> )
  >>> model.fit(series, future_covariates=future_cov)
  >>> pred = model.predict(6)
  >>> pred.values()
  array([[472.26891239],
         [467.56955721],
         [494.47230467],
         [493.10568429],
         [497.54686113],
         [539.11716811]])
docstr_tok: ["Facebook","Prophet","This","class","provides","a","basic","wrapper","around","`","Facebook","Prophet","<","https",":","\/\/github.com\/facebook\/prophet",">","`","_",".","It","supports","adding","country","holidays","as","well","as","custom","seasonalities","and","adds","support","for","stochastic","forecasting","and","future","covariates",".","Parameters","--","--","--","--","--","add_seasonalities","Optionally",",","a","dict","or","list","of","dicts","with","custom","seasonality\/ies","to","add","to","the","model",".","Each","dict","takes","the","following","mandatory","and","optional","data",":","..","highlight",":",":","python","..","code-block",":",":","python","dict","(","{","'name","'",":","str","#","(","name","of","the","seasonality","component",")",",","'seasonal_periods","'",":","Union","[","int",",","float","]","#","(","nr","of","steps","composing","a","season",")",",","'fourier_order","'",":","int","#","(","number","of","Fourier","components","to","use",")",",","'prior_scale","'",":","Optional","[","float","]","#","(","a","prior","scale","for","this","component",")",",","'mode","'",":","Optional","[","str","]","#","(","'additive","'","or","'multiplicative","'",")","}",")","..","An","example","for","`","seasonal_periods","`",":","If","you","have","hourly","data","(","frequency=","'","H","'",")","and","your","seasonal","cycle","repeats","after","48","hours","then","set","`","seasonal_periods=48","`",".","Notice","that","this","value","will","be","multiplied","by","the","inferred","number","of","days","for","the","TimeSeries","frequency","(","1","\/","24","in","this","example",")","to","be","consistent","with","the","`","add_seasonality","(",")","`","method","of","Facebook","Prophet",",","where","the","`","period","`","parameter","is","specified","in","days",".","Apart","from","`","seasonal_periods","`",",","this","is","very","similar","to","how","you","would","call","Facebook","Prophet's","`","add_seasonality","(",")","`","method",".","Alternatively",",","you","can","add","seasonalities","after","model","creation","and","before","fitting","with",":","meth",":","`","add_seasonality","(",")","<","Prophet.add_seasonality","(",")",">","`",".","country_holidays","An","optional","country","code",",","for","which","holidays","can","be","taken","into","account","by","Prophet",".","See",":","https",":","\/\/github.com\/dr-prodigy\/python-holidays","In","addition","to","those","countries",",","Prophet","includes","holidays","for","these","countries",":","Brazil","(","BR",")",",","Indonesia","(","ID",")",",","India","(","IN",")",",","Malaysia","(","MY",")",",","Vietnam","(","VN",")",",","Thailand","(","TH",")",",","Philippines","(","PH",")",",","Turkey","(","TU",")",",","Pakistan","(","PK",")",",","Bangladesh","(","BD",")",",","Egypt","(","EG",")",",","China","(","CN",")",",","and","Russia","(","RU",")",".","suppress_stdout_stderror","Optionally","suppress","the","log","output","produced","by","Prophet","during","training",".","add_encoders","A","large","number","of","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","'",":","{","'future","'",":","[","'relative","'","]","}",",","'custom","'",":","{","'future","'",":","[","encode_year","]","}",",","'transformer","'",":","Scaler","(",")",",","'tz","'",":","'CET'","}","..","cap","Parameter","specifiying","the","maximum","carrying","capacity","when","predicting","with","logistic","growth",".","Mandatory","when","`","growth","=","'logistic","'","`",",","otherwise","ignored",".","See","<","https",":","\/\/facebook.github.io\/prophet\/docs\/saturating_forecasts.html",">","for","more","information","on","logistic","forecasts",".","Can","be","either","-","a","number",",","for","constant","carrying","capacities","-","a","function","taking","a","DatetimeIndex","or","RangeIndex","and","returning","a","corresponding","a","Sequence","of","numbers",",","where","each","number","indicates","the","carrying","capacity","at","this","index",".","floor","Parameter","specifiying","the","minimum","carrying","capacity","when","predicting","logistic","growth",".","Optional","when","`","growth","=","'logistic","'","`","(","defaults","to","0",")",",","otherwise","ignored",".","See","<","https",":","\/\/facebook.github.io\/prophet\/docs\/saturating_forecasts.html",">","for","more","information","on","logistic","forecasts",".","Can","be","either","-","a","number",",","for","constant","carrying","capacities","-","a","function","taking","a","DatetimeIndex","or","RangeIndex","and","returning","a","corresponding","a","Sequence","of","numbers",",","where","each","number","indicates","the","carrying","capacity","at","this","index",".","prophet_kwargs","Some","optional","keyword","arguments","for","Prophet",".","For","information","about","the","parameters","see",":","`","The","Prophet","source","code","<","https",":","\/\/github.com\/facebook\/prophet\/blob\/master\/python\/prophet\/forecaster.py",">","`","_",".","Examples","--","--","--","--",">",">",">","from","darts.datasets","import","AirPassengersDataset",">",">",">","from","darts.models","import","Prophet",">",">",">","from","darts.utils.timeseries_generation","import","datetime_attribute_timeseries",">",">",">","series","=","AirPassengersDataset","(",")",".load","(",")",">",">",">","#","optionally",",","use","some","future","covariates",";","e.g",".","the","value","of","the","month","encoded","as","a","sine","and","cosine","series",">",">",">","future_cov","=","datetime_attribute_timeseries","(","series",",","``","month","''",",","cyclic=True",",","add_length=6",")",">",">",">","#","adding","a","seasonality","(","daily",",","weekly","and","yearly","are","included","by","default",")","and","holidays",">",">",">","model","=","Prophet","(",">",">",">","add_seasonalities=","{",">",">",">","'name","'",":","''","quarterly_seasonality","''",",",">",">",">","'seasonal_periods':4",",",">",">",">","'fourier_order':5",">",">",">","}",",",">",">",">",")",">",">",">","model.fit","(","series",",","future_covariates=future_cov",")",">",">",">","pred","=","model.predict","(","6",")",">",">",">","pred.values","(",")","array","(","[","[","472.26891239","]",",","[","467.56955721","]",",","[","494.47230467","]",",","[","493.10568429","]",",","[","497.54686113","]",",","[","539.11716811","]","]",")"]
code: def __init__(
      self,
      add_seasonalities: Optional[Union[dict, List[dict]]] = None,
      country_holidays: Optional[str] = None,
      suppress_stdout_stderror: bool = True,
      add_encoders: Optional[dict] = None,
      cap: Optional[
          Union[
              float,
              Callable[
                  [Union[pd.DatetimeIndex, pd.RangeIndex]],
                  Sequence[float],
              ],
          ]
      ] = None,
      floor: Optional[
          Union[
              float,
              Callable[
                  [Union[pd.DatetimeIndex, pd.RangeIndex]],
                  Sequence[float],
              ],
          ]
      ] = None,
      **prophet_kwargs,
  ):
      """Facebook Prophet
  
      This class provides a basic wrapper around `Facebook Prophet <https://github.com/facebook/prophet>`_.
      It supports adding country holidays as well as custom seasonalities and adds support for stochastic
      forecasting and future covariates.
  
      Parameters
      ----------
      add_seasonalities
          Optionally, a dict or list of dicts with custom seasonality/ies to add to the model.
          Each dict takes the following mandatory and optional data:
  
          .. highlight:: python
          .. code-block:: python
  
              dict({
              'name': str  # (name of the seasonality component),
              'seasonal_periods': Union[int, float]  # (nr of steps composing a season),
              'fourier_order': int  # (number of Fourier components to use),
              'prior_scale': Optional[float]  # (a prior scale for this component),
              'mode': Optional[str]  # ('additive' or 'multiplicative')
              })
          ..
  
          An example for `seasonal_periods`: If you have hourly data (frequency='H') and your seasonal cycle repeats
          after 48 hours then set `seasonal_periods=48`. Notice that this value will be multiplied by the inferred
          number of days for the TimeSeries frequency (1 / 24 in this example) to be consistent with the
          `add_seasonality()` method of Facebook Prophet, where the `period` parameter is specified in days.
  
          Apart from `seasonal_periods`, this is very similar to how you would call Facebook Prophet's
          `add_seasonality()` method.
          Alternatively, you can add seasonalities after model creation and before fitting with
          :meth:`add_seasonality() <Prophet.add_seasonality()>`.
      country_holidays
          An optional country code, for which holidays can be taken into account by Prophet.
  
          See: https://github.com/dr-prodigy/python-holidays
  
          In addition to those countries, Prophet includes holidays for these
          countries: Brazil (BR), Indonesia (ID), India (IN), Malaysia (MY), Vietnam (VN),
          Thailand (TH), Philippines (PH), Turkey (TU), Pakistan (PK), Bangladesh (BD),
          Egypt (EG), China (CN), and Russia (RU).
      suppress_stdout_stderror
          Optionally suppress the log output produced by Prophet during training.
      add_encoders
          A large number of 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': {'future': ['relative']},
                  'custom': {'future': [encode_year]},
                  'transformer': Scaler(),
                  'tz': 'CET'
              }
          ..
      cap
          Parameter specifiying the maximum carrying capacity when predicting with logistic growth.
          Mandatory when `growth = 'logistic'`, otherwise ignored.
          See <https://facebook.github.io/prophet/docs/saturating_forecasts.html> for more information
          on logistic forecasts.
          Can be either
  
          - a number, for constant carrying capacities
          - a function taking a DatetimeIndex or RangeIndex and returning a corresponding a Sequence of numbers,
          where each number indicates the carrying capacity at this index.
      floor
          Parameter specifiying the minimum carrying capacity when predicting logistic growth.
          Optional when `growth = 'logistic'` (defaults to 0), otherwise ignored.
          See <https://facebook.github.io/prophet/docs/saturating_forecasts.html> for more information
          on logistic forecasts.
          Can be either
  
          - a number, for constant carrying capacities
          - a function taking a DatetimeIndex or RangeIndex and returning a corresponding a Sequence of numbers,
          where each number indicates the carrying capacity at this index.
      prophet_kwargs
          Some optional keyword arguments for Prophet.
          For information about the parameters see:
          `The Prophet source code <https://github.com/facebook/prophet/blob/master/python/prophet/forecaster.py>`_.
  
      Examples
      --------
      >>> from darts.datasets import AirPassengersDataset
      >>> from darts.models import Prophet
      >>> from darts.utils.timeseries_generation import datetime_attribute_timeseries
      >>> series = AirPassengersDataset().load()
      >>> # optionally, use some future covariates; e.g. the value of the month encoded as a sine and cosine series
      >>> future_cov = datetime_attribute_timeseries(series, "month", cyclic=True, add_length=6)
      >>> # adding a seasonality (daily, weekly and yearly are included by default) and holidays
      >>> model = Prophet(
      >>>     add_seasonalities={
      >>>         'name':"quarterly_seasonality",
      >>>         'seasonal_periods':4,
      >>>         'fourier_order':5
      >>>         },
      >>> )
      >>> model.fit(series, future_covariates=future_cov)
      >>> pred = model.predict(6)
      >>> pred.values()
      array([[472.26891239],
             [467.56955721],
             [494.47230467],
             [493.10568429],
             [497.54686113],
             [539.11716811]])
      """
  
      super().__init__(add_encoders=add_encoders)
  
      self._auto_seasonalities = self._extract_auto_seasonality(
          prophet_kwargs
      )
  
      self._add_seasonalities = dict()
      add_seasonality_calls = (
          add_seasonalities
          if isinstance(add_seasonalities, list)
          else [add_seasonalities]
      )
      for call in add_seasonality_calls:
          self._store_add_seasonality_call(seasonality_call=call)
  
      self.country_holidays = country_holidays
      self.prophet_kwargs = prophet_kwargs
      self.model = None
      self.suppress_stdout_stderr = suppress_stdout_stderror
  
      self._execute_and_suppress_output = execute_and_suppress_output
      self._model_builder = prophet.Prophet
  
      self._cap = cap
      self._floor = floor
      self.is_logistic = (
          "growth" in prophet_kwargs
          and prophet_kwargs["growth"] == "logistic"
      )
      if not self.is_logistic and (
          cap is not None or floor is not None
      ):
          logger.warning(
              "Parameters `cap` and/or `floor` were set although `growth` is not "
              "logistic. The set capacities will be ignored."
          )
      if self.is_logistic:
          raise_if(
              cap is None,
              "Parameter `cap` has to be set when `growth` is logistic",
              logger,
          )
          if floor is None:
              # Use 0 as default value
              self._floor = 0
  
imports: import logging
  import re
  from typing import Callable, List, Optional, Sequence, Union
  import numpy
  import pandas
  import prophet
  from darts.logging import execute_and_suppress_output, get_logger, raise_if, raise_log
  from darts.models.forecasting.forecasting_model import FutureCovariatesLocalForecastingModel
  from darts.timeseries import TimeSeries
label_desc: Use image node_id 1 to create a new Prophet object from inherited base classes: FutureCovariatesLocalForecastingModel with example: obj = Prophet(add_seasonalities, country_holidays, suppress_stdout_stderror, add_encoders, cap, floor)