actableai.timeseries.models package

Submodules

actableai.timeseries.models.base module

class actableai.timeseries.models.base.AAITimeSeriesBaseModel(prediction_length: int)

Bases: abc.ABC

Time Series Model interface.

abstract fit(dataset: actableai.timeseries.dataset.AAITimeSeriesDataset, model_params: List[actableai.timeseries.models.params.base.BaseParams], *, mx_ctx: Optional[mxnet.context.Context] = cpu(0), loss: str = 'mean_wQuantileLoss', trials: int = 1, max_concurrent: Optional[int] = 1, use_ray: bool = True, tune_samples: int = 3, sampling_method: str = 'random', random_state: Optional[int] = None, ray_tune_kwargs: Optional[Dict[str, Any]] = None, verbose: int = 1, fit_full: bool = True) Tuple[float, pandas.core.frame.DataFrame]

Tune and fit the model.

Parameters
  • dataset – Dataset containing the time series.
  • model_params – List of models parameters to run the tuning search on.
  • mx_ctx – mxnet context, CPU by default.
  • loss – Loss to minimize when tuning.
  • trials – Number of trials for hyperparameter search.
  • max_concurrent – Maximum number of concurrent ray task.
  • use_ray – If True ray will be used for hyperparameter tuning.
  • tune_samples – Number of dataset samples to use when tuning.
  • sampling_method – Method used when extracting the samples for the tuning [“random”, “last”].
  • random_state – Random state to use for reproducibility.
  • ray_tune_kwargs – Named parameters to pass to ray’s tune function.
  • verbose – Verbose level.
  • fit_full – If True the model will be fit after tuning using all the data (tuning data).
Returns

  • Total time spent for tuning.
  • Leaderboard

abstract predict(dataset: actableai.timeseries.dataset.AAITimeSeriesDataset, quantiles: List[float] = [0.05, 0.5, 0.95]) Dict[Tuple[Any, ...], pandas.core.frame.DataFrame]

Make a prediction using the model.

Parameters
  • dataset – Dataset containing the time series.
  • quantiles – Quantiles to predict.
Raises

UntrainedModelException – If the model has not been trained/tuned before.

Returns

Dictionary containing the predicted time series for each group.

abstract refit(dataset: actableai.timeseries.dataset.AAITimeSeriesDataset, mx_ctx: Optional[mxnet.context.Context] = cpu(0))

Fit previously tuned model.

Parameters
  • dataset – Dataset containing the time series.
  • mx_ctx – mxnet context, CPU by default.
Raises

UntrainedModelException – If the model has not been trained/tuned before.

abstract score(dataset: actableai.timeseries.dataset.AAITimeSeriesDataset, num_samples: int = 100, quantiles: List[float] = [0.05, 0.5, 0.95], num_workers: Optional[int] = None) Tuple[Dict[Tuple[Any, ...], pandas.core.frame.DataFrame], Dict[Tuple[Any, ...], pandas.core.frame.DataFrame], pandas.core.frame.DataFrame]

Evaluate model.

Parameters
  • dataset – Dataset containing the time series.
  • num_samples – Number of dataset samples to use for evaluation
  • quantiles – List of quantiles to use for evaluation.
  • num_workers – Maximum number of workers to use, if None no parallelization will be done.
Raises

UntrainedModelException – If the model has not been trained/tuned before.

Returns

  • Dictionary containing the predicted time series for each group.
  • Dictionary containing the metrics for each target for each group.
  • Dataframe containing the aggregated metrics for each target.

actableai.timeseries.models.estimator module

class actableai.timeseries.models.estimator.AAITimeSeriesEstimator(estimator: gluonts.model.estimator.Estimator, transformation: Optional[actableai.timeseries.transform.base.Transformation] = None)

Bases: object

Custom Wrapper around GluonTS Estimator.

train(dataset: actableai.timeseries.dataset.AAITimeSeriesDataset) actableai.timeseries.models.predictor.AAITimeSeriesPredictor

Train estimator.

Parameters
dataset – Training data.
Returns
GluonTS trained predictor.

actableai.timeseries.models.evaluator module

class actableai.timeseries.models.evaluator.AAITimeSeriesEvaluator(*, target_columns: List[str], group_list: Optional[List[Tuple[Any, ...]]] = None, **kwargs)

Bases: object

Custom Wrapper around GluonTS Evaluator.

actableai.timeseries.models.forecaster module

class actableai.timeseries.models.forecaster.AAITimeSeriesForecaster(date_column: str, target_columns: List[str], prediction_length: int, seasonal_periods: Optional[List[int]] = None, group_by: Optional[List[str]] = None, feature_columns: Optional[List[str]] = None)

Bases: actableai.models.base.AAIBaseModel[pandas.core.frame.DataFrame, pandas.core.frame.DataFrame], abc.ABC

Time Series Forecaster Model.

fit(model_params: List[actableai.timeseries.models.params.base.BaseParams], *, df: Optional[pandas.core.frame.DataFrame] = None, dataset: Optional[actableai.timeseries.dataset.AAITimeSeriesDataset] = None, mx_ctx: Optional[mxnet.context.Context] = cpu(0), loss: str = 'mean_wQuantileLoss', trials: int = 1, max_concurrent: Optional[int] = 1, use_ray: bool = True, tune_samples: int = 3, sampling_method: str = 'random', random_state: Optional[int] = None, ray_tune_kwargs: Optional[Dict[str, Any]] = None, verbose: int = 1, fit_full: bool = True) Tuple[float, pandas.core.frame.DataFrame]

Tune and fit the model.

Parameters
  • model_params – List of models parameters to run the tuning search on.
  • df – Input DataFrame. If None group_df_dict, freq, and group_label_dict must be provided.
  • dataset – Dataset containing the time series. If None df must be provided.
  • mx_ctx – mxnet context, CPU by default.
  • loss – Loss to minimize when tuning.
  • trials – Number of trials for hyperparameter search.
  • max_concurrent – Maximum number of concurrent ray task.
  • use_ray – If True ray will be used for hyperparameter tuning.
  • tune_samples – Number of dataset samples to use when tuning.
  • sampling_method – Method used when extracting the samples for the tuning [“random”, “last”].
  • random_state – Random state to use for reproducibility.
  • ray_tune_kwargs – Named parameters to pass to ray’s tune function.
  • verbose – Verbose level.
  • fit_full – If True the model will be fit after tuning using all the data (tuning data).
Returns

  • Total time spent for tuning.
  • Leaderboard

has_fit: bool = False
has_predict: bool = True
classmethod pre_process_data(df: pandas.core.frame.DataFrame, date_column: str, target_columns: List[str], prediction_length: int, seasonal_periods: Optional[List[int]] = None, feature_columns: Optional[List[str]] = None, group_by: Optional[List[str]] = None, inplace: bool = True, freq: Optional[str] = None) actableai.timeseries.dataset.AAITimeSeriesDataset

Pre-process dataframe, handle datetime, and return a PandasDataset.

Parameters
  • df – Input DataFrame
  • date_column – Column containing the date/datetime/time component of the time series.
  • target_columns – List of columns to forecast, if None all the columns will be selected.
  • prediction_length – Length of the prediction to forecast.
  • seasonal_periods – List of seasonal periods (seasonality).
  • feature_columns – List of columns containing extraneous features used to forecast.
  • group_by – List of columns to use to separate different time series/groups.
  • inplace – If True this function will modify the original DataFrame.
Returns

  • Dictionary containing the time series for each group.
  • Dictionary containing the frequency of each group.

predict(*, df: Optional[pandas.core.frame.DataFrame] = None, dataset: Optional[actableai.timeseries.dataset.AAITimeSeriesDataset] = None, quantiles: List[float] = [0.05, 0.5, 0.95]) pandas.core.frame.DataFrame

Make a prediction using the model.

Parameters
  • df – Input DataFrame. If None group_df_dict must be provided.
  • dataset – Dataset containing the time series. If None df must be provided.
  • quantiles – Quantiles to predict.
Raises

UntrainedModelException – If the model has not been trained/tuned before.

Returns

Predicted time series.

refit(*, df: Optional[pandas.core.frame.DataFrame] = None, dataset: Optional[actableai.timeseries.dataset.AAITimeSeriesDataset] = None, mx_ctx: Optional[mxnet.context.Context] = cpu(0))

Fit previously tuned model.

Parameters
  • df – Input DataFrame. If None group_df_dict must be provided.
  • dataset – Dataset containing the time series. If None df must be provided.
  • mx_ctx – mxnet context, CPU by default.
Raises

UntrainedModelException – If the model has not been trained/tuned before.

score(*, df: Optional[pandas.core.frame.DataFrame] = None, dataset: Optional[actableai.timeseries.dataset.AAITimeSeriesDataset] = None, num_samples: int = 100, quantiles: List[float] = [0.05, 0.5, 0.95], num_workers: Optional[int] = None) Tuple[pandas.core.frame.DataFrame, pandas.core.frame.DataFrame, pandas.core.frame.DataFrame]

Evaluate model.

Parameters
  • df – Input DataFrame. If None group_df_dict must be provided.
  • dataset – Dataset containing the time series. If None df must be provided.
  • num_samples – Number of dataset samples to use for evaluation
  • quantiles – List of quantiles to use for evaluation.
  • num_workers – Maximum number of workers to use, if None no parallelization will be done.
Raises

UntrainedModelException – If the model has not been trained/tuned before.

Returns

  • Predicted time series.
  • Metrics for each target and groups.
  • Aggregated metrics for each target.

class actableai.timeseries.models.forecaster.TsForecastInference(model: actableai.models.inference.ModelType)

Bases: actableai.models.inference.AAIBaseModelInference[actableai.timeseries.models.forecaster.AAITimeSeriesForecaster, actableai.timeseries.models.forecaster.TsForecastMetadata]

class actableai.timeseries.models.forecaster.TsForecastMetadata(*, date_column: str, features: List[str], prediction_targets: List[str], freq: str)

Bases: actableai.models.inference.AAIBaseModelMetadata

date_column: str
features: List[str]
freq: str
prediction_targets: List[str]

actableai.timeseries.models.independent_multivariate_model module

class actableai.timeseries.models.independent_multivariate_model.AAITimeSeriesIndependentMultivariateModel(prediction_length: int)

Bases: actableai.timeseries.models.base.AAITimeSeriesBaseModel

Multi-Target Time Series Model, can be used for univariate and multivariate forecasting. It will internally use one AAITimeSeriesSingleModel for each target, using the other target as features for every model.

It also keeps a multivariate model internally, and use it if the performances for one specific column are better.

fit(dataset: actableai.timeseries.dataset.AAITimeSeriesDataset, model_params: List[actableai.timeseries.models.params.base.BaseParams], *, mx_ctx: Optional[mxnet.context.Context] = cpu(0), loss: str = 'mean_wQuantileLoss', trials: int = 1, max_concurrent: Optional[int] = 1, use_ray: bool = True, tune_samples: int = 3, sampling_method: str = 'random', random_state: Optional[int] = None, ray_tune_kwargs: Optional[Dict[str, Any]] = None, verbose: int = 1, fit_full: bool = True) Tuple[float, pandas.core.frame.DataFrame]

Tune and fit the model.

Parameters
  • dataset – Dataset containing the time series.
  • model_params – List of models parameters to run the tuning search on.
  • mx_ctx – mxnet context, CPU by default.
  • loss – Loss to minimize when tuning.
  • trials – Number of trials for hyperparameter search.
  • max_concurrent – Maximum number of concurrent ray task.
  • use_ray – If True ray will be used for hyperparameter tuning.
  • tune_samples – Number of dataset samples to use when tuning.
  • sampling_method – Method used when extracting the samples for the tuning [“random”, “last”].
  • random_state – Random state to use for reproducibility.
  • ray_tune_kwargs – Named parameters to pass to ray’s tune function.
  • verbose – Verbose level.
  • fit_full – If True the model will be fit after tuning using all the data (tuning data).
Returns

  • Total time spent for tuning.
  • Leaderboard

predict(dataset: actableai.timeseries.dataset.AAITimeSeriesDataset, quantiles: List[float] = [0.05, 0.5, 0.95]) Dict[Tuple[Any, ...], pandas.core.frame.DataFrame]

Make a prediction using the model.

Parameters
  • dataset – Dataset containing the time series.
  • quantiles – Quantiles to predict.
Raises

UntrainedModelException – If the model has not been trained/tuned before.

Returns

Dictionary containing the predicted time series for each group.

refit(dataset: actableai.timeseries.dataset.AAITimeSeriesDataset, mx_ctx: Optional[mxnet.context.Context] = cpu(0))

Fit previously tuned model.

Parameters
  • dataset – Dataset containing the time series.
  • mx_ctx – mxnet context, CPU by default.
Raises

UntrainedModelException – If the model has not been trained/tuned before.

score(dataset: actableai.timeseries.dataset.AAITimeSeriesDataset, num_samples: int = 100, quantiles: List[float] = [0.05, 0.5, 0.95], num_workers: Optional[int] = None) Tuple[Dict[Tuple[Any, ...], pandas.core.frame.DataFrame], Dict[Tuple[Any, ...], pandas.core.frame.DataFrame], pandas.core.frame.DataFrame]

Evaluate model.

Parameters
  • dataset – Dataset containing the time series.
  • num_samples – Number of dataset samples to use for evaluation
  • quantiles – List of quantiles to use for evaluation.
  • num_workers – Maximum number of workers to use, if None no parallelization will be done.
Raises

UntrainedModelException – If the model has not been trained/tuned before.

Returns

  • Dictionary containing the predicted time series for each group.
  • Dictionary containing the metrics for each target for each group.
  • Dataframe containing the aggregated metrics for each target.

actableai.timeseries.models.predictor module

class actableai.timeseries.models.predictor.AAITimeSeriesPredictor(predictor: gluonts.model.predictor.Predictor, transformation: Optional[actableai.timeseries.transform.base.Transformation] = None)

Bases: object

Custom Wrapper around GluonTS Predictor.

make_evaluation_predictions(dataset: actableai.timeseries.dataset.AAITimeSeriesDataset, num_samples: int) Tuple[Iterable[actableai.timeseries.forecast.AAITimeSeriesForecast], Iterable[Union[pandas.core.frame.DataFrame, pandas.core.series.Series]]]

Wrapper around the GluonTS make_evaluation_predictions function.

Parameters
  • dataset – Data used for evaluation.
  • num_samples – Number of samples to draw on the model when evaluating.
Returns

  • Iterator containing the evaluation forecasts.
  • Iterator containing the original sampled time series.

predict(dataset: actableai.timeseries.dataset.AAITimeSeriesDataset, **kwargs) Iterable[actableai.timeseries.forecast.AAITimeSeriesForecast]

Run prediction.

Parameters
dataset – Data used for prediction.
Returns
Predictions results

actableai.timeseries.models.single_model module

class actableai.timeseries.models.single_model.AAITimeSeriesSingleModel(prediction_length: int)

Bases: actableai.timeseries.models.base.AAITimeSeriesBaseModel

Simple Time Series Model,

fit(dataset: actableai.timeseries.dataset.AAITimeSeriesDataset, model_params: List[actableai.timeseries.models.params.base.BaseParams], *, mx_ctx: Optional[mxnet.context.Context] = cpu(0), loss: str = 'mean_wQuantileLoss', trials: int = 1, max_concurrent: Optional[int] = 1, use_ray: bool = True, tune_samples: int = 3, sampling_method: str = 'random', random_state: Optional[int] = None, ray_tune_kwargs: Optional[Dict[str, Any]] = None, verbose: int = 1, fit_full: bool = True) Tuple[float, pandas.core.frame.DataFrame]

Tune and fit the model.

Parameters
  • dataset – Dataset containing the time series.
  • model_params – List of models parameters to run the tuning search on.
  • mx_ctx – mxnet context, CPU by default.
  • loss – Loss to minimize when tuning.
  • trials – Number of trials for hyperparameter search.
  • max_concurrent – Maximum number of concurrent ray task.
  • use_ray – If True ray will be used for hyperparameter tuning.
  • tune_samples – Number of dataset samples to use when tuning.
  • sampling_method – Method used when extracting the samples for the tuning [“random”, “last”].
  • random_state – Random state to use for reproducibility.
  • ray_tune_kwargs – Named parameters to pass to ray’s tune function.
  • verbose – Verbose level.
  • fit_full – If True the model will be fit after tuning using all the data (tuning data).
Returns

  • Total time spent for tuning.
  • Leaderboard

predict(dataset: actableai.timeseries.dataset.AAITimeSeriesDataset, quantiles: List[float] = [0.05, 0.5, 0.95]) Dict[Tuple[Any, ...], pandas.core.frame.DataFrame]

Make a prediction using the model.

Parameters
  • dataset – Dataset containing the time series.
  • quantiles – Quantiles to predict.
Raises

UntrainedModelException – If the model has not been trained/tuned before.

Returns

Dictionary containing the predicted time series for each group.

refit(dataset: actableai.timeseries.dataset.AAITimeSeriesDataset, mx_ctx: Optional[mxnet.context.Context] = cpu(0))

Fit previously tuned model.

Parameters
  • dataset – Dataset containing the time series.
  • mx_ctx – mxnet context, CPU by default.
Raises

UntrainedModelException – If the model has not been trained/tuned before.

score(dataset: actableai.timeseries.dataset.AAITimeSeriesDataset, num_samples: int = 100, quantiles: List[float] = [0.05, 0.5, 0.95], num_workers: Optional[int] = None) Tuple[Dict[Tuple[Any, ...], pandas.core.frame.DataFrame], Dict[Tuple[Any, ...], pandas.core.frame.DataFrame], pandas.core.frame.DataFrame]

Evaluate model.

Parameters
  • dataset – Dataset containing the time series.
  • num_samples – Number of dataset samples to use for evaluation
  • quantiles – List of quantiles to use for evaluation.
  • num_workers – Maximum number of workers to use, if None no parallelization will be done.
Raises

UntrainedModelException – If the model has not been trained/tuned before.

Returns

  • Dictionary containing the predicted time series for each group.
  • Dictionary containing the metrics for each target for each group.
  • Dataframe containing the aggregated metrics for each target.

Module contents