MODULE REFERENCE
encoder_base
anomx.data.processing.encoders.encoder_baseEncoder Base Classes
CovariatesIndexGenerator
CovariatesIndexGenerator(input_chunk_length: int | None = None, output_chunk_length: int | None = None, lags_covariates: list[int] | None = None)Bases: ABC
| Parameter | Type | Default |
|---|---|---|
input_chunk_length | int | None | None |
output_chunk_length | int | None | None |
lags_covariates | list[int] | None | None |
anomx.data.processing.encoders.encoder_base.CovariatesIndexGenerator generates a time index for covariates at training and inference / prediction time with methods generate_train_idx(), and generate_inference_idx(). Without user covariates, it generates the minimum required covariate times spans for the corresponding scenarios described below. With user covariates, it simply copies and returns the covariates time index.
It can be used:
- in combination with local forecasting estimators, or in a model agnostic scenario: All parameters can be ignored. This scenario is only supported by
anomx.data.processing.encoders.encoder_base.FutureCovariatesIndexGenerator. - in combination with lag-based regression estimators: Set
input_chunk_length,output_chunk_length, andlags_covariates.input_chunk_lengthis the absolute value of the minimum target lagabs(min(lags))used with the lag-based regression estimator. Setoutput_chunk_length, andlags_covariateswith the identical values used at forecasting model creation. For the covariate lags, uselags_past_covariatesforanomx.data.processing.encoders.encoder_base.PastCovariatesIndexGenerator, andlags_future_covariatesforanomx.data.processing.encoders.encoder_base.FutureCovariatesIndexGenerator. - in combination with chunk-based neural forecasting estimators: Set
input_chunk_length, andoutput_chunk_lengthwith the identical values used at forecasting model creation.
Parameters
- input_chunk_length
Optionally, the number of input target time steps per chunk. Only required in scenarios B, C. Corresponds to
input_chunk_lengthfor chunk-based neural forecasting estimators, or to the absolute minimum target lag valueabs(min(lags))for lag-based regression estimators.- output_chunk_length
Optionally, the number of output target time steps per chunk. Only required in scenarios B, and C. Corresponds to
output_chunk_lengthfor both chunk-based neural forecasting estimators, and lag-based regression estimators.- lags_covariates
Optionally, a list of integers giving the covariates lags used by lag-based forecasting estimators. Only required in scenario B. Corresponds to the lag values from
lags_past_covariatesfor past covariates, andlags_future_covariatesfor future covariates.
Members
generate_train_idxmethod
generate_train_idx(target: TimeSeries, covariates: TimeSeries | None = None) -> tuple[TimeIndex, pd.Timestamp]Generates/extracts time index (or integer index) for covariates at model training time.
Parameters
- target
The target TimeSeries used during training.
- covariates
Optionally, the covariates used for training. If given, the returned time index is equal to the
covariatestime index. Else, the returned time index covers the minimum required covariate time span for training a specific forecasting model. These requirements are derived from parameters set atanomx.data.processing.encoders.encoder_base.CovariatesIndexGeneratorcreation.
| Parameter | Type | Default |
|---|---|---|
target | TimeSeries | required |
covariates | TimeSeries | None | None |
Returns tuple[TimeIndex, pd.Timestamp]
generate_inference_idxmethod
generate_inference_idx(n: int, target: TimeSeries, covariates: TimeSeries | None = None) -> tuple[TimeIndex, pd.Timestamp]Generates/extracts time index (or integer index) for covariates at model inference / prediction time.
Parameters
- n
The forecasting horizon.
- target
The target TimeSeries used during training or passed to prediction as
series.- covariates
Optionally, the covariates used for prediction. If given, the returned time index is equal to the
covariatestime index. Else, the returned time index covers the minimum required covariate time spans for performing inference / prediction with a specific forecasting model. These requirements are derived from parameters set atanomx.data.processing.encoders.encoder_base.CovariatesIndexGeneratorcreation.
| Parameter | Type | Default |
|---|---|---|
n | int | required |
target | TimeSeries | required |
covariates | TimeSeries | None | None |
Returns tuple[TimeIndex, pd.Timestamp]
generate_train_inference_idxmethod
generate_train_inference_idx(n: int, target: TimeSeries, covariates: TimeSeries | None = None) -> tuple[TimeIndex, pd.Timestamp]Generates/extracts time index (or integer index) for covariates for training and inference / prediction.
Parameters
- n
The forecasting horizon.
- target
The target TimeSeries used for training and inference / prediction as
series.- covariates
Optionally, the covariates used for training and inference / prediction. If given, the returned time index is equal to the
covariatestime index. Else, the returned time index covers the minimum required covariate time spans for performing training and inference / prediction with a specific forecasting model. These requirements are derived from parameters set atanomx.data.processing.encoders.encoder_base.CovariatesIndexGeneratorcreation.
| Parameter | Type | Default |
|---|---|---|
n | int | required |
target | TimeSeries | required |
covariates | TimeSeries | None | None |
Returns tuple[TimeIndex, pd.Timestamp]
base_component_nameproperty
base_component_name: strReturns the index generator base component name. - "pc": past covariates - "fc": future covariates
Returns str
Encoder
Encoder()Bases: ABC
Abstract class for all encoders
Members
encode_trainmethod
encode_train(target: TimeSeries, covariates: TimeSeries | None = None, merge_covariates: bool = True, **kwargs) -> TimeSeriesEach subclass must implement a method to encode the covariates index for training.
Parameters
- target
The target TimeSeries used during training or passed to prediction as
series.- covariates
Optionally, the past or future covariates used for training.
- merge_covariates
Whether to merge the encoded TimeSeries with
covariates.
| Parameter | Type | Default |
|---|---|---|
target | TimeSeries | required |
covariates | TimeSeries | None | None |
merge_covariates | bool | True |
**kwargs | — | — |
Returns TimeSeries
encode_inferencemethod
encode_inference(n: int, target: TimeSeries, covariates: TimeSeries | None = None, merge_covariates: bool = True, **kwargs) -> TimeSeriesEach subclass must implement a method to encode the covariates index for prediction.
Parameters
- n
The forecast horizon
- target
The target TimeSeries used during training or passed to prediction as
series- covariates
Optionally, the past or future covariates used for prediction.
- merge_covariates
Whether to merge the encoded TimeSeries with
covariates.
| Parameter | Type | Default |
|---|---|---|
n | int | required |
target | TimeSeries | required |
covariates | TimeSeries | None | None |
merge_covariates | bool | True |
**kwargs | — | — |
Returns TimeSeries
encode_train_inferencemethod
encode_train_inference(n: int, target: TimeSeries, covariates: TimeSeries | None = None, merge_covariates: bool = True, **kwargs) -> TimeSeriesEach subclass must implement a method to encode the covariates index for training and prediction.
Parameters
- n
The forecast horizon
- target
The target TimeSeries used during training and prediction.
- covariates
Optionally, the past or future covariates used for training and prediction.
- merge_covariates
Whether to merge the encoded TimeSeries with
covariates.
| Parameter | Type | Default |
|---|---|---|
n | int | required |
target | TimeSeries | required |
covariates | TimeSeries | None | None |
merge_covariates | bool | True |
**kwargs | — | — |
Returns TimeSeries
fit_calledproperty
requires_fitproperty
requires_fit: boolWhether the Encoder sub class must be fit with Encoder.encode_train() before inference with Encoder.encode_inference().
Returns bool
FutureCovariatesIndexGenerator
FutureCovariatesIndexGenerator(input_chunk_length: int | None = None, output_chunk_length: int | None = None, lags_covariates: list[int] | None = None)Bases: CovariatesIndexGenerator
Generates index for future covariates on train and inference datasets.
| Parameter | Type | Default |
|---|---|---|
input_chunk_length | int | None | None |
output_chunk_length | int | None | None |
lags_covariates | list[int] | None | None |
anomx.data.processing.encoders.encoder_base.CovariatesIndexGenerator generates a time index for covariates at training and inference / prediction time with methods generate_train_idx(), and generate_inference_idx(). Without user covariates, it generates the minimum required covariate times spans for the corresponding scenarios described below. With user covariates, it simply copies and returns the covariates time index.
It can be used:
- in combination with local forecasting estimators, or in a model agnostic scenario: All parameters can be ignored. This scenario is only supported by
anomx.data.processing.encoders.encoder_base.FutureCovariatesIndexGenerator. - in combination with lag-based regression estimators: Set
input_chunk_length,output_chunk_length, andlags_covariates.input_chunk_lengthis the absolute value of the minimum target lagabs(min(lags))used with the lag-based regression estimator. Setoutput_chunk_length, andlags_covariateswith the identical values used at forecasting model creation. For the covariate lags, uselags_past_covariatesforanomx.data.processing.encoders.encoder_base.PastCovariatesIndexGenerator, andlags_future_covariatesforanomx.data.processing.encoders.encoder_base.FutureCovariatesIndexGenerator. - in combination with chunk-based neural forecasting estimators: Set
input_chunk_length, andoutput_chunk_lengthwith the identical values used at forecasting model creation.
Parameters
- input_chunk_length
Optionally, the number of input target time steps per chunk. Only required in scenarios B, C. Corresponds to
input_chunk_lengthfor chunk-based neural forecasting estimators, or to the absolute minimum target lag valueabs(min(lags))for lag-based regression estimators.- output_chunk_length
Optionally, the number of output target time steps per chunk. Only required in scenarios B, and C. Corresponds to
output_chunk_lengthfor both chunk-based neural forecasting estimators, and lag-based regression estimators.- lags_covariates
Optionally, a list of integers giving the covariates lags used by lag-based forecasting estimators. Only required in scenario B. Corresponds to the lag values from
lags_past_covariatesfor past covariates, andlags_future_covariatesfor future covariates.
Members
generate_train_idxmethod
generate_train_idx(target: TimeSeries, covariates: TimeSeries | None = None) -> tuple[TimeIndex, pd.Timestamp]| Parameter | Type | Default |
|---|---|---|
target | TimeSeries | required |
covariates | TimeSeries | None | None |
Returns tuple[TimeIndex, pd.Timestamp]
generate_inference_idxmethod
generate_inference_idx(n: int, target: TimeSeries, covariates: TimeSeries | None = None) -> tuple[TimeIndex, pd.Timestamp]| Parameter | Type | Default |
|---|---|---|
n | int | required |
target | TimeSeries | required |
covariates | TimeSeries | None | None |
Returns tuple[TimeIndex, pd.Timestamp]
base_component_nameproperty
Inherited members
PastCovariatesIndexGenerator
PastCovariatesIndexGenerator(input_chunk_length: int | None = None, output_chunk_length: int | None = None, lags_covariates: list[int] | None = None)Bases: CovariatesIndexGenerator
Generates index for past covariates on train and inference datasets
| Parameter | Type | Default |
|---|---|---|
input_chunk_length | int | None | None |
output_chunk_length | int | None | None |
lags_covariates | list[int] | None | None |
anomx.data.processing.encoders.encoder_base.CovariatesIndexGenerator generates a time index for covariates at training and inference / prediction time with methods generate_train_idx(), and generate_inference_idx(). Without user covariates, it generates the minimum required covariate times spans for the corresponding scenarios described below. With user covariates, it simply copies and returns the covariates time index.
It can be used:
- in combination with local forecasting estimators, or in a model agnostic scenario: All parameters can be ignored. This scenario is only supported by
anomx.data.processing.encoders.encoder_base.FutureCovariatesIndexGenerator. - in combination with lag-based regression estimators: Set
input_chunk_length,output_chunk_length, andlags_covariates.input_chunk_lengthis the absolute value of the minimum target lagabs(min(lags))used with the lag-based regression estimator. Setoutput_chunk_length, andlags_covariateswith the identical values used at forecasting model creation. For the covariate lags, uselags_past_covariatesforanomx.data.processing.encoders.encoder_base.PastCovariatesIndexGenerator, andlags_future_covariatesforanomx.data.processing.encoders.encoder_base.FutureCovariatesIndexGenerator. - in combination with chunk-based neural forecasting estimators: Set
input_chunk_length, andoutput_chunk_lengthwith the identical values used at forecasting model creation.
Parameters
- input_chunk_length
Optionally, the number of input target time steps per chunk. Only required in scenarios B, C. Corresponds to
input_chunk_lengthfor chunk-based neural forecasting estimators, or to the absolute minimum target lag valueabs(min(lags))for lag-based regression estimators.- output_chunk_length
Optionally, the number of output target time steps per chunk. Only required in scenarios B, and C. Corresponds to
output_chunk_lengthfor both chunk-based neural forecasting estimators, and lag-based regression estimators.- lags_covariates
Optionally, a list of integers giving the covariates lags used by lag-based forecasting estimators. Only required in scenario B. Corresponds to the lag values from
lags_past_covariatesfor past covariates, andlags_future_covariatesfor future covariates.
Members
generate_train_idxmethod
generate_train_idx(target: TimeSeries, covariates: TimeSeries | None = None) -> tuple[TimeIndex, pd.Timestamp]| Parameter | Type | Default |
|---|---|---|
target | TimeSeries | required |
covariates | TimeSeries | None | None |
Returns tuple[TimeIndex, pd.Timestamp]
generate_inference_idxmethod
generate_inference_idx(n: int, target: TimeSeries, covariates: TimeSeries | None = None) -> tuple[TimeIndex, pd.Timestamp]| Parameter | Type | Default |
|---|---|---|
n | int | required |
target | TimeSeries | required |
covariates | TimeSeries | None | None |
Returns tuple[TimeIndex, pd.Timestamp]
base_component_nameproperty
Inherited members
SequentialEncoderTransformer
SequentialEncoderTransformer(transformer: FittableDataTransformer, transform_mask: list[bool])SequentialEncoderTransformer applies transformation to the non-transformed encoded covariates output of SequentialEncoder.encode_train() and SequentialEncoder.encode_inference(). The transformer is fitted when transform() is called for the first time. This ensures proper transformation of train, validation and inference dataset covariates. User-supplied covariates are not transformed.
| Parameter | Type | Default |
|---|---|---|
transformer | FittableDataTransformer | required |
transform_mask | list[bool] | required |
Parameters
- transformer
A
FittableDataTransformerobject with afit_transform()andtransform()method.- transform_mask
A boolean 1-D mask specifying which of the input covariates to
transform()must be transformed.
Members
transformmethod
transform(covariates: list[TimeSeries]) -> list[TimeSeries]This method applies transformation to the non-transformed encoded covariates output of SequentialEncoder._encode_sequence() after being merged with user-defined covariates. The transformer is fitted when transform() is called for the first time. This ensures proper transformation of train, validation and inference dataset covariates. The masks ensure that no covariates are transformed that user explicitly supplied to estimator.fit() and estimator.predict()
Parameters
- covariates
The non-transformed encoded covariates output of
SequentialEncoder._encode_sequence()before merging with user-defined covariates.
| Parameter | Type | Default |
|---|---|---|
covariates | list[TimeSeries] | required |
Returns list[TimeSeries]
fit_calledproperty
fit_called: boolReturn whether the transformer has been fitted.
Returns bool
SingleEncoder
SingleEncoder(index_generator: CovariatesIndexGenerator)Bases: Encoder, ABC
SingleEncoder: Abstract class for single index encoders. Single encoders can be used to implement new encoding techniques. Each single encoder must implement an _encode() method that carries the encoding logic.
The _encode() method must take an index as input and generate a encoded single TimeSeries as output.
| Parameter | Type | Default |
|---|---|---|
index_generator | CovariatesIndexGenerator | required |
Single encoders take an index_generator to generate the required index for encoding past and future covariates. See anomx._series_utils.data.covariate_index_generators.py for the CovariatesIndexGenerator subclasses. For past covariates encoders, use a PastCovariatesIndexGenerator. For future covariates encoders use a FutureCovariatesIndexGenerator.
Parameters
- index_generator
An instance of
CovariatesIndexGeneratorwith methodsgenerate_train_idx()andgenerate_inference_idx(). Used to generate the index for encoders.
Members
encode_trainmethod
encode_train(target: TimeSeries, covariates: TimeSeries | None = None, merge_covariates: bool = True, **kwargs) -> TimeSeriesReturns encoded index for training.
Parameters
- target
The target TimeSeries used during training or passed to prediction as
series- covariates
Optionally, the covariates used for training: past covariates if
self.index_generatoris aPastCovariatesIndexGenerator, future covariates ifself.index_generatoris aFutureCovariatesIndexGenerator- merge_covariates
Whether to merge the encoded TimeSeries with
covariates.
| Parameter | Type | Default |
|---|---|---|
target | TimeSeries | required |
covariates | TimeSeries | None | None |
merge_covariates | bool | True |
**kwargs | — | — |
Returns TimeSeries
encode_inferencemethod
encode_inference(n: int, target: TimeSeries, covariates: TimeSeries | None = None, merge_covariates: bool = True, **kwargs) -> TimeSeriesReturns encoded index for inference/prediction.
Parameters
- n
The forecast horizon
- target
The target TimeSeries used during training or passed to prediction as
series- covariates
Optionally, the covariates used for prediction: past covariates if
self.index_generatoris aPastCovariatesIndexGenerator, future covariates ifself.index_generatoris aFutureCovariatesIndexGenerator- merge_covariates
Whether to merge the encoded TimeSeries with
covariates.
| Parameter | Type | Default |
|---|---|---|
n | int | required |
target | TimeSeries | required |
covariates | TimeSeries | None | None |
merge_covariates | bool | True |
**kwargs | — | — |
Returns TimeSeries
encode_train_inferencemethod
encode_train_inference(n: int, target: TimeSeries, covariates: TimeSeries | None = None, merge_covariates: bool = True, **kwargs) -> TimeSeriesReturns encoded index for inference/prediction.
Parameters
- n
The forecast horizon
- target
The target TimeSeries used during training and prediction.
- covariates
Optionally, the covariates used for training and prediction: past covariates if
self.index_generatoris aPastCovariatesIndexGenerator, future covariates ifself.index_generatoris aFutureCovariatesIndexGenerator- merge_covariates
Whether to merge the encoded TimeSeries with
covariates.
| Parameter | Type | Default |
|---|---|---|
n | int | required |
target | TimeSeries | required |
covariates | TimeSeries | None | None |
merge_covariates | bool | True |
**kwargs | — | — |
Returns TimeSeries
accept_transformerproperty
accept_transformer: list[bool]Whether the SingleEncoder sub class accepts to be transformed.
Returns list[bool]
encoding_n_componentsproperty
componentsproperty
components: pd.IndexReturns the encoded component names. Only available after Encoder.encode_train() or Encoder.encode_inference() have been called.
Returns pd.Index
base_component_nameproperty
base_component_name: strReturns the base encoder base component name. The string follows the given format: "anomx_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")
Returns str