FittableDataTransformerWrapper
Python template · sinapsis_darts_forecasting.templates.time_series_preprocessing
Overview
A dynamic preprocessing template for applying Darts transformations to time series data.
This template allows users to apply various transformations from `darts.dataprocessing.transformers` to different parts of the time series packet (`content`, `past_covariates`, `future_covariates`).
If a transformer requires fitting (e.g., `Scaler`), it stores and retrieves transformation parameters.
FittableDataTransformer — inherited documentation
Helper class that provides a standard way to create an ABC using inheritance.Base class for fittable transformers.
All the deriving classes have to implement the static methods :func:`ts_transform()` and :func:`ts_fit()`. The fitting and transformation functions must be passed during the transformer's initialization. This class takes care of parallelizing operations involving multiple ``TimeSeries`` when possible.
Parameters ---------- name The data transformer's name n_jobs The number of jobs to run in parallel. Parallel jobs are created only when a `Sequence[TimeSeries]` is passed as input to a method, parallelising operations regarding different `TimeSeries`. Defaults to `1` (sequential). Setting the parameter to `-1` means using all the available processors. Note: for a small amount of data, the parallelisation overhead could end up increasing the total required amount of time. verbose Optionally, whether to print operations progress parallel_params Optionally, specifies which fixed parameters (i.e. the attributes initialized in the child-most class's `__init__`) take on different values for different parallel jobs. Fixed parameters specified by `parallel_params` are assumed to be a `Sequence` of values that should be used for that parameter in each parallel job; the length of this `Sequence` should equal the number of parallel jobs. If `parallel_params=True`, every fixed parameter will take on a different value for each parallel job. If `parallel_params=False`, every fixed parameter will take on the same value for each parallel job. If `parallel_params` is a `Sequence` of fixed attribute names, only those attribute names specified will take on different values between different parallel jobs. mask_components Optionally, whether to automatically apply any provided `component_mask`s to the `TimeSeries` inputs passed to `transform`, `fit`, `inverse_transform`, or `fit_transform`. If `True`, any specified `component_mask` will be applied to each input timeseries before passing them to the called method; the masked components will also be automatically 'unmasked' in the returned `TimeSeries`. If `False`, then `component_mask` (if provided) will be passed as a keyword argument, but won't automatically be applied to the input timeseries. See `apply_component_mask` method of `BaseDataTransformer` for further details. global_fit Optionally, whether all `TimeSeries` passed to the `fit()` method should be used to fit a *single* set of parameters, or if a different set of parameters should be independently fitted to each provided `TimeSeries`. If `True`, then a `Sequence[TimeSeries]` is passed to `ts_fit` and a single set of parameters is fitted using all provided `TimeSeries`. If `False`, then each `TimeSeries` is individually passed to `ts_fit`, and a different set of fitted parameters if yielded for each of these fitting operations. See `ts_fit` for further details.
Notes ----- If `global_fit` is `False` and `fit` is called with a `Sequence` containing `n` different `TimeSeries`, then `n` sets of parameters will be fitted. When `transform` and/or `inverse_transform` is subsequently called with a `Series[TimeSeries]`, the `i`th set of fitted parameter values will be passed to `ts_transform`/`ts_inverse_transform` to transform the `i`th `TimeSeries` in this sequence. Conversely, if `global_fit` is `True`, then only a single set of fitted values will be produced when `fit` is provided with a `Sequence[TimeSeries]`. Consequently, if a `Sequence[TimeSeries]` is then passed to `transform`/`inverse_transform`, each of these `TimeSeries` will be transformed using the exact same set of fitted parameters.
Note that if an invertible *and* fittable data transformer is to be globally fitted, the data transformer class should first inherit from `FittableDataTransformer` and then from `InvertibleDataTransformer`. In other words, `MyTransformer(FittableDataTransformer, InvertibleDataTransformer)` is correct, but `MyTransformer(InvertibleDataTransformer, FittableDataTransformer)` is **not**. If this is not implemented correctly, then the `global_fit` parameter will not be correctly passed to `FittableDataTransformer`'s constructor.
The :func:`ts_transform()` and :func:`ts_fit()` methods are designed to be static methods instead of instance methods to allow an efficient parallelisation also when the scaler instance is storing a non-negligible amount of data. Using instance methods would imply copying the instance's data through multiple processes, which can easily introduce a bottleneck and nullify parallelisation benefits.
Example -------- >>> from darts.dataprocessing.transformers import FittableDataTransformer >>> from darts.utils.timeseries_generation import linear_timeseries >>> >>> class SimpleRangeScaler(FittableDataTransformer): >>> >>> def __init__(self, scale, position): >>> self._scale = scale >>> self._position = position >>> super().__init__() >>> >>> @staticmethod >>> def ts_transform(series, params): >>> vals = series.all_values(copy=False) >>> fit_params = params['fitted'] >>> unit_scale = (vals - fit_params['position'])/fit_params['scale'] >>> fix_params = params['fixed'] >>> rescaled = fix_params['_scale'] * unit_scale + fix_params['_position'] >>> return series.from_values(rescaled) >>> >>> @staticmethod >>> def ts_fit(series, params): >>> vals = series.all_values(copy=False) >>> scale = vals.max() - vals.min() >>> position = vals[0] >>> return {'scale': scale, 'position': position} >>> >>> series = linear_timeseries(length=5, start_value=1, end_value=5) >>> print(series.values()) [[1.] [2.] [3.] [4.] [5.]] >>> series = SimpleRangeScaler(scale=2, position=-1).fit_transform(series) >>> print(series.values()) [[-1. ] [-0.5] [ 0. ] [ 0.5] [ 1. ]]
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.
Required
Default: null
Required
Default: null
Optional
Default: null
Optional
Default: null
Optional
Default: null
Required
Default: null
Optional
Default: "FittableDataTransformer"
Optional
Default: 1
Optional
Default: false
Optional
Default: false
Optional
Default: true
Optional
Default: false
Configuration example
Generated from documented defaults. Replace any placeholders and complete required nested settings before running.
templates:
- template_name: "FittableDataTransformerWrapper"
class_name: "FittableDataTransformerWrapper"
attributes:
method: "<required>"
apply_to: "<required>"
params_key: null
transform_kwargs: null
fittabledatatransformer_init:
name: "FittableDataTransformer"
n_jobs: 1
verbose: false
global_fit: false
mask_components: true
parallel_params: false
View original docstring example
The source example references MissingValuesFillerWrapper, not FittableDataTransformerWrapper.
agent:
name: my_test_agent
templates:
- template_name: InputTemplate
class_name: InputTemplate
attributes: {}
- template_name: MissingValuesFillerWrapper
class_name: MissingValuesFillerWrapper
template_input: InputTemplate
attributes:
method: "transform"
apply_to: ["content"]
transform_kwargs:
method: "linear"
missingvaluesfiller_init:
fill: "auto"
name: "MissingValuesFiller"
n_jobs: 1
verbose: False
For a full list of options use the sinapsis cli: sinapsis info --all-template-names
If you want to see all available transformers, please visit: https://unit8co.github.io/darts/generated_api/darts.dataprocessing.transformers.htmlInheritance
sinapsis_darts_forecasting.templates.time_series_preprocessing.TimeSeriesPreprocessorEnvironment variables
Environment definitions belong to their canonical Python modules.