Docs /Templates/ sinapsis-darts-forecasting

FFTWrapper

sinapsis-darts-forecastingDartsdartsdynamicforecastingmodels

Python template · sinapsis_darts_forecasting.templates.time_series_model

Overview

Base Template for Darts Time Series forecasting models.

FFT — inherited documentation

The base class for "local" forecasting models, handling only single univariate time series.

Local Forecasting Models (LFM) are models that can be trained on a single univariate target series only. In Darts, most models in this category tend to be simpler statistical models (such as ETS or FFT). LFMs usually train on the entire target 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.

All implementations must implement the `fit()` and `predict()` methods.Fast Fourier Transform Model

This model performs forecasting on a TimeSeries instance using FFT, subsequent frequency filtering (controlled by the `nr_freqs_to_keep` argument) and inverse FFT, combined with the option to detrend the data (controlled by the `trend` argument) and to crop the training sequence to full seasonal periods Note that if the training series contains any NaNs (missing values), these will be filled using :func:`darts.utils.missing_values.fill_missing_values()`.

Parameters ---------- nr_freqs_to_keep The total number of frequencies that will be used for forecasting. required_matches The attributes of pd.Timestamp that will be used to create a training sequence that is cropped at the beginning such that the first timestamp of the training sequence and the first prediction point have matching phases. If the series has a yearly seasonality, include `month`, if it has a monthly seasonality, include `day`, etc. If not set, or explicitly set to None, the model tries to find the pd.Timestamp attributes that are relevant for the seasonality automatically. trend If set, indicates what kind of detrending will be applied before performing DFT. Possible values: 'poly', 'exp' or None, for polynomial trend, exponential trend or no trend, respectively. trend_poly_degree The degree of the polynomial that will be used for detrending, if `trend='poly'`.

Examples -------- Automatically detect the seasonal periods, uses the 10 most significant frequencies for forecasting and expect no global trend to be present in the data:

>>> FFT(nr_freqs_to_keep=10)

Assume the provided TimeSeries instances will have a monthly seasonality and an exponential global trend, and do not perform any frequency filtering:

>>> FFT(required_matches={'month'}, trend='exp')

Simple usage example, using one of the dataset available in darts

>>> from darts.datasets import AirPassengersDataset >>> from darts.models import FFT >>> series = AirPassengersDataset().load() >>> # increase the number of frequency and use a polynomial trend of degree 2 >>> model = FFT( >>> nr_freqs_to_keep=20, >>> trend= "poly", >>> trend_poly_degree=2 >>> ) >>> model.fit(series) >>> pred = model.predict(6) >>> print(pred.values()) [[471.79323146] [494.6381425 ] [504.5659999 ] [515.82463265] [520.59404623] [547.26720705]]

.. note:: `FFT example notebook <https://unit8co.github.io/darts/examples/03-FFT-examples.html>`__ presents techniques that can be used to improve the forecasts quality compared to this simple usage example.

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.

fft_initRequired
__init__Attributes
Required
Default: null
trend
typing.Optional[str]
Optional
Default: null
nr_freqs_to_keep
typing.Optional[int]
Optional
Default: 10
required_matches
typing.Optional[set]
Optional
Default: null
trend_poly_degree
int
Optional
Default: 3
metadata
sinapsis_core.template_base.base_models.TemplateMetadata | None
Optional
Default: null
validation_mode
bool
Optional
Default: false
forecast_horizon
int
Optional
Default: 10

Configuration example

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

yaml
templates:
  - template_name: "FFTWrapper"
    class_name: "FFTWrapper"
    attributes:
      fft_init:
        trend: null
        nr_freqs_to_keep: 10
        required_matches: null
        trend_poly_degree: 3
      validation_mode: false
      forecast_horizon: 10
View original docstring example

The source example references XGBModelWrapper, not FFTWrapper.

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