actableai.timeseries.transform package

Submodules

actableai.timeseries.transform.base module

class actableai.timeseries.transform.base.ArrayTransformation

Bases: actableai.timeseries.transform.base.MapTransformation

Base class for Transformations than are applied on numpy array.

map_revert_forecast(forecast: gluonts.model.forecast.Forecast, group: Tuple[Any, ...]) gluonts.model.forecast.Forecast

Revert a transformation on a forecast.

Parameters
  • forecast – Forecast to revert.
  • group – Forecast’s group.
Returns

The transformed forecast.

map_revert_time_series(data: Union[pandas.core.frame.DataFrame, pandas.core.series.Series], group: Tuple[Any, ...]) Union[pandas.core.frame.DataFrame, pandas.core.series.Series]

Revert a transformation on a time series.

Parameters
  • data – Time series to revert.
  • group – Time series group.
Returns

The transformed time series.

map_transform(data: Dict[str, Any], group: Tuple[Any, ...]) Dict[str, Any]

Transform a data entry.

Parameters
  • data – Data entry to revert.
  • group – Data entry’s group.
Returns

The transformed data entry.

revert_array(array: numpy.ndarray, start_date: pandas._libs.tslibs.period.Period, group: Tuple[Any, ...]) numpy.ndarray

Revert a transformation on an array.

Parameters
  • array – Array to revert.
  • start_date – Starting date of the array (in the time series context).
  • group – Array’s group.
Returns

The transformed array.

abstract transform_array(array: numpy.ndarray, start_date: pandas._libs.tslibs.period.Period, group: Tuple[Any, ...]) numpy.ndarray

Transform an array.

Parameters
  • array – Array to transform.
  • start_date – Starting date of the array (in the time series context).
  • group – Array’s group.
Returns

The transformed array.

class actableai.timeseries.transform.base.Chain(transformations: List[actableai.timeseries.transform.base.Transformation], is_flattenable: bool = True)

Bases: actableai.timeseries.transform.base.Transformation

Chain multiple transformations together.

revert_forecasts(forecast_it: Iterable[gluonts.model.forecast.Forecast]) Iterable[gluonts.model.forecast.Forecast]

Revert a transformation on forecasts.

Parameters
forecast_it – Iterable object of forecasts.
Returns
Iterable object of transformed forecasts.
revert_time_series(data_it: Iterable[Union[pandas.core.frame.DataFrame, pandas.core.series.Series]]) Iterable[Union[pandas.core.frame.DataFrame, pandas.core.series.Series]]

Revert a transformation on time series.

Parameters
data_it – Iterable object of time series.
Returns
Iterable object of transformed time series.
transform(data_it: Iterable[Dict[str, Any]]) Iterable[Dict[str, Any]]

Transform data entries.

Parameters
data_it – Iterable object of data entries.
Returns
Iterable object of transformed data entries.
class actableai.timeseries.transform.base.MapTransformation

Bases: actableai.timeseries.transform.base.Transformation

Base class for Transformations that returns exactly one result per input in the
stream.
map_revert_forecast(forecast: gluonts.model.forecast.Forecast, group: Tuple[Any, ...]) gluonts.model.forecast.Forecast

Revert a transformation on a forecast.

Parameters
  • forecast – Forecast to revert.
  • group – Forecast’s group.
Returns

The transformed forecast.

map_revert_time_series(data: Union[pandas.core.frame.DataFrame, pandas.core.series.Series], group: Tuple[Any, ...]) Union[pandas.core.frame.DataFrame, pandas.core.series.Series]

Revert a transformation on a time series.

Parameters
  • data – Time series to revert.
  • group – Time series group.
Returns

The transformed time series.

abstract map_transform(data: Dict[str, Any], group: Tuple[Any, ...]) Dict[str, Any]

Transform a data entry.

Parameters
  • data – Data entry to revert.
  • group – Data entry’s group.
Returns

The transformed data entry.

revert_forecasts(forecast_it: Iterable[gluonts.model.forecast.Forecast]) Iterable[gluonts.model.forecast.Forecast]

Revert a transformation on forecasts.

Parameters
forecast_it – Iterable object of forecasts.
Returns
Iterable object of transformed forecasts.
revert_time_series(data_it: Iterable[Union[pandas.core.frame.DataFrame, pandas.core.series.Series]]) Iterable[Union[pandas.core.frame.DataFrame, pandas.core.series.Series]]

Revert a transformation on time series.

Parameters
data_it – Iterable object of time series.
Returns
Iterable object of transformed time series.
transform(data_it: Iterable[Dict[str, Any]]) Iterable[Dict[str, Any]]

Transform data entries.

Parameters
data_it – Iterable object of data entries.
Returns
Iterable object of transformed data entries.
class actableai.timeseries.transform.base.Transformation

Bases: object

Base class for all Transformations.

chain(other: actableai.timeseries.transform.base.Transformation) Union[actableai.timeseries.transform.base.Transformation, actableai.timeseries.transform.base.Chain]

Chain transformation with the current transformation.

Parameters
other – Other transformation to apply.
Returns
The chain of transformation containing the current one and the other.
revert_forecasts(forecast_it: Iterable[gluonts.model.forecast.Forecast]) Iterable[gluonts.model.forecast.Forecast]

Revert a transformation on forecasts.

Parameters
forecast_it – Iterable object of forecasts.
Returns
Iterable object of transformed forecasts.
revert_time_series(data_it: Iterable[Union[pandas.core.frame.DataFrame, pandas.core.series.Series]]) Iterable[Union[pandas.core.frame.DataFrame, pandas.core.series.Series]]

Revert a transformation on time series.

Parameters
data_it – Iterable object of time series.
Returns
Iterable object of transformed time series.
setup(dataset: actableai.timeseries.dataset.AAITimeSeriesDataset)

Set up the transformation with a dataset.

Parameters
dataset – Dataset to set up the transformation with.
abstract transform(data_it: Iterable[Dict[str, Any]]) Iterable[Dict[str, Any]]

Transform data entries.

Parameters
data_it – Iterable object of data entries.
Returns
Iterable object of transformed data entries.

actableai.timeseries.transform.clean_features module

class actableai.timeseries.transform.clean_features.CleanFeatures(keep_feat_static_real: bool = True, keep_feat_static_cat: bool = True, keep_feat_dynamic_real: bool = True, keep_feat_dynamic_cat: bool = True)

Bases: actableai.timeseries.transform.base.MapTransformation

Transformation that clean features from dataset.

map_transform(data: Dict[str, Any], group: Tuple[Any, ...]) Dict[str, Any]

Transform a data entry.

Parameters
  • data – Data entry to revert.
  • group – Data entry’s group.
Returns

The transformed data entry.

actableai.timeseries.transform.deseasonalizing module

class actableai.timeseries.transform.deseasonalizing.Deseasonalizing(seasonal_period: int)

Bases: actableai.timeseries.transform.base.ArrayTransformation

Remove seasonality.

Will compute the mean of all the values over a specified period of time. This mean values represent what is called the seasonality component. This transformation consists in removing this component from the time series.

For a more accurate representation of the seasonality it is advised to run a PowerTransformation and Detrend transformation beforehand.

revert_array(array: numpy.ndarray, start_date: pandas._libs.tslibs.period.Period, group: Tuple[Any, ...]) numpy.ndarray

Revert a transformation on an array.

Parameters
  • array – Array to revert.
  • start_date – Starting date of the array (in the time series context).
  • group – Array’s group.
Returns

The transformed array.

transform_array(array: numpy.ndarray, start_date: pandas._libs.tslibs.period.Period, group: Tuple[Any, ...]) numpy.ndarray

Transform an array.

Parameters
  • array – Array to transform.
  • start_date – Starting date of the array (in the time series context).
  • group – Array’s group.
Returns

The transformed array.

class actableai.timeseries.transform.deseasonalizing.MultiDeseasonalizing

Bases: actableai.timeseries.transform.base.Chain

Remove multiple seasonality.

actableai.timeseries.transform.detrend module

class actableai.timeseries.transform.detrend.Detrend

Bases: actableai.timeseries.transform.base.ArrayTransformation

Detrend transformation using model fitting.

The trend is computed using a simple Linear Regression. This transformation computes the trend and subtracts it from the time series. Since it is a simple Linear Regression this transformation does not handle multiple trends.

revert_array(array: numpy.ndarray, start_date: pandas._libs.tslibs.period.Period, group: Tuple[Any, ...]) numpy.ndarray

Revert a transformation on an array.

Parameters
  • array – Array to revert.
  • start_date – Starting date of the array (in the time series context).
  • group – Array’s group.
Returns

The transformed array.

transform_array(array: numpy.ndarray, start_date: pandas._libs.tslibs.period.Period, group: Tuple[Any, ...]) numpy.ndarray

Transform an array.

Parameters
  • array – Array to transform.
  • start_date – Starting date of the array (in the time series context).
  • group – Array’s group.
Returns

The transformed array.

actableai.timeseries.transform.identity module

class actableai.timeseries.transform.identity.Identity

Bases: actableai.timeseries.transform.base.Transformation

Identity transformation (no transformation).

transform(data_it: Iterable[Dict[str, Any]]) Iterable[Dict[str, Any]]

Transform data entries.

Parameters
data_it – Iterable object of data entries.
Returns
Iterable object of transformed data entries.

actableai.timeseries.transform.power_transformation module

class actableai.timeseries.transform.power_transformation.PowerTransformation

Bases: actableai.timeseries.transform.base.ArrayTransformation

Power transformation.

This transformation will have for effect to make the data more Gaussian-like. see: https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.PowerTransformer.html

revert_array(array: numpy.ndarray, start_date: pandas._libs.tslibs.period.Period, group: Tuple[Any, ...]) numpy.ndarray

Revert a transformation on an array.

Parameters
  • array – Array to revert.
  • start_date – Starting date of the array (in the time series context).
  • group – Array’s group.
Returns

The transformed array.

transform_array(array: numpy.ndarray, start_date: pandas._libs.tslibs.period.Period, group: Tuple[Any, ...]) numpy.ndarray

Transform an array.

Parameters
  • array – Array to transform.
  • start_date – Starting date of the array (in the time series context).
  • group – Array’s group.
Returns

The transformed array.

Module contents