gluonts.transform.feature module#
- class gluonts.transform.feature.AddAgeFeature(target_field: str, output_field: str, pred_length: int, log_scale: bool = True, dtype: typing.Type = <class 'numpy.float32'>)[source]#
Bases:
gluonts.transform._base.MapTransformation
Adds an ‘age’ feature to the data_entry.
The age feature starts with a small value at the start of the time series and grows over time.
If is_train=True the age feature has the same length as the target field. If is_train=False the age feature has length len(target) + pred_length
- Parameters
target_field – Field with target values (array) of time series
output_field – Field name to use for the output.
pred_length – Prediction length
log_scale – If set to true the age feature grows logarithmically otherwise linearly over time.
- class gluonts.transform.feature.AddAggregateLags(target_field: str, output_field: str, pred_length: int, base_freq: str, agg_freq: str, agg_lags: typing.List[int], agg_fun: str = 'mean', dtype: typing.Type = <class 'numpy.float32'>)[source]#
Bases:
gluonts.transform._base.MapTransformation
Adds aggregate lags as a feature to the data_entry.
Aggregates the original time series to a new frequency and selects the aggregated lags of interest. It does not use aggregate lags that need the last prediction_length values to be computed. Therefore the transformation is applicable to both training and inference.
If is_train=True the lags have the same length as the target field. If is_train=False the lags have length len(target) + pred_length
- Parameters
target_field – Field with target values (array) of time series
output_field – Field name to use for the output.
pred_length – Prediction length.
base_freq – Base frequency, i.e., the frequency of the original time series.
agg_freq – Aggregate frequency, i.e., the frequency of the aggregate time series.
agg_lags – List of aggregate lags given in the aggregate frequency. If some of them are invalid (need some of the last prediction_length values to be computed) they are ignored.
agg_fun – Aggregation function. Default is ‘mean’.
- class gluonts.transform.feature.AddConstFeature(output_field: str, target_field: str, pred_length: int, const: float = 1.0, dtype: typing.Type = <class 'numpy.float32'>)[source]#
Bases:
gluonts.transform._base.MapTransformation
Expands a const value along the time axis as a dynamic feature, where the T-dimension is defined as the sum of the pred_length parameter and the length of a time series specified by the target_field.
If is_train=True the feature matrix has the same length as the target field. If is_train=False the feature matrix has length len(target) + pred_length.
- Parameters
output_field – Field name for output.
target_field – Field containing the target array. The length of this array will be used.
pred_length – Prediction length (this is necessary since features have to be available in the future)
const – Constant value to use.
dtype – Numpy dtype to use for resulting array.
- class gluonts.transform.feature.AddObservedValuesIndicator(target_field: str, output_field: str, imputation_method: typing.Optional[gluonts.transform.feature.MissingValueImputation] = gluonts.transform.feature.DummyValueImputation(dummy_value=0.0), dtype: typing.Type = <class 'numpy.float32'>)[source]#
Bases:
gluonts.transform._base.SimpleTransformation
Replaces missing values in a numpy array (NaNs) with a dummy value and adds an “observed”-indicator that is
1
when values are observed and0
when values are missing.- Parameters
target_field – Field for which missing values will be replaced
output_field – Field name to use for the indicator
imputation_method – One of the methods from ImputationStrategy. If set to None, no imputation is done and only the indicator is included.
- class gluonts.transform.feature.AddTimeFeatures(start_field: str, target_field: str, output_field: str, time_features: typing.List[typing.Callable[[pandas.core.indexes.period.PeriodIndex], numpy.ndarray]], pred_length: int, dtype: typing.Type = <class 'numpy.float32'>)[source]#
Bases:
gluonts.transform._base.MapTransformation
Adds a set of time features.
If is_train=True the feature matrix has the same length as the target field. If is_train=False the feature matrix has length len(target) + pred_length
- Parameters
start_field – Field with the start time stamp of the time series
target_field – Field with the array containing the time series values
output_field – Field name for result.
time_features – list of time features to use.
pred_length – Prediction length
- class gluonts.transform.feature.CausalMeanValueImputation[source]#
Bases:
gluonts.transform.feature.MissingValueImputation
This class replaces each missing value with the average of all the values up to this point.
(If the first values are missing, they are replaced by the closest non missing value.)
- class gluonts.transform.feature.CountTrailingZeros(new_field: str = 'trailing_zeros', target_field: str = 'target', axis: int = - 1, as_array: bool = False)[source]#
Bases:
gluonts.transform._base.SimpleTransformation
Add the number of ‘trailing’ zeros in each univariate time series as a feature, to be used when dealing with sparse (intermittent) time series.
For example, for 1-d a time series [0, 0, 2, 3, 0], the number of trailing zeros will be 1. If an n-dimensional array is provided, the first 1-d array along the axis dimension will be checked for trailing zeros. For example, if axis is set to 1 for a 3-d array A, the transformation will return the number of trailing zeros in A[0, :, 0].
- Parameters
new_field – Name of the new field to be created, which will contain the number of trailing zeros.
target_field – Field with target values (array) of time series
as_array – if True, the returned field will be a numpy array of shape (1,)
- class gluonts.transform.feature.DummyValueImputation(dummy_value: float = 0.0)[source]#
Bases:
gluonts.transform.feature.MissingValueImputation
This class replaces all the missing values with the same dummy value given in advance.
- class gluonts.transform.feature.LastValueImputation[source]#
Bases:
gluonts.transform.feature.MissingValueImputation
This class replaces each missing value with the last value that was not missing.
(If the first values are missing, they are replaced by the closest non missing value.)
- class gluonts.transform.feature.LeavesMissingValues[source]#
Bases:
gluonts.transform.feature.MissingValueImputation
Just leaves the missing values untouched.
- class gluonts.transform.feature.MeanValueImputation[source]#
Bases:
gluonts.transform.feature.MissingValueImputation
This class replaces all the missing values with the mean of the non missing values.
Careful this is not a ‘causal’ method in the sense that it leaks information about the furture in the imputation. You may prefer to use CausalMeanValueImputation instead.
- class gluonts.transform.feature.MissingValueImputation[source]#
Bases:
object
The parent class for all the missing value imputation classes.
You can just implement your own inheriting this class.
- class gluonts.transform.feature.RollingMeanValueImputation(window_size: int = 10)[source]#
Bases:
gluonts.transform.feature.MissingValueImputation
This class replaces each missing value with the average of all the last window_size (default=10) values.
(If the first values are missing, they are replaced by the closest non missing value.)