Time Axes Encoders

Encoders can generate past and/or future covariates series by encoding the index of a TimeSeries series. Each encoder class has methods encode_train(), encode_inference(), and encode_train_inference() to generate the encodings for training and inference.

The encoders extract the index either from the target series or optional additional past/future covariates. If additional covariates are supplied to encode_train(), encode_inference(), or encode_train_inference(), the time index of those covariates are used for the encodings. This means that the input covariates must meet the same model-specific requirements as without encoders.

There are two main types of encoder classes: SingleEncoder and SequentialEncoder.

  • SingleEncoder

    The SingleEncoder classes carry the encoder logic for past and future covariates, and training and inference datasets. They can be used as stand-alone encoders.

    Each SingleEncoder has a dedicated subclass for generating past or future covariates. The naming convention is {X}{SingleEncoder} where {X} is one of (Past, Future) and {SingleEncoder} is one of the SingleEncoder classes described in the next section. An example:

    encoder = PastDatetimeAttributeEncoder(
        input_chunk_length=24,
        output_chunk_length=12,
        attribute='month'
        tz='CET'
    )
    
    past_covariates_train = encoder.encode_train(
        target=target,
        covariates=optional_past_covariates
    )
    past_covariates_inf = encoder.encode_inference(
        n=12,
        target=target,
        covariates=optional_past_covariates
    )
    # or generate encodings for train and inference together
    past_covariates_train_inf = encoder.encode_train_inference(
        n=12,
        target=target,
        covariates=optional_past_covariates
    )
    
  • SequentialEncoder

    Stores and controls multiple SingleEncoders for both past and/or future covariates all under one hood. It provides the same functionality as SingleEncoders (encode_train(), encode_inference(), and encode_train_inference()). It can be used both as stand-alone or as an all-in-one solution with Darts’ forecasting models that support covariates through optional parameter add_encoders:

    model = SomeForecastingModel(..., add_encoders={...})
    

    If used at model creation, the SequentialEncoder will handle all past and future encoders autonomously. The requirements for model parameter add_encoders are described in the next section or in SequentialEncoder.

SingleEncoder

The SingleEncoders from {X}{SingleEncoder} are:

  • DatetimeAttributeEncoder

    Adds scalar pd.DatatimeIndex attribute information derived from series.time_index. Requires series to have a pd.DatetimeIndex.

    attribute

    An attribute of pd.DatetimeIndex: see all available attributes in https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DatetimeIndex.html#pandas.DatetimeIndex.

    tz

    Optionally, convert the time zone naive index to a time zone tz before applying the encoder.

  • CyclicTemporalEncoder

    Adds cyclic pd.DatetimeIndex attribute information deriveed from series.time_index. Adds 2 columns, corresponding to sin and cos encodings, to uniquely describe the underlying attribute. Requires series to have a pd.DatetimeIndex.

    attribute

    An attribute of pd.DatetimeIndex that follows a cyclic pattern. One of (‘month’, ‘day’, ‘weekday’, ‘dayofweek’, ‘day_of_week’, ‘hour’, ‘minute’, ‘second’, ‘microsecond’, ‘nanosecond’, ‘quarter’, ‘dayofyear’, ‘day_of_year’, ‘week’, ‘weekofyear’, ‘week_of_year’).

    tz

    Optionally, convert the time zone naive index to a time zone tz before applying the encoder.

  • IntegerIndexEncoder

    Adds the relative index positions as integer values (positions) derived from series time index. series can either have a pd.DatetimeIndex or an integer index.

    attribute

    Currently, only ‘relative’ is supported. ‘relative’ will generate position values relative to the forecasting/prediction point. Values range from -inf to inf where 0 is set at the forecasting point.

  • CallableIndexEncoder

    Applies a user-defined callable to encode series’ index. series can either have a pd.DatetimeIndex or an integer index.

    attribute

    a callable/function to encode the index. For series with a pd.DatetimeIndex: lambda index: (index.year - 1950) / 50. For series with an integer index: lambda index: index / 50

SequentialEncoder

The SequentialEncoder combines the logic of all SingleEncoders from above and has additional benefits:

  • use multiple encoders at once

  • generate multiple attribute encodings at once

  • generate both past and future at once

  • supports transformers (Scaler)

  • easy to use with any forecasting model that supports covariates.

The model parameter add_encoders must be a Dict following of this convention:

  • outer keys: SingleEncoder and Transformer tags:

    • ‘datetime_attribute’ for DatetimeAttributeEncoder

    • ‘cyclic’ for CyclicEncoder

    • ‘position’ for IntegerIndexEncoder

    • ‘custom’ for CallableIndexEncoder

    • ‘transformer’ for a transformer

    • ‘tz’ for applying a time zone conversion

  • inner keys: covariates type

    • ‘past’ for past covariates

    • ‘future’ for future covariates

    • (do not specify for ‘transformer’)

  • inner key values:

    • list of attributes for SingleEncoder

    • transformer object for ‘transformer’

Below is an example that illustrates a valid add_encoders dict for hourly data and how it can be used with a TorchForecastingModel (this is only meant to illustrate many features at once).

add_encoders = {
    'cyclic': {'future': ['month']},
    'datetime_attribute': {'future': ['hour', 'dayofweek']},
    'position': {'past': ['relative'], 'future': ['relative']},
    'custom': {'past': [lambda idx: (idx.year - 1950) / 50]},
    'transformer': Scaler(),
    'tz': 'CET',
}

model = SomeTorchForecastingModel(..., add_encoders=add_encoders)
class darts.dataprocessing.encoders.encoders.CallableIndexEncoder(index_generator, attribute)[source]

Bases: SingleEncoder

CallableIndexEncoder: Applies a user-defined callable to encode the underlying index for past and future covariates.

Attributes

accept_transformer

CallableIndexEncoder accepts transformations.

base_component_name

Returns the base encoder base component name.

components

Returns the encoded component names.

encoding_n_components

The number of components in the SingleEncoder output.

fit_called

Returns whether the Encoder object has been fitted.

requires_fit

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Methods

encode_inference(n, target[, covariates, ...])

Returns encoded index for inference/prediction.

encode_train(target[, covariates, ...])

Returns encoded index for training.

encode_train_inference(n, target[, ...])

Returns encoded index for inference/prediction.

Parameters
  • index_generator (CovariatesIndexGenerator) – An instance of CovariatesIndexGenerator with methods generate_train_idx() and generate_inference_idx(). Used to generate the index for encoders.

  • attribute (Callable) – A callable that takes an index index of type (pd.DatetimeIndex, pd.RangeIndex) as input and returns a np.ndarray of shape (len(index),). An example for a correct attribute for index of type pd.DatetimeIndex: attribute = lambda index: (index.year - 1950) / 50. And for pd.RangeIndex: attribute = lambda index: (index - 1950) / 50

Attributes

accept_transformer

CallableIndexEncoder accepts transformations.

base_component_name

Returns the base encoder base component name.

components

Returns the encoded component names.

encoding_n_components

The number of components in the SingleEncoder output.

fit_called

Returns whether the Encoder object has been fitted.

requires_fit

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Methods

encode_inference(n, target[, covariates, ...])

Returns encoded index for inference/prediction.

encode_train(target[, covariates, ...])

Returns encoded index for training.

encode_train_inference(n, target[, ...])

Returns encoded index for inference/prediction.

property accept_transformer: List[bool]

CallableIndexEncoder accepts transformations.

Return type

List[bool]

property base_component_name: str

Returns the base encoder base component name. The string follows the given format: “darts_enc_{covariates_temp}_{encoder}_{attribute}”, where the elements are:

  • covariates_temp: “pc” or “fc” for past, or future covariates respectively.

  • encoder: the SingleEncoder type used:
    • “cyc” (cyclic temporal encoder),

    • “dta” (datetime attribute encoder),

    • “pos” (positional integer index encoder),

    • “cus” (custom callable index encoder)

  • attribute: the attribute used for the underlying encoder. Some examples:
    • “month_sin”, “month_cos” (for “cyc”)

    • “month” (for “dta”)

    • “relative” (for “pos”)

    • “custom” (for “cus”)

Return type

str

property components: Index

Returns the encoded component names. Only available after Encoder.encode_train() or Encoder.encode_inference() have been called.

Return type

Index

encode_inference(n, target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for inference/prediction.

Parameters
  • n (int) – The forecast horizon

  • target (TimeSeries) – The target TimeSeries used during training or passed to prediction as series

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for prediction: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

encode_train(target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for training.

Parameters
  • target (TimeSeries) – The target TimeSeries used during training or passed to prediction as series

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for training: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

encode_train_inference(n, target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for inference/prediction.

Parameters
  • n (int) – The forecast horizon

  • target (TimeSeries) – The target TimeSeries used during training and prediction.

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for training and prediction: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

property encoding_n_components: int

The number of components in the SingleEncoder output.

Return type

int

property fit_called: bool

Returns whether the Encoder object has been fitted.

Return type

bool

property requires_fit: bool

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Return type

bool

class darts.dataprocessing.encoders.encoders.CyclicTemporalEncoder(index_generator, attribute, tz=None)[source]

Bases: SingleEncoder

CyclicTemporalEncoder: Cyclic encoding of time series datetime attributes.

Attributes

accept_transformer

CyclicTemporalEncoder should not be transformed.

base_component_name

Returns the base encoder base component name.

components

Returns the encoded component names.

encoding_n_components

The number of components in the SingleEncoder output.

fit_called

Returns whether the Encoder object has been fitted.

requires_fit

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Methods

encode_inference(n, target[, covariates, ...])

Returns encoded index for inference/prediction.

encode_train(target[, covariates, ...])

Returns encoded index for training.

encode_train_inference(n, target[, ...])

Returns encoded index for inference/prediction.

Cyclic index encoding for TimeSeries that have a time index of type pd.DatetimeIndex.

Parameters

Attributes

accept_transformer

CyclicTemporalEncoder should not be transformed.

base_component_name

Returns the base encoder base component name.

components

Returns the encoded component names.

encoding_n_components

The number of components in the SingleEncoder output.

fit_called

Returns whether the Encoder object has been fitted.

requires_fit

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Methods

encode_inference(n, target[, covariates, ...])

Returns encoded index for inference/prediction.

encode_train(target[, covariates, ...])

Returns encoded index for training.

encode_train_inference(n, target[, ...])

Returns encoded index for inference/prediction.

property accept_transformer: List[bool]

CyclicTemporalEncoder should not be transformed. Returns two elements for sine and cosine waves.

Return type

List[bool]

property base_component_name: str

Returns the base encoder base component name. The string follows the given format: “darts_enc_{covariates_temp}_{encoder}_{attribute}”, where the elements are:

  • covariates_temp: “pc” or “fc” for past, or future covariates respectively.

  • encoder: the SingleEncoder type used:
    • “cyc” (cyclic temporal encoder),

    • “dta” (datetime attribute encoder),

    • “pos” (positional integer index encoder),

    • “cus” (custom callable index encoder)

  • attribute: the attribute used for the underlying encoder. Some examples:
    • “month_sin”, “month_cos” (for “cyc”)

    • “month” (for “dta”)

    • “relative” (for “pos”)

    • “custom” (for “cus”)

Return type

str

property components: Index

Returns the encoded component names. Only available after Encoder.encode_train() or Encoder.encode_inference() have been called.

Return type

Index

encode_inference(n, target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for inference/prediction.

Parameters
  • n (int) – The forecast horizon

  • target (TimeSeries) – The target TimeSeries used during training or passed to prediction as series

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for prediction: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

encode_train(target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for training.

Parameters
  • target (TimeSeries) – The target TimeSeries used during training or passed to prediction as series

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for training: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

encode_train_inference(n, target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for inference/prediction.

Parameters
  • n (int) – The forecast horizon

  • target (TimeSeries) – The target TimeSeries used during training and prediction.

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for training and prediction: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

property encoding_n_components: int

The number of components in the SingleEncoder output.

Return type

int

property fit_called: bool

Returns whether the Encoder object has been fitted.

Return type

bool

property requires_fit: bool

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Return type

bool

class darts.dataprocessing.encoders.encoders.DatetimeAttributeEncoder(index_generator, attribute, tz=None)[source]

Bases: SingleEncoder

DatetimeAttributeEncoder: Adds pd.DatatimeIndex attribute information derived from the index as scalars. Requires the underlying TimeSeries to have a pd.DatetimeIndex

Attributes

accept_transformer

DatetimeAttributeEncoder accepts transformations

base_component_name

Returns the base encoder base component name.

components

Returns the encoded component names.

encoding_n_components

The number of components in the SingleEncoder output.

fit_called

Returns whether the Encoder object has been fitted.

requires_fit

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Methods

encode_inference(n, target[, covariates, ...])

Returns encoded index for inference/prediction.

encode_train(target[, covariates, ...])

Returns encoded index for training.

encode_train_inference(n, target[, ...])

Returns encoded index for inference/prediction.

Parameters

Attributes

accept_transformer

DatetimeAttributeEncoder accepts transformations

base_component_name

Returns the base encoder base component name.

components

Returns the encoded component names.

encoding_n_components

The number of components in the SingleEncoder output.

fit_called

Returns whether the Encoder object has been fitted.

requires_fit

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Methods

encode_inference(n, target[, covariates, ...])

Returns encoded index for inference/prediction.

encode_train(target[, covariates, ...])

Returns encoded index for training.

encode_train_inference(n, target[, ...])

Returns encoded index for inference/prediction.

property accept_transformer: List[bool]

DatetimeAttributeEncoder accepts transformations

Return type

List[bool]

property base_component_name: str

Returns the base encoder base component name. The string follows the given format: “darts_enc_{covariates_temp}_{encoder}_{attribute}”, where the elements are:

  • covariates_temp: “pc” or “fc” for past, or future covariates respectively.

  • encoder: the SingleEncoder type used:
    • “cyc” (cyclic temporal encoder),

    • “dta” (datetime attribute encoder),

    • “pos” (positional integer index encoder),

    • “cus” (custom callable index encoder)

  • attribute: the attribute used for the underlying encoder. Some examples:
    • “month_sin”, “month_cos” (for “cyc”)

    • “month” (for “dta”)

    • “relative” (for “pos”)

    • “custom” (for “cus”)

Return type

str

property components: Index

Returns the encoded component names. Only available after Encoder.encode_train() or Encoder.encode_inference() have been called.

Return type

Index

encode_inference(n, target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for inference/prediction.

Parameters
  • n (int) – The forecast horizon

  • target (TimeSeries) – The target TimeSeries used during training or passed to prediction as series

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for prediction: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

encode_train(target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for training.

Parameters
  • target (TimeSeries) – The target TimeSeries used during training or passed to prediction as series

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for training: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

encode_train_inference(n, target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for inference/prediction.

Parameters
  • n (int) – The forecast horizon

  • target (TimeSeries) – The target TimeSeries used during training and prediction.

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for training and prediction: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

property encoding_n_components: int

The number of components in the SingleEncoder output.

Return type

int

property fit_called: bool

Returns whether the Encoder object has been fitted.

Return type

bool

property requires_fit: bool

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Return type

bool

class darts.dataprocessing.encoders.encoders.FutureCallableIndexEncoder(attribute, input_chunk_length=None, output_chunk_length=None, lags_covariates=None, **kwargs)[source]

Bases: CallableIndexEncoder

IntegerIndexEncoder: Adds integer index value (position) for future covariates derived from the underlying TimeSeries’ time index.

Attributes

accept_transformer

CallableIndexEncoder accepts transformations.

base_component_name

Returns the base encoder base component name.

components

Returns the encoded component names.

encoding_n_components

The number of components in the SingleEncoder output.

fit_called

Returns whether the Encoder object has been fitted.

requires_fit

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Methods

encode_inference(n, target[, covariates, ...])

Returns encoded index for inference/prediction.

encode_train(target[, covariates, ...])

Returns encoded index for training.

encode_train_inference(n, target[, ...])

Returns encoded index for inference/prediction.

Parameters
  • attribute (Callable) – A callable that takes an index index of type (pd.DatetimeIndex, pd.RangeIndex) as input and returns a np.ndarray of shape (len(index),). An example for a correct attribute for index of type pd.DatetimeIndex: attribute = lambda index: (index.year - 1950) / 50. And for pd.RangeIndex: attribute = lambda index: (index - 1950) / 50

  • input_chunk_length (Optional[int]) – Optionally, the number of input target time steps per chunk. Only required for TorchForecastingModel, and RegressionModel. Corresponds to parameter input_chunk_length from TorchForecastingModel, or to the absolute minimum target lag value abs(min(lags)) for RegressionModel.

  • output_chunk_length (Optional[int]) – Optionally, the number of output target time steps per chunk. Only required for TorchForecastingModel, and RegressionModel. Corresponds to parameter output_chunk_length from both TorchForecastingModel, and RegressionModel.

  • lags_covariates (Optional[List[int]]) – Optionally, a list of integers representing the future covariate lags. Accepts all integer values. Only required for RegressionModel. Corresponds to the lag values from parameter lags_future_covariates from RegressionModel.

Attributes

accept_transformer

CallableIndexEncoder accepts transformations.

base_component_name

Returns the base encoder base component name.

components

Returns the encoded component names.

encoding_n_components

The number of components in the SingleEncoder output.

fit_called

Returns whether the Encoder object has been fitted.

requires_fit

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Methods

encode_inference(n, target[, covariates, ...])

Returns encoded index for inference/prediction.

encode_train(target[, covariates, ...])

Returns encoded index for training.

encode_train_inference(n, target[, ...])

Returns encoded index for inference/prediction.

property accept_transformer: List[bool]

CallableIndexEncoder accepts transformations.

Return type

List[bool]

property base_component_name: str

Returns the base encoder base component name. The string follows the given format: “darts_enc_{covariates_temp}_{encoder}_{attribute}”, where the elements are:

  • covariates_temp: “pc” or “fc” for past, or future covariates respectively.

  • encoder: the SingleEncoder type used:
    • “cyc” (cyclic temporal encoder),

    • “dta” (datetime attribute encoder),

    • “pos” (positional integer index encoder),

    • “cus” (custom callable index encoder)

  • attribute: the attribute used for the underlying encoder. Some examples:
    • “month_sin”, “month_cos” (for “cyc”)

    • “month” (for “dta”)

    • “relative” (for “pos”)

    • “custom” (for “cus”)

Return type

str

property components: Index

Returns the encoded component names. Only available after Encoder.encode_train() or Encoder.encode_inference() have been called.

Return type

Index

encode_inference(n, target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for inference/prediction.

Parameters
  • n (int) – The forecast horizon

  • target (TimeSeries) – The target TimeSeries used during training or passed to prediction as series

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for prediction: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

encode_train(target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for training.

Parameters
  • target (TimeSeries) – The target TimeSeries used during training or passed to prediction as series

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for training: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

encode_train_inference(n, target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for inference/prediction.

Parameters
  • n (int) – The forecast horizon

  • target (TimeSeries) – The target TimeSeries used during training and prediction.

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for training and prediction: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

property encoding_n_components: int

The number of components in the SingleEncoder output.

Return type

int

property fit_called: bool

Returns whether the Encoder object has been fitted.

Return type

bool

property requires_fit: bool

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Return type

bool

class darts.dataprocessing.encoders.encoders.FutureCyclicEncoder(attribute, input_chunk_length=None, output_chunk_length=None, lags_covariates=None, tz=None)[source]

Bases: CyclicTemporalEncoder

CyclicEncoder: Cyclic encoding of future covariates datetime attributes.

Attributes

accept_transformer

CyclicTemporalEncoder should not be transformed.

base_component_name

Returns the base encoder base component name.

components

Returns the encoded component names.

encoding_n_components

The number of components in the SingleEncoder output.

fit_called

Returns whether the Encoder object has been fitted.

requires_fit

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Methods

encode_inference(n, target[, covariates, ...])

Returns encoded index for inference/prediction.

encode_train(target[, covariates, ...])

Returns encoded index for training.

encode_train_inference(n, target[, ...])

Returns encoded index for inference/prediction.

Parameters
  • attribute (str) – The attribute of the underlying pd.DatetimeIndex from for which to apply cyclic encoding. Must be an attribute of pd.DatetimeIndex, or week / weekofyear / week_of_year - e.g. “month”, “weekday”, “day”, “hour”, “minute”, “second”. See all available attributes in https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DatetimeIndex.html#pandas.DatetimeIndex. For more information, check out datetime_attribute_timeseries()

  • input_chunk_length (Optional[int]) – Optionally, the number of input target time steps per chunk. Only required for TorchForecastingModel, and RegressionModel. Corresponds to parameter input_chunk_length from TorchForecastingModel, or to the absolute minimum target lag value abs(min(lags)) for RegressionModel.

  • output_chunk_length (Optional[int]) – Optionally, the number of output target time steps per chunk. Only required for TorchForecastingModel, and RegressionModel. Corresponds to parameter output_chunk_length from both TorchForecastingModel, and RegressionModel.

  • lags_covariates (Optional[List[int]]) – Optionally, a list of integers representing the future covariate lags. Accepts all integer values. Only required for RegressionModel. Corresponds to the lag values from parameter lags_future_covariates from RegressionModel.

  • tz (Optional[str]) – Optionally, a time zone to convert the time index to before computing the attributes.

Attributes

accept_transformer

CyclicTemporalEncoder should not be transformed.

base_component_name

Returns the base encoder base component name.

components

Returns the encoded component names.

encoding_n_components

The number of components in the SingleEncoder output.

fit_called

Returns whether the Encoder object has been fitted.

requires_fit

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Methods

encode_inference(n, target[, covariates, ...])

Returns encoded index for inference/prediction.

encode_train(target[, covariates, ...])

Returns encoded index for training.

encode_train_inference(n, target[, ...])

Returns encoded index for inference/prediction.

property accept_transformer: List[bool]

CyclicTemporalEncoder should not be transformed. Returns two elements for sine and cosine waves.

Return type

List[bool]

property base_component_name: str

Returns the base encoder base component name. The string follows the given format: “darts_enc_{covariates_temp}_{encoder}_{attribute}”, where the elements are:

  • covariates_temp: “pc” or “fc” for past, or future covariates respectively.

  • encoder: the SingleEncoder type used:
    • “cyc” (cyclic temporal encoder),

    • “dta” (datetime attribute encoder),

    • “pos” (positional integer index encoder),

    • “cus” (custom callable index encoder)

  • attribute: the attribute used for the underlying encoder. Some examples:
    • “month_sin”, “month_cos” (for “cyc”)

    • “month” (for “dta”)

    • “relative” (for “pos”)

    • “custom” (for “cus”)

Return type

str

property components: Index

Returns the encoded component names. Only available after Encoder.encode_train() or Encoder.encode_inference() have been called.

Return type

Index

encode_inference(n, target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for inference/prediction.

Parameters
  • n (int) – The forecast horizon

  • target (TimeSeries) – The target TimeSeries used during training or passed to prediction as series

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for prediction: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

encode_train(target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for training.

Parameters
  • target (TimeSeries) – The target TimeSeries used during training or passed to prediction as series

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for training: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

encode_train_inference(n, target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for inference/prediction.

Parameters
  • n (int) – The forecast horizon

  • target (TimeSeries) – The target TimeSeries used during training and prediction.

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for training and prediction: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

property encoding_n_components: int

The number of components in the SingleEncoder output.

Return type

int

property fit_called: bool

Returns whether the Encoder object has been fitted.

Return type

bool

property requires_fit: bool

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Return type

bool

class darts.dataprocessing.encoders.encoders.FutureDatetimeAttributeEncoder(attribute, input_chunk_length=None, output_chunk_length=None, lags_covariates=None, tz=None)[source]

Bases: DatetimeAttributeEncoder

Datetime attribute encoder for future covariates.

Attributes

accept_transformer

DatetimeAttributeEncoder accepts transformations

base_component_name

Returns the base encoder base component name.

components

Returns the encoded component names.

encoding_n_components

The number of components in the SingleEncoder output.

fit_called

Returns whether the Encoder object has been fitted.

requires_fit

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Methods

encode_inference(n, target[, covariates, ...])

Returns encoded index for inference/prediction.

encode_train(target[, covariates, ...])

Returns encoded index for training.

encode_train_inference(n, target[, ...])

Returns encoded index for inference/prediction.

Parameters
  • attribute (str) – The attribute of the underlying pd.DatetimeIndex for which to add scalar information. Must be an attribute of pd.DatetimeIndex, or week / weekofyear / week_of_year - e.g. “month”, “weekday”, “day”, “hour”, “minute”, “second”. See all available attributes in https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DatetimeIndex.html#pandas.DatetimeIndex. For more information, check out datetime_attribute_timeseries()

  • input_chunk_length (Optional[int]) – Optionally, the number of input target time steps per chunk. Only required for TorchForecastingModel, and RegressionModel. Corresponds to parameter input_chunk_length from TorchForecastingModel, or to the absolute minimum target lag value abs(min(lags)) for RegressionModel.

  • output_chunk_length (Optional[int]) – Optionally, the number of output target time steps per chunk. Only required for TorchForecastingModel, and RegressionModel. Corresponds to parameter output_chunk_length from both TorchForecastingModel, and RegressionModel.

  • lags_covariates (Optional[List[int]]) – Optionally, a list of integers representing the future covariate lags. Accepts all integer values. Only required for RegressionModel. Corresponds to the lag values from parameter lags_future_covariates from RegressionModel.

  • tz (Optional[str]) – Optionally, a time zone to convert the time index to before computing the attributes.

Attributes

accept_transformer

DatetimeAttributeEncoder accepts transformations

base_component_name

Returns the base encoder base component name.

components

Returns the encoded component names.

encoding_n_components

The number of components in the SingleEncoder output.

fit_called

Returns whether the Encoder object has been fitted.

requires_fit

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Methods

encode_inference(n, target[, covariates, ...])

Returns encoded index for inference/prediction.

encode_train(target[, covariates, ...])

Returns encoded index for training.

encode_train_inference(n, target[, ...])

Returns encoded index for inference/prediction.

property accept_transformer: List[bool]

DatetimeAttributeEncoder accepts transformations

Return type

List[bool]

property base_component_name: str

Returns the base encoder base component name. The string follows the given format: “darts_enc_{covariates_temp}_{encoder}_{attribute}”, where the elements are:

  • covariates_temp: “pc” or “fc” for past, or future covariates respectively.

  • encoder: the SingleEncoder type used:
    • “cyc” (cyclic temporal encoder),

    • “dta” (datetime attribute encoder),

    • “pos” (positional integer index encoder),

    • “cus” (custom callable index encoder)

  • attribute: the attribute used for the underlying encoder. Some examples:
    • “month_sin”, “month_cos” (for “cyc”)

    • “month” (for “dta”)

    • “relative” (for “pos”)

    • “custom” (for “cus”)

Return type

str

property components: Index

Returns the encoded component names. Only available after Encoder.encode_train() or Encoder.encode_inference() have been called.

Return type

Index

encode_inference(n, target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for inference/prediction.

Parameters
  • n (int) – The forecast horizon

  • target (TimeSeries) – The target TimeSeries used during training or passed to prediction as series

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for prediction: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

encode_train(target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for training.

Parameters
  • target (TimeSeries) – The target TimeSeries used during training or passed to prediction as series

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for training: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

encode_train_inference(n, target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for inference/prediction.

Parameters
  • n (int) – The forecast horizon

  • target (TimeSeries) – The target TimeSeries used during training and prediction.

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for training and prediction: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

property encoding_n_components: int

The number of components in the SingleEncoder output.

Return type

int

property fit_called: bool

Returns whether the Encoder object has been fitted.

Return type

bool

property requires_fit: bool

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Return type

bool

class darts.dataprocessing.encoders.encoders.FutureIntegerIndexEncoder(attribute, input_chunk_length=None, output_chunk_length=None, lags_covariates=None, **kwargs)[source]

Bases: IntegerIndexEncoder

IntegerIndexEncoder: Adds integer index value (position) for future covariates derived from the underlying TimeSeries’ time index.

Attributes

accept_transformer

IntegerIndexEncoder accepts transformations.

base_component_name

Returns the base encoder base component name.

components

Returns the encoded component names.

encoding_n_components

The number of components in the SingleEncoder output.

fit_called

Returns whether the Encoder object has been fitted.

requires_fit

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Methods

encode_inference(n, target[, covariates, ...])

Returns encoded index for inference/prediction.

encode_train(target[, covariates, ...])

Returns encoded index for training.

encode_train_inference(n, target[, ...])

Returns encoded index for inference/prediction.

Parameters
  • attribute (str) – Currently only ‘relative’ is supported. The generated encoded values will range from (-inf, inf) and the target series end time will be used as a reference to evaluate the relative index positions.

  • input_chunk_length (Optional[int]) – Optionally, the number of input target time steps per chunk. Only required for TorchForecastingModel, and RegressionModel. Corresponds to parameter input_chunk_length from TorchForecastingModel, or to the absolute minimum target lag value abs(min(lags)) for RegressionModel.

  • output_chunk_length (Optional[int]) – Optionally, the number of output target time steps per chunk. Only required for TorchForecastingModel, and RegressionModel. Corresponds to parameter output_chunk_length from both TorchForecastingModel, and RegressionModel.

  • lags_covariates (Optional[List[int]]) – Optionally, a list of integers representing the future covariate lags. Accepts all integer values. Only required for RegressionModel. Corresponds to the lag values from parameter lags_future_covariates from RegressionModel.

Attributes

accept_transformer

IntegerIndexEncoder accepts transformations.

base_component_name

Returns the base encoder base component name.

components

Returns the encoded component names.

encoding_n_components

The number of components in the SingleEncoder output.

fit_called

Returns whether the Encoder object has been fitted.

requires_fit

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Methods

encode_inference(n, target[, covariates, ...])

Returns encoded index for inference/prediction.

encode_train(target[, covariates, ...])

Returns encoded index for training.

encode_train_inference(n, target[, ...])

Returns encoded index for inference/prediction.

property accept_transformer: List[bool]

IntegerIndexEncoder accepts transformations. Note that transforming ‘relative’ IntegerIndexEncoder will return the absolute position (in the transformed space).

Return type

List[bool]

property base_component_name: str

Returns the base encoder base component name. The string follows the given format: “darts_enc_{covariates_temp}_{encoder}_{attribute}”, where the elements are:

  • covariates_temp: “pc” or “fc” for past, or future covariates respectively.

  • encoder: the SingleEncoder type used:
    • “cyc” (cyclic temporal encoder),

    • “dta” (datetime attribute encoder),

    • “pos” (positional integer index encoder),

    • “cus” (custom callable index encoder)

  • attribute: the attribute used for the underlying encoder. Some examples:
    • “month_sin”, “month_cos” (for “cyc”)

    • “month” (for “dta”)

    • “relative” (for “pos”)

    • “custom” (for “cus”)

Return type

str

property components: Index

Returns the encoded component names. Only available after Encoder.encode_train() or Encoder.encode_inference() have been called.

Return type

Index

encode_inference(n, target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for inference/prediction.

Parameters
  • n (int) – The forecast horizon

  • target (TimeSeries) – The target TimeSeries used during training or passed to prediction as series

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for prediction: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

encode_train(target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for training.

Parameters
  • target (TimeSeries) – The target TimeSeries used during training or passed to prediction as series

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for training: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

encode_train_inference(n, target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for inference/prediction.

Parameters
  • n (int) – The forecast horizon

  • target (TimeSeries) – The target TimeSeries used during training and prediction.

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for training and prediction: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

property encoding_n_components: int

The number of components in the SingleEncoder output.

Return type

int

property fit_called: bool

Returns whether the Encoder object has been fitted.

Return type

bool

property requires_fit: bool

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Return type

bool

class darts.dataprocessing.encoders.encoders.IntegerIndexEncoder(index_generator, attribute)[source]

Bases: SingleEncoder

IntegerIndexEncoder: Adds integer index value (position) derived from the underlying TimeSeries’ time index for past and future covariates.

Attributes

accept_transformer

IntegerIndexEncoder accepts transformations.

base_component_name

Returns the base encoder base component name.

components

Returns the encoded component names.

encoding_n_components

The number of components in the SingleEncoder output.

fit_called

Returns whether the Encoder object has been fitted.

requires_fit

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Methods

encode_inference(n, target[, covariates, ...])

Returns encoded index for inference/prediction.

encode_train(target[, covariates, ...])

Returns encoded index for training.

encode_train_inference(n, target[, ...])

Returns encoded index for inference/prediction.

Parameters
  • index_generator (CovariatesIndexGenerator) – An instance of CovariatesIndexGenerator with methods generate_train_idx() and generate_inference_idx(). Used to generate the index for encoders.

  • attribute (str) – Currently only ‘relative’ is supported. The generated encoded values will range from (-inf, inf) and the target series end time will be used as a reference to evaluate the relative index positions.

Attributes

accept_transformer

IntegerIndexEncoder accepts transformations.

base_component_name

Returns the base encoder base component name.

components

Returns the encoded component names.

encoding_n_components

The number of components in the SingleEncoder output.

fit_called

Returns whether the Encoder object has been fitted.

requires_fit

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Methods

encode_inference(n, target[, covariates, ...])

Returns encoded index for inference/prediction.

encode_train(target[, covariates, ...])

Returns encoded index for training.

encode_train_inference(n, target[, ...])

Returns encoded index for inference/prediction.

property accept_transformer: List[bool]

IntegerIndexEncoder accepts transformations. Note that transforming ‘relative’ IntegerIndexEncoder will return the absolute position (in the transformed space).

Return type

List[bool]

property base_component_name: str

Returns the base encoder base component name. The string follows the given format: “darts_enc_{covariates_temp}_{encoder}_{attribute}”, where the elements are:

  • covariates_temp: “pc” or “fc” for past, or future covariates respectively.

  • encoder: the SingleEncoder type used:
    • “cyc” (cyclic temporal encoder),

    • “dta” (datetime attribute encoder),

    • “pos” (positional integer index encoder),

    • “cus” (custom callable index encoder)

  • attribute: the attribute used for the underlying encoder. Some examples:
    • “month_sin”, “month_cos” (for “cyc”)

    • “month” (for “dta”)

    • “relative” (for “pos”)

    • “custom” (for “cus”)

Return type

str

property components: Index

Returns the encoded component names. Only available after Encoder.encode_train() or Encoder.encode_inference() have been called.

Return type

Index

encode_inference(n, target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for inference/prediction.

Parameters
  • n (int) – The forecast horizon

  • target (TimeSeries) – The target TimeSeries used during training or passed to prediction as series

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for prediction: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

encode_train(target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for training.

Parameters
  • target (TimeSeries) – The target TimeSeries used during training or passed to prediction as series

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for training: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

encode_train_inference(n, target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for inference/prediction.

Parameters
  • n (int) – The forecast horizon

  • target (TimeSeries) – The target TimeSeries used during training and prediction.

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for training and prediction: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

property encoding_n_components: int

The number of components in the SingleEncoder output.

Return type

int

property fit_called: bool

Returns whether the Encoder object has been fitted.

Return type

bool

property requires_fit: bool

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Return type

bool

class darts.dataprocessing.encoders.encoders.PastCallableIndexEncoder(attribute, input_chunk_length=None, output_chunk_length=None, lags_covariates=None, **kwargs)[source]

Bases: CallableIndexEncoder

IntegerIndexEncoder: Adds integer index value (position) for past covariates derived from the underlying TimeSeries’ time index.

Attributes

accept_transformer

CallableIndexEncoder accepts transformations.

base_component_name

Returns the base encoder base component name.

components

Returns the encoded component names.

encoding_n_components

The number of components in the SingleEncoder output.

fit_called

Returns whether the Encoder object has been fitted.

requires_fit

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Methods

encode_inference(n, target[, covariates, ...])

Returns encoded index for inference/prediction.

encode_train(target[, covariates, ...])

Returns encoded index for training.

encode_train_inference(n, target[, ...])

Returns encoded index for inference/prediction.

Parameters
  • attribute (Callable) – A callable that takes an index index of type (pd.DatetimeIndex, pd.RangeIndex) as input and returns a np.ndarray of shape (len(index),). An example for a correct attribute for index of type pd.DatetimeIndex: attribute = lambda index: (index.year - 1950) / 50. And for pd.RangeIndex: attribute = lambda index: (index - 1950) / 50

  • input_chunk_length (Optional[int]) – Optionally, the number of input target time steps per chunk. Only required for TorchForecastingModel, and RegressionModel. Corresponds to parameter input_chunk_length from TorchForecastingModel, or to the absolute minimum target lag value abs(min(lags)) for RegressionModel.

  • output_chunk_length (Optional[int]) – Optionally, the number of output target time steps per chunk. Only required for TorchForecastingModel, and RegressionModel. Corresponds to parameter output_chunk_length from both TorchForecastingModel, and RegressionModel.

  • lags_covariates (Optional[List[int]]) – Optionally, a list of integers representing the past covariate lags. Accepts integer lag values <= -1. Only required for RegressionModel. Corresponds to the lag values from parameter lags_past_covariates of RegressionModel.

Attributes

accept_transformer

CallableIndexEncoder accepts transformations.

base_component_name

Returns the base encoder base component name.

components

Returns the encoded component names.

encoding_n_components

The number of components in the SingleEncoder output.

fit_called

Returns whether the Encoder object has been fitted.

requires_fit

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Methods

encode_inference(n, target[, covariates, ...])

Returns encoded index for inference/prediction.

encode_train(target[, covariates, ...])

Returns encoded index for training.

encode_train_inference(n, target[, ...])

Returns encoded index for inference/prediction.

property accept_transformer: List[bool]

CallableIndexEncoder accepts transformations.

Return type

List[bool]

property base_component_name: str

Returns the base encoder base component name. The string follows the given format: “darts_enc_{covariates_temp}_{encoder}_{attribute}”, where the elements are:

  • covariates_temp: “pc” or “fc” for past, or future covariates respectively.

  • encoder: the SingleEncoder type used:
    • “cyc” (cyclic temporal encoder),

    • “dta” (datetime attribute encoder),

    • “pos” (positional integer index encoder),

    • “cus” (custom callable index encoder)

  • attribute: the attribute used for the underlying encoder. Some examples:
    • “month_sin”, “month_cos” (for “cyc”)

    • “month” (for “dta”)

    • “relative” (for “pos”)

    • “custom” (for “cus”)

Return type

str

property components: Index

Returns the encoded component names. Only available after Encoder.encode_train() or Encoder.encode_inference() have been called.

Return type

Index

encode_inference(n, target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for inference/prediction.

Parameters
  • n (int) – The forecast horizon

  • target (TimeSeries) – The target TimeSeries used during training or passed to prediction as series

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for prediction: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

encode_train(target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for training.

Parameters
  • target (TimeSeries) – The target TimeSeries used during training or passed to prediction as series

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for training: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

encode_train_inference(n, target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for inference/prediction.

Parameters
  • n (int) – The forecast horizon

  • target (TimeSeries) – The target TimeSeries used during training and prediction.

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for training and prediction: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

property encoding_n_components: int

The number of components in the SingleEncoder output.

Return type

int

property fit_called: bool

Returns whether the Encoder object has been fitted.

Return type

bool

property requires_fit: bool

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Return type

bool

class darts.dataprocessing.encoders.encoders.PastCyclicEncoder(attribute, input_chunk_length=None, output_chunk_length=None, lags_covariates=None, tz=None)[source]

Bases: CyclicTemporalEncoder

CyclicEncoder: Cyclic encoding of past covariates datetime attributes.

Attributes

accept_transformer

CyclicTemporalEncoder should not be transformed.

base_component_name

Returns the base encoder base component name.

components

Returns the encoded component names.

encoding_n_components

The number of components in the SingleEncoder output.

fit_called

Returns whether the Encoder object has been fitted.

requires_fit

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Methods

encode_inference(n, target[, covariates, ...])

Returns encoded index for inference/prediction.

encode_train(target[, covariates, ...])

Returns encoded index for training.

encode_train_inference(n, target[, ...])

Returns encoded index for inference/prediction.

Parameters
  • attribute (str) – The attribute of the underlying pd.DatetimeIndex from for which to apply cyclic encoding. Must be an attribute of pd.DatetimeIndex, or week / weekofyear / week_of_year - e.g. “month”, “weekday”, “day”, “hour”, “minute”, “second”. See all available attributes in https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DatetimeIndex.html#pandas.DatetimeIndex. For more information, check out datetime_attribute_timeseries()

  • input_chunk_length (Optional[int]) – Optionally, the number of input target time steps per chunk. Only required for TorchForecastingModel, and RegressionModel. Corresponds to parameter input_chunk_length from TorchForecastingModel, or to the absolute minimum target lag value abs(min(lags)) for RegressionModel.

  • output_chunk_length (Optional[int]) – Optionally, the number of output target time steps per chunk. Only required for TorchForecastingModel, and RegressionModel. Corresponds to parameter output_chunk_length from both TorchForecastingModel, and RegressionModel.

  • lags_covariates (Optional[List[int]]) – Optionally, a list of integers representing the past covariate lags. Accepts integer lag values <= -1. Only required for RegressionModel. Corresponds to the lag values from parameter lags_past_covariates of RegressionModel.

  • tz (Optional[str]) – Optionally, a time zone to convert the time index to before computing the attributes.

Attributes

accept_transformer

CyclicTemporalEncoder should not be transformed.

base_component_name

Returns the base encoder base component name.

components

Returns the encoded component names.

encoding_n_components

The number of components in the SingleEncoder output.

fit_called

Returns whether the Encoder object has been fitted.

requires_fit

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Methods

encode_inference(n, target[, covariates, ...])

Returns encoded index for inference/prediction.

encode_train(target[, covariates, ...])

Returns encoded index for training.

encode_train_inference(n, target[, ...])

Returns encoded index for inference/prediction.

property accept_transformer: List[bool]

CyclicTemporalEncoder should not be transformed. Returns two elements for sine and cosine waves.

Return type

List[bool]

property base_component_name: str

Returns the base encoder base component name. The string follows the given format: “darts_enc_{covariates_temp}_{encoder}_{attribute}”, where the elements are:

  • covariates_temp: “pc” or “fc” for past, or future covariates respectively.

  • encoder: the SingleEncoder type used:
    • “cyc” (cyclic temporal encoder),

    • “dta” (datetime attribute encoder),

    • “pos” (positional integer index encoder),

    • “cus” (custom callable index encoder)

  • attribute: the attribute used for the underlying encoder. Some examples:
    • “month_sin”, “month_cos” (for “cyc”)

    • “month” (for “dta”)

    • “relative” (for “pos”)

    • “custom” (for “cus”)

Return type

str

property components: Index

Returns the encoded component names. Only available after Encoder.encode_train() or Encoder.encode_inference() have been called.

Return type

Index

encode_inference(n, target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for inference/prediction.

Parameters
  • n (int) – The forecast horizon

  • target (TimeSeries) – The target TimeSeries used during training or passed to prediction as series

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for prediction: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

encode_train(target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for training.

Parameters
  • target (TimeSeries) – The target TimeSeries used during training or passed to prediction as series

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for training: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

encode_train_inference(n, target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for inference/prediction.

Parameters
  • n (int) – The forecast horizon

  • target (TimeSeries) – The target TimeSeries used during training and prediction.

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for training and prediction: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

property encoding_n_components: int

The number of components in the SingleEncoder output.

Return type

int

property fit_called: bool

Returns whether the Encoder object has been fitted.

Return type

bool

property requires_fit: bool

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Return type

bool

class darts.dataprocessing.encoders.encoders.PastDatetimeAttributeEncoder(attribute, input_chunk_length=None, output_chunk_length=None, lags_covariates=None, tz=None)[source]

Bases: DatetimeAttributeEncoder

Datetime attribute encoder for past covariates.

Attributes

accept_transformer

DatetimeAttributeEncoder accepts transformations

base_component_name

Returns the base encoder base component name.

components

Returns the encoded component names.

encoding_n_components

The number of components in the SingleEncoder output.

fit_called

Returns whether the Encoder object has been fitted.

requires_fit

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Methods

encode_inference(n, target[, covariates, ...])

Returns encoded index for inference/prediction.

encode_train(target[, covariates, ...])

Returns encoded index for training.

encode_train_inference(n, target[, ...])

Returns encoded index for inference/prediction.

Parameters
  • attribute (str) – The attribute of the underlying pd.DatetimeIndex for which to add scalar information. Must be an attribute of pd.DatetimeIndex, or week / weekofyear / week_of_year - e.g. “month”, “weekday”, “day”, “hour”, “minute”, “second”. See all available attributes in https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DatetimeIndex.html#pandas.DatetimeIndex. For more information, check out datetime_attribute_timeseries()

  • input_chunk_length (Optional[int]) – Optionally, the number of input target time steps per chunk. Only required for TorchForecastingModel, and RegressionModel. Corresponds to parameter input_chunk_length from TorchForecastingModel, or to the absolute minimum target lag value abs(min(lags)) for RegressionModel.

  • output_chunk_length (Optional[int]) – Optionally, the number of output target time steps per chunk. Only required for TorchForecastingModel, and RegressionModel. Corresponds to parameter output_chunk_length from both TorchForecastingModel, and RegressionModel.

  • lags_covariates (Optional[List[int]]) – Optionally, a list of integers representing the past covariate lags. Accepts integer lag values <= -1. Only required for RegressionModel. Corresponds to the lag values from parameter lags_past_covariates of RegressionModel.

  • tz (Optional[str]) – Optionally, a time zone to convert the time index to before computing the attributes.

Attributes

accept_transformer

DatetimeAttributeEncoder accepts transformations

base_component_name

Returns the base encoder base component name.

components

Returns the encoded component names.

encoding_n_components

The number of components in the SingleEncoder output.

fit_called

Returns whether the Encoder object has been fitted.

requires_fit

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Methods

encode_inference(n, target[, covariates, ...])

Returns encoded index for inference/prediction.

encode_train(target[, covariates, ...])

Returns encoded index for training.

encode_train_inference(n, target[, ...])

Returns encoded index for inference/prediction.

property accept_transformer: List[bool]

DatetimeAttributeEncoder accepts transformations

Return type

List[bool]

property base_component_name: str

Returns the base encoder base component name. The string follows the given format: “darts_enc_{covariates_temp}_{encoder}_{attribute}”, where the elements are:

  • covariates_temp: “pc” or “fc” for past, or future covariates respectively.

  • encoder: the SingleEncoder type used:
    • “cyc” (cyclic temporal encoder),

    • “dta” (datetime attribute encoder),

    • “pos” (positional integer index encoder),

    • “cus” (custom callable index encoder)

  • attribute: the attribute used for the underlying encoder. Some examples:
    • “month_sin”, “month_cos” (for “cyc”)

    • “month” (for “dta”)

    • “relative” (for “pos”)

    • “custom” (for “cus”)

Return type

str

property components: Index

Returns the encoded component names. Only available after Encoder.encode_train() or Encoder.encode_inference() have been called.

Return type

Index

encode_inference(n, target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for inference/prediction.

Parameters
  • n (int) – The forecast horizon

  • target (TimeSeries) – The target TimeSeries used during training or passed to prediction as series

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for prediction: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

encode_train(target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for training.

Parameters
  • target (TimeSeries) – The target TimeSeries used during training or passed to prediction as series

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for training: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

encode_train_inference(n, target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for inference/prediction.

Parameters
  • n (int) – The forecast horizon

  • target (TimeSeries) – The target TimeSeries used during training and prediction.

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for training and prediction: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

property encoding_n_components: int

The number of components in the SingleEncoder output.

Return type

int

property fit_called: bool

Returns whether the Encoder object has been fitted.

Return type

bool

property requires_fit: bool

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Return type

bool

class darts.dataprocessing.encoders.encoders.PastIntegerIndexEncoder(attribute, input_chunk_length=None, output_chunk_length=None, lags_covariates=None, **kwargs)[source]

Bases: IntegerIndexEncoder

IntegerIndexEncoder: Adds integer index value (position) for past covariates derived from the underlying TimeSeries’ time index.

Attributes

accept_transformer

IntegerIndexEncoder accepts transformations.

base_component_name

Returns the base encoder base component name.

components

Returns the encoded component names.

encoding_n_components

The number of components in the SingleEncoder output.

fit_called

Returns whether the Encoder object has been fitted.

requires_fit

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Methods

encode_inference(n, target[, covariates, ...])

Returns encoded index for inference/prediction.

encode_train(target[, covariates, ...])

Returns encoded index for training.

encode_train_inference(n, target[, ...])

Returns encoded index for inference/prediction.

Parameters
  • attribute (str) – Currently only ‘relative’ is supported. The generated encoded values will range from (-inf, inf) and the target series end time will be used as a reference to evaluate the relative index positions.

  • input_chunk_length (Optional[int]) – Optionally, the number of input target time steps per chunk. Only required for TorchForecastingModel, and RegressionModel. Corresponds to parameter input_chunk_length from TorchForecastingModel, or to the absolute minimum target lag value abs(min(lags)) for RegressionModel.

  • output_chunk_length (Optional[int]) – Optionally, the number of output target time steps per chunk. Only required for TorchForecastingModel, and RegressionModel. Corresponds to parameter output_chunk_length from both TorchForecastingModel, and RegressionModel.

  • lags_covariates (Optional[List[int]]) – Optionally, a list of integers representing the past covariate lags. Accepts integer lag values <= -1. Only required for RegressionModel. Corresponds to the lag values from parameter lags_past_covariates of RegressionModel.

Attributes

accept_transformer

IntegerIndexEncoder accepts transformations.

base_component_name

Returns the base encoder base component name.

components

Returns the encoded component names.

encoding_n_components

The number of components in the SingleEncoder output.

fit_called

Returns whether the Encoder object has been fitted.

requires_fit

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Methods

encode_inference(n, target[, covariates, ...])

Returns encoded index for inference/prediction.

encode_train(target[, covariates, ...])

Returns encoded index for training.

encode_train_inference(n, target[, ...])

Returns encoded index for inference/prediction.

property accept_transformer: List[bool]

IntegerIndexEncoder accepts transformations. Note that transforming ‘relative’ IntegerIndexEncoder will return the absolute position (in the transformed space).

Return type

List[bool]

property base_component_name: str

Returns the base encoder base component name. The string follows the given format: “darts_enc_{covariates_temp}_{encoder}_{attribute}”, where the elements are:

  • covariates_temp: “pc” or “fc” for past, or future covariates respectively.

  • encoder: the SingleEncoder type used:
    • “cyc” (cyclic temporal encoder),

    • “dta” (datetime attribute encoder),

    • “pos” (positional integer index encoder),

    • “cus” (custom callable index encoder)

  • attribute: the attribute used for the underlying encoder. Some examples:
    • “month_sin”, “month_cos” (for “cyc”)

    • “month” (for “dta”)

    • “relative” (for “pos”)

    • “custom” (for “cus”)

Return type

str

property components: Index

Returns the encoded component names. Only available after Encoder.encode_train() or Encoder.encode_inference() have been called.

Return type

Index

encode_inference(n, target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for inference/prediction.

Parameters
  • n (int) – The forecast horizon

  • target (TimeSeries) – The target TimeSeries used during training or passed to prediction as series

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for prediction: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

encode_train(target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for training.

Parameters
  • target (TimeSeries) – The target TimeSeries used during training or passed to prediction as series

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for training: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

encode_train_inference(n, target, covariates=None, merge_covariates=True, **kwargs)

Returns encoded index for inference/prediction.

Parameters
  • n (int) – The forecast horizon

  • target (TimeSeries) – The target TimeSeries used during training and prediction.

  • covariates (Optional[TimeSeries]) – Optionally, the covariates used for training and prediction: past covariates if self.index_generator is a PastCovariatesIndexGenerator, future covariates if self.index_generator is a FutureCovariatesIndexGenerator

  • merge_covariates (bool) – Whether to merge the encoded TimeSeries with covariates.

Return type

TimeSeries

property encoding_n_components: int

The number of components in the SingleEncoder output.

Return type

int

property fit_called: bool

Returns whether the Encoder object has been fitted.

Return type

bool

property requires_fit: bool

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Return type

bool

class darts.dataprocessing.encoders.encoders.SequentialEncoder(add_encoders, input_chunk_length=None, output_chunk_length=None, lags_past_covariates=None, lags_future_covariates=None, takes_past_covariates=False, takes_future_covariates=False)[source]

Bases: Encoder

A SequentialEncoder object can store and control multiple past and future covariates encoders at once. It provides the same functionality as single encoders (encode_train(), encode_inference(), encode_train_inference()).

Attributes

components

Returns the covariates component names generated by SequentialEncoder.past_encoders and SequentialEncoder.future_encoders.

encoder_map

Mapping between encoder identifier string (from parameters at model creations) and the corresponding future or past covariates encoder

encoders

Returns a tuple of (past covariates encoders, future covariates encoders)

encoding_n_components

Returns the number of components generated by SequentialEncoder.past_encoders and SequentialEncoder.future_encoders.

fit_called

Returns whether the Encoder object has been fitted.

future_components

Returns the future covariates component names generated by SequentialEncoder.future_encoders.

future_encoders

Returns the future covariates encoders

future_transformer

Returns the future transformer object

past_components

Returns the past covariates component names generated by SequentialEncoder.past_encoders.

past_encoders

Returns the past covariates encoders

past_transformer

Returns the past transformer object

requires_fit

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Methods

encode_inference(n, target[, ...])

Returns encoded index for all past and/or future covariates for inference/prediction.

encode_train(target[, past_covariates, ...])

Returns encoded index for all past and/or future covariates for training.

encode_train_inference(n, target[, ...])

Returns encoded index for all past and/or future covariates for training and inference/prediction.

transformers()

Returns a tuple of (past transformer, future transformer).

SequentialEncoder automatically creates encoder objects from parameter add_encoders. add_encoders can also be set directly in all of Darts’ ForecastingModels. This will automatically set up a SequentialEncoder tailored to the settings of the underlying forecasting model.

The add_encoders dict must follow this convention:

{encoder keyword: {temporal keyword: List[attributes]}, …, transformer keyword: transformer object}

Supported encoder keywords:

‘cyclic’ for cyclic temporal encoder. See the docs CyclicTemporalEncoder; ‘datetime_attribute’ for adding scalar information of pd.DatetimeIndex attribute. See the docs DatetimeAttributeEncoder ‘position’ for integer index position encoder. See the docs IntegerIndexEncoder; ‘custom’ for encoding index with custom callables (functions). See the docs CallableIndexEncoder;

Supported temporal keywords:

‘past’ for adding encoding as past covariates ‘future’ for adding encoding as future covariates

Supported attributes:

for attributes read the referred docs for the corresponding encoder from above

Supported transformers:

a transformer can be added with transformer keyword ‘transformer’. The transformer object must be an instance of Darts’ FittableDataTransformer such as Scaler() or BoxCox(). The transformers will be fitted on the training dataset when calling calling model.fit(). The training, validation and inference datasets are then transformed equally.

Supported time zone:

Optionally, apply a time zone conversion with keyword ‘tz’. This converts the time zone-naive index to a timezone ‘tz’ before applying the ‘cyclic’ or ‘datetime_attribute’ temporal encoders.

An example of a valid add_encoders dict for hourly data:

from darts.dataprocessing.transformers import Scaler
add_encoders={
    'cyclic': {'future': ['month']},
    'datetime_attribute': {'past': ['hour'], 'future': ['year', 'dayofweek']},
    'position': {'past': ['relative'], 'future': ['relative']},
    'custom': {'past': [lambda idx: (idx.year - 1950) / 50]},
    'transformer': Scaler(),
    'tz': 'CET',
}

Tuples of (encoder_id, attribute) are extracted from add_encoders to instantiate the SingleEncoder objects:

  • The encoder_id is extracted as follows:

    str(encoder_kw) + str(temporal_kw) -> ‘cyclic’ + ‘past’ -> encoder_id = ‘cyclic_past’ The encoder_id is used to map the parameters with the corresponding SingleEncoder objects.

  • The attribute is extracted from the values given by values under temporal_kw

    attribute = ‘month’ … The attribute tells the SingleEncoder which attribute of the index to encode

New encoders can be added by appending them to the mapping property SequentialEncoder.encoder_map()

Parameters
  • add_encoders (Dict) – A dictionary with the encoder settings.

  • input_chunk_length (Optional[int]) – Optionally, the number of input target time steps per chunk. Only required for TorchForecastingModel, and RegressionModel. Corresponds to parameter input_chunk_length from TorchForecastingModel, or to the absolute minimum target lag value abs(min(lags)) for RegressionModel.

  • output_chunk_length (Optional[int]) – Optionally, the number of output target time steps per chunk. Only required for TorchForecastingModel, and RegressionModel. Corresponds to parameter output_chunk_length from both TorchForecastingModel, and RegressionModel.

  • lags_past_covariates (Optional[List[int]]) – Optionally, a list of integers representing the past covariate lags. Accepts integer lag values <= -1. Only required for RegressionModel. Corresponds to the lag values from parameter lags_past_covariates of RegressionModel.

  • lags_future_covariates (Optional[List[int]]) – Optionally, a list of integers representing the future covariate lags. Accepts all integer values. Only required for RegressionModel. Corresponds to the lag values from parameter lags_future_covariates from RegressionModel.

  • takes_past_covariates (bool) – Whether to encode/generate past covariates.

  • takes_future_covariates (bool) – Whether to encode/generate future covariates.

Attributes

components

Returns the covariates component names generated by SequentialEncoder.past_encoders and SequentialEncoder.future_encoders.

encoder_map

Mapping between encoder identifier string (from parameters at model creations) and the corresponding future or past covariates encoder

encoders

Returns a tuple of (past covariates encoders, future covariates encoders)

encoding_n_components

Returns the number of components generated by SequentialEncoder.past_encoders and SequentialEncoder.future_encoders.

fit_called

Returns whether the Encoder object has been fitted.

future_components

Returns the future covariates component names generated by SequentialEncoder.future_encoders.

future_encoders

Returns the future covariates encoders

future_transformer

Returns the future transformer object

past_components

Returns the past covariates component names generated by SequentialEncoder.past_encoders.

past_encoders

Returns the past covariates encoders

past_transformer

Returns the past transformer object

requires_fit

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Methods

encode_inference(n, target[, ...])

Returns encoded index for all past and/or future covariates for inference/prediction.

encode_train(target[, past_covariates, ...])

Returns encoded index for all past and/or future covariates for training.

encode_train_inference(n, target[, ...])

Returns encoded index for all past and/or future covariates for training and inference/prediction.

transformers()

Returns a tuple of (past transformer, future transformer).

property components: Tuple[Index, Index]

Returns the covariates component names generated by SequentialEncoder.past_encoders and SequentialEncoder.future_encoders. A tuple of (past encoded components, future encoded components). Only available after calling SequentialEncoder.encode_train()

Return type

Tuple[Index, Index]

encode_inference(n, target, past_covariates=None, future_covariates=None, encode_past=True, encode_future=True)[source]

Returns encoded index for all past and/or future covariates for inference/prediction. Which covariates are generated depends on the parameters used at model creation.

Parameters
  • n (int) – The forecast horizon

  • target (Union[TimeSeries, Sequence[TimeSeries]]) – The target TimeSeries used during training or passed to prediction as series.

  • past_covariates (Union[TimeSeries, Sequence[TimeSeries], None]) – Optionally, the past covariates used for training.

  • future_covariates (Union[TimeSeries, Sequence[TimeSeries], None]) – Optionally, the future covariates used for training.

  • encode_past (bool) – Whether to apply encoders for past covariates.

  • encode_future (bool) – Whether to apply encoders for future covariates.

Returns

The past_covariates and/or future_covariates for prediction/inference including the encodings. If input {x}_covariates is None and no {x}_encoders are given, will return None for the {x}_covariates.

Return type

Tuple[past_covariates, future_covariates]

encode_train(target, past_covariates=None, future_covariates=None, encode_past=True, encode_future=True)[source]

Returns encoded index for all past and/or future covariates for training. Which covariates are generated depends on the parameters used at model creation.

Parameters
  • target (Union[TimeSeries, Sequence[TimeSeries]]) – The target TimeSeries used during training or passed to prediction as series.

  • past_covariates (Union[TimeSeries, Sequence[TimeSeries], None]) – Optionally, the past covariates used for training.

  • future_covariates (Union[TimeSeries, Sequence[TimeSeries], None]) – Optionally, the future covariates used for training.

  • encode_past (bool) – Whether to apply encoders for past covariates.

  • encode_future (bool) – Whether to apply encoders for future covariates.

Returns

The past_covariates and/or future_covariates for training including the encodings. If input {x}_covariates is None and no {x}_encoders are given, will return None for the {x}_covariates.

Return type

Tuple[past_covariates, future_covariates]

Raises

Warning – If model was created with add_encoders and there is suspicion of lazy loading. The encodings/covariates are generated eagerly before starting training for all individual targets and loaded into memory. Depending on the size of target data, this can create memory issues. In case this applies, consider setting add_encoders=None at model creation and build your encodings covariates manually for lazy loading.

encode_train_inference(n, target, past_covariates=None, future_covariates=None, encode_past=True, encode_future=True)[source]

Returns encoded index for all past and/or future covariates for training and inference/prediction. Which covariates are generated depends on the parameters used at model creation.

Parameters
  • n (int) – The forecast horizon

  • target (Union[TimeSeries, Sequence[TimeSeries]]) – The target TimeSeries used for training and prediction.

  • past_covariates (Union[TimeSeries, Sequence[TimeSeries], None]) – Optionally, the past covariates used for training and prediction.

  • future_covariates (Union[TimeSeries, Sequence[TimeSeries], None]) – Optionally, the future covariates used for training and prediction.

  • encode_past (bool) – Whether to apply encoders for past covariates.

  • encode_future (bool) – Whether to apply encoders for future covariates.

Returns

The past_covariates and/or future_covariates for prediction/inference including the encodings. If input {x}_covariates is None and no {x}_encoders are given, will return None for the {x}_covariates.

Return type

Tuple[past_covariates, future_covariates]

property encoder_map: Dict

Mapping between encoder identifier string (from parameters at model creations) and the corresponding future or past covariates encoder

Return type

Dict

property encoders: Tuple[List[SingleEncoder], List[SingleEncoder]]

Returns a tuple of (past covariates encoders, future covariates encoders)

Return type

Tuple[List[SingleEncoder], List[SingleEncoder]]

property encoding_n_components: Tuple[int, int]

Returns the number of components generated by SequentialEncoder.past_encoders and SequentialEncoder.future_encoders.

Return type

Tuple[int, int]

property fit_called: bool

Returns whether the Encoder object has been fitted.

Return type

bool

property future_components: Index

Returns the future covariates component names generated by SequentialEncoder.future_encoders. Only available after calling SequentialEncoder.encode_train()

Return type

Index

property future_encoders: List[SingleEncoder]

Returns the future covariates encoders

Return type

List[SingleEncoder]

property future_transformer: SequentialEncoderTransformer

Returns the future transformer object

Return type

SequentialEncoderTransformer

property past_components: Index

Returns the past covariates component names generated by SequentialEncoder.past_encoders. Only available after calling SequentialEncoder.encode_train()

Return type

Index

property past_encoders: List[SingleEncoder]

Returns the past covariates encoders

Return type

List[SingleEncoder]

property past_transformer: SequentialEncoderTransformer

Returns the past transformer object

Return type

SequentialEncoderTransformer

property requires_fit: bool

Whether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().

Return type

bool

transformers()[source]

Returns a tuple of (past transformer, future transformer).

Return type

Tuple[SequentialEncoderTransformer, SequentialEncoderTransformer]