ProphetWrapper
Python template · sinapsis_darts_forecasting.templates.time_series_model
Overview
Base Template for Darts Time Series forecasting models.
Prophet — inherited documentation
The base class for future covariates "local" forecasting models, handling single uni- or multivariate target and optional future covariates time series.
Future Covariates Local Forecasting Models (FC-LFM) are models that can be trained on a single uni- or multivariate target and optional future covariates series. In Darts, most models in this category tend to be simpler statistical models (such as ARIMA). FC-LFMs usually train on the entire target and future covariates series supplied when calling :func:`fit()` at once. They can also predict in one go with :func:`predict()` for any number of predictions `n` after the end of the training series. When using future covariates, the values for the future `n` prediction steps must be given in the covariate series.
All implementations must implement the :func:`_fit()` and :func:`_predict()` methods.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()>`. add_regressor_configs Optionally, a dictionary of configuration dictionaries for custom regressors / components of `future_covariates`. Each key is a regressor name, and the value is a dictionary of parameters for Prophet's `add_regressor()` method. Supported parameters are `prior_scale`, `standardize`, and `mode`. For example:
.. highlight:: python .. code-block:: python
add_regressor_configs={ 'temperature': {'prior_scale': 5.0, 'standardize': True, 'mode': 'additive'}, 'humidity': {'prior_scale': 2.0, 'standardize': 'auto', 'mode': 'multiplicative'}, 'pressure': {'prior_scale': 15.0} # uses defaults for other params } .. country_holidays An optional country code, for which holidays can be taken into account by Prophet. See `holidays package <https://holidays.readthedocs.io/en/latest/#available-countries>`__ for available country codes.
cap Parameter specifying 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 specifying 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. 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' } .. random_state Controls the randomness for reproducible forecasting. suppress_stdout_stderror Optionally suppress the log output produced by Prophet during training. 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) >>> print(pred.values()) [[472.26891239] [467.56955721] [494.47230467] [493.10568429] [497.54686113] [539.11716811]]
Capabilities
Capabilities: not setInstallation
Install the published package using pip or uv.
pip install sinapsis-darts-forecasting==1.0.0uv pip install sinapsis-darts-forecasting==1.0.0uv add sinapsis-darts-forecasting==1.0.0Configuration
Effective fields from the inspector schema, including nested Pydantic model fields.
Optional
Default: null
Required
Default: null
Optional
Default: false
Optional
Default: 10
Configuration example
Generated from documented defaults. Replace any placeholders and complete required nested settings before running.
templates:
- template_name: "ProphetWrapper"
class_name: "ProphetWrapper"
attributes:
prophet_init: {}
validation_mode: false
forecast_horizon: 10
View original docstring example
The source example references XGBModelWrapper, not ProphetWrapper.
agent:
name: my_test_agent
templates:
- template_name: InputTemplate
class_name: InputTemplate
attributes: {}
- template_name: XGBModelWrapper
class_name: XGBModelWrapper
template_input: InputTemplate
attributes:
forecast_horizon: 100
xgbmodel_init:
lags: 30
lags_past_covariates: 30
output_chunk_length: 100
random_state: 42
n_estimators: 200
learning_rate: 0.1
max_depth: 6
For a full list of options use the sinapsis cli: sinapsis info --all-template-names.
If you want to see all available models, please visit:
https://unit8co.github.io/darts/generated_api/darts.models.forecasting.htmlInheritance
sinapsis_darts_forecasting.templates.time_series_model.TimeSeriesModelEnvironment variables
Environment definitions belong to their canonical Python modules.