Docs /Templates/ sinapsis-darts-forecasting

GlobalNaiveSeasonalWrapper

sinapsis-darts-forecastingDartsdartsdynamicforecastingmodels

Python template · sinapsis_darts_forecasting.templates.time_series_model

Overview

Base Template for Darts Time Series forecasting models.

GlobalNaiveSeasonal — inherited documentation

The base class for "global" forecasting models, handling several time series and optional covariates.

Global forecasting models expand upon the functionality of `ForecastingModel` in 4 ways: 1. Models can be fitted on many series (multivariate or univariate) with different indices. 2. The input series used by :func:`predict()` can be different from the series used to fit the model. 3. Covariates can be supported (multivariate or univariate). 4. They can allow for multivariate target series and covariates.

The name "global" stems from the fact that a training set of a forecasting model of this class is not constrained to a temporally contiguous, "local", time series.

All implementations must implement the :func:`fit()` and :func:`predict()` methods. The :func:`fit()` method is meant to train the model on one or several training time series, along with optional covariates.

If :func:`fit()` has been called with only one training and covariate series as argument, then calling :func:`predict()` will forecast the future of this series. Otherwise, the user has to provide to :func:`predict()` the series they want to forecast, as well as covariates, if needed.Global Naive Seasonal Model.

The model generates forecasts for each `series` as described below:

- take the value from each target component at the `input_chunk_length`th point before the end of the target `series`. - the forecast is the component value repeated `output_chunk_length` times.

Depending on the horizon `n` used when calling `model.predict()`, the forecasts are either:

- a constant value if `n <= output_chunk_length`, or - a moving (seasonal) value if `n > output_chunk_length`, as a result of the autoregressive prediction.

This model is equivalent to:

- :class:`~darts.models.forecasting.baselines.NaiveSeasonal`, when `input_chunk_length` is equal to the length of the input target `series` and `output_chunk_length=1`.

.. note:: - Model checkpointing with `save_checkpoints=True`, and checkpoint loading with `load_from_checkpoint()` and `load_weights_from_checkpoint()` are not supported for global naive models.

Parameters ---------- input_chunk_length The length of the input sequence fed to the model. output_chunk_length The length of the emitted forecast and output sequence fed to the model. output_chunk_shift Optionally, the number of steps to shift the start of the output chunk into the future (relative to the input chunk end). This will create a gap between the input and output. If the model supports `future_covariates`, the future values are extracted from the shifted output chunk. Predictions will start `output_chunk_shift` steps after the end of the target `series`. If `output_chunk_shift` is set, the model cannot generate autoregressive predictions (`n > output_chunk_length`). **kwargs Optional arguments to initialize the pytorch_lightning.Module, pytorch_lightning.Trainer, and Darts' :class:`TorchForecastingModel`. Since naive models are not trained, the following parameters will have no effect: `loss_fn`, `likelihood`, `optimizer_cls`, `optimizer_kwargs`, `lr_scheduler_cls`, `lr_scheduler_kwargs`, `n_epochs`, `save_checkpoints`, and some of `pl_trainer_kwargs`.

Examples -------- >>> from darts.datasets import IceCreamHeaterDataset >>> from darts.models import GlobalNaiveSeasonal >>> # create list of multivariate series >>> series_1 = IceCreamHeaterDataset().load() >>> series_2 = series_1 + 100. >>> series = [series_1, series_2] >>> # predict 3 months, use value from 12 months ago >>> horizon, icl = 3, 12 >>> # repeated seasonal value (with `output_chunk_length = horizon`) >>> model = GlobalNaiveSeasonal(input_chunk_length=icl, output_chunk_length=horizon) >>> # predict after end of each multivariate series >>> pred = model.fit(series).predict(n=horizon, series=series) >>> [p.values() for p in pred] [array([[ 21., 100.], [ 21., 100.], [ 21., 100.]]), array([[121., 200.], [121., 200.], [121., 200.]])] >>> # moving seasonal value (with `output_chunk_length < horizon`) >>> model = GlobalNaiveSeasonal(input_chunk_length=icl, output_chunk_length=1) >>> pred = model.fit(series).predict(n=horizon, series=series) >>> [p.values() for p in pred] [array([[ 21., 100.], [ 21., 68.], [ 24., 51.]]), array([[121., 200.], [121., 168.], [124., 151.]])]

Capabilities

Capabilities: not set

Installation

Install the published package using pip or uv.

Terminalbash
pip install sinapsis-darts-forecasting==1.0.0
uv pip install sinapsis-darts-forecasting==1.0.0
uv add sinapsis-darts-forecasting==1.0.0

Configuration

Effective fields from the inspector schema, including nested Pydantic model fields.

metadata
sinapsis_core.template_base.base_models.TemplateMetadata | None
Optional
Default: null
validation_mode
bool
Optional
Default: false
forecast_horizon
int
Optional
Default: 10
globalnaiveseasonal_initRequired
BaseModel
Required
Default: null

Configuration example

Generated from documented defaults. Replace any placeholders and complete required nested settings before running.

yaml
templates:
  - template_name: "GlobalNaiveSeasonalWrapper"
    class_name: "GlobalNaiveSeasonalWrapper"
    attributes:
      validation_mode: false
      forecast_horizon: 10
      globalnaiveseasonal_init: {}
View original docstring example

The source example references XGBModelWrapper, not GlobalNaiveSeasonalWrapper.

yaml
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.html

Inheritance

Immediate parent: sinapsis_darts_forecasting.templates.time_series_model.TimeSeriesModel

Environment variables

Environment definitions belong to their canonical Python modules.

SINAPSIS_BUILD_DOCS · defined elsewhere