Table Of Contents
Table Of Contents

gluonts.model.predictor module

class gluonts.model.predictor.FallbackPredictor(prediction_length: int, freq: str)[source]

Bases: gluonts.model.predictor.Predictor

classmethod from_predictor(base: gluonts.model.predictor.RepresentablePredictor, **overrides) → gluonts.model.predictor.Predictor[source]
class gluonts.model.predictor.GluonPredictor(input_names: List[str], prediction_net: mxnet.gluon.block.Block, batch_size: int, prediction_length: int, freq: str, ctx: mxnet.context.Context, input_transform: gluonts.transform.Transformation, output_transform: Optional[Callable[[Dict[str, Any], numpy.ndarray], numpy.ndarray]] = None, float_type: gluonts.core.component.DType = <class 'numpy.float32'>, forecast_cls_name: str = 'SampleForecast', forecast_kwargs: Optional[Dict] = None)[source]

Bases: gluonts.model.predictor.Predictor

Base predictor type for Gluon-based models.

Parameters:
  • input_names – Input tensor names for the graph
  • prediction_net – Network that will be called for prediction
  • batch_size – Number of time series to predict in a single batch
  • prediction_length – Number of time steps to predict
  • freq – Frequency of the input data
  • input_transform – Input transformation pipeline
  • output_transform – Output transformation
  • ctx – MXNet context to use for computation
  • forecast_cls_name – Class name of the forecast type that will be generated
  • forecast_kwargs – A dictionary that will be passed as kwargs when instantiating the forecast object
BlockType

alias of mxnet.gluon.block.Block

as_symbol_block_predictor(batch: Dict[str, Any]) → gluonts.model.predictor.SymbolBlockPredictor[source]

Returns a variant of the current GluonPredictor backed by a Gluon SymbolBlock. If the current predictor is already a SymbolBlockPredictor, it just returns itself.

Parameters:batch – A batch of data to use for the required forward pass after the hybridize() call of the underlying network.
Returns:A predictor derived from the current one backed by a SymbolBlock.
Return type:SymbolBlockPredictor
hybridize(batch: Dict[str, Any]) → None[source]

Hybridizes the underlying prediction network.

Parameters:batch – A batch of data to use for the required forward pass after the hybridize() call.
predict(dataset: gluonts.dataset.common.Dataset, num_eval_samples: Optional[int] = None) → Iterator[gluonts.model.forecast.Forecast][source]

Compute forecasts for the time series in the provided dataset. This method is not implemented in this abstract class; please use one of the subclasses.

Parameters:dataset – The dataset containing the time series to predict.
Returns:Iterator over the forecasts, in the same order as the dataset iterable was provided.
Return type:Iterator[Forecast]
serialize(path: pathlib.Path) → None[source]
serialize_prediction_net(path: pathlib.Path) → None[source]
class gluonts.model.predictor.Localizer(estimator: Estimator)[source]

Bases: gluonts.model.predictor.Predictor

A Predictor that uses an estimator to train a local model per time series and immediatly calls this to predict.

Parameters:estimator – The estimator object to train on each dataset entry at prediction time.
predict(dataset: gluonts.dataset.common.Dataset, **kwargs) → Iterator[gluonts.model.forecast.Forecast][source]

Compute forecasts for the time series in the provided dataset. This method is not implemented in this abstract class; please use one of the subclasses.

Parameters:dataset – The dataset containing the time series to predict.
Returns:Iterator over the forecasts, in the same order as the dataset iterable was provided.
Return type:Iterator[Forecast]
class gluonts.model.predictor.ParallelizedPredictor(base_predictor: gluonts.model.predictor.Predictor, num_workers: Optional[int] = None, chunk_size=1)[source]

Bases: gluonts.model.predictor.Predictor

Runs multiple instances (workers) of a predictor in parallel.

Exceptions are propagated from the workers.

Note: That there is currently an issue with tqdm that will cause things to hang if the ParallelizedPredictor is used with tqdm and an exception occurs during prediction.

https://github.com/tqdm/tqdm/issues/548

Parameters:
  • base_predictor – A representable predictor that will be used
  • num_workers – Number of workers (processes) to use. If set to None, one worker per CPU will be used.
  • chunk_size – Number of items to pass per call
predict(dataset: gluonts.dataset.common.Dataset, **kwargs) → Iterator[gluonts.model.forecast.Forecast][source]

Compute forecasts for the time series in the provided dataset. This method is not implemented in this abstract class; please use one of the subclasses.

Parameters:dataset – The dataset containing the time series to predict.
Returns:Iterator over the forecasts, in the same order as the dataset iterable was provided.
Return type:Iterator[Forecast]
terminate()[source]
class gluonts.model.predictor.Predictor(prediction_length: int, freq: str)[source]

Bases: object

Abstract class representing predictor objects.

Parameters:
  • prediction_length – Prediction horizon.
  • freq – Frequency of the predicted data.
classmethod deserialize(path: pathlib.Path, ctx: Optional[mxnet.context.Context] = None) → gluonts.model.predictor.Predictor[source]

Load a serialized predictor from the given path

Parameters:
  • path – Path to the serialized files predictor.
  • ctx – Optional mxnet context to be used with the predictor. If nothing is passed will use the GPU if available and CPU otherwise.
classmethod from_hyperparameters(**hyperparameters)[source]
predict(dataset: gluonts.dataset.common.Dataset, **kwargs) → Iterator[gluonts.model.forecast.Forecast][source]

Compute forecasts for the time series in the provided dataset. This method is not implemented in this abstract class; please use one of the subclasses.

Parameters:dataset – The dataset containing the time series to predict.
Returns:Iterator over the forecasts, in the same order as the dataset iterable was provided.
Return type:Iterator[Forecast]
serialize(path: pathlib.Path) → None[source]
class gluonts.model.predictor.RepresentableBlockPredictor(prediction_net: mxnet.gluon.block.HybridBlock, batch_size: int, prediction_length: int, freq: str, ctx: mxnet.context.Context, input_transform: gluonts.transform.Transformation, output_transform: Optional[Callable[[Dict[str, Any], numpy.ndarray], numpy.ndarray]] = None, float_type: gluonts.core.component.DType = <class 'numpy.float32'>, forecast_cls_name: str = 'SampleForecast', forecast_kwargs: Optional[Dict] = None)[source]

Bases: gluonts.model.predictor.GluonPredictor

A predictor which serializes the network structure using the JSON-serialization methods located in gluonts.core.serde. Use the following logic to create a RepresentableBlockPredictor from a trained prediction network.

>>> def create_representable_block_predictor(
...        prediction_network: mx.gluon.HybridBlock,
...        **kwargs
... ) -> RepresentableBlockPredictor:
...    return RepresentableBlockPredictor(
...        prediction_net=prediction_network,
...        **kwargs
...    )
BlockType

alias of mxnet.gluon.block.HybridBlock

as_symbol_block_predictor(batch: Dict[str, Any]) → gluonts.model.predictor.SymbolBlockPredictor[source]

Returns a variant of the current GluonPredictor backed by a Gluon SymbolBlock. If the current predictor is already a SymbolBlockPredictor, it just returns itself.

Parameters:batch – A batch of data to use for the required forward pass after the hybridize() call of the underlying network.
Returns:A predictor derived from the current one backed by a SymbolBlock.
Return type:SymbolBlockPredictor
classmethod deserialize(path: pathlib.Path, ctx: Optional[mxnet.context.Context] = None) → gluonts.model.predictor.RepresentableBlockPredictor[source]

Load a serialized predictor from the given path

Parameters:
  • path – Path to the serialized files predictor.
  • ctx – Optional mxnet context to be used with the predictor. If nothing is passed will use the GPU if available and CPU otherwise.
serialize_prediction_net(path: pathlib.Path) → None[source]
class gluonts.model.predictor.RepresentablePredictor(prediction_length: int, freq: str)[source]

Bases: gluonts.model.predictor.Predictor

An abstract predictor that can be subclassed by models that are not based on Gluon. Subclasses should have @validated() constructors. (De)serialization and value equality are all implemented on top of the @validated() logic.

Parameters:
  • prediction_length – Prediction horizon.
  • freq – Frequency of the predicted data.
classmethod deserialize(path: pathlib.Path, ctx: Optional[mxnet.context.Context] = None) → gluonts.model.predictor.RepresentablePredictor[source]

Load a serialized predictor from the given path

Parameters:
  • path – Path to the serialized files predictor.
  • ctx – Optional mxnet context to be used with the predictor. If nothing is passed will use the GPU if available and CPU otherwise.
predict(dataset: gluonts.dataset.common.Dataset, **kwargs) → Iterator[gluonts.model.forecast.Forecast][source]

Compute forecasts for the time series in the provided dataset. This method is not implemented in this abstract class; please use one of the subclasses.

Parameters:dataset – The dataset containing the time series to predict.
Returns:Iterator over the forecasts, in the same order as the dataset iterable was provided.
Return type:Iterator[Forecast]
predict_item(item: Dict[str, Any]) → gluonts.model.forecast.Forecast[source]
serialize(path: pathlib.Path) → None[source]
class gluonts.model.predictor.SymbolBlockPredictor(input_names: List[str], prediction_net: mxnet.gluon.block.Block, batch_size: int, prediction_length: int, freq: str, ctx: mxnet.context.Context, input_transform: gluonts.transform.Transformation, output_transform: Optional[Callable[[Dict[str, Any], numpy.ndarray], numpy.ndarray]] = None, float_type: gluonts.core.component.DType = <class 'numpy.float32'>, forecast_cls_name: str = 'SampleForecast', forecast_kwargs: Optional[Dict] = None)[source]

Bases: gluonts.model.predictor.GluonPredictor

A predictor which serializes the network structure as an MXNet symbolic graph. Should be used for models deployed in production in order to ensure forward-compatibility as GluonTS models evolve.

Used by the training shell if training is invoked with a hyperparameter use_symbol_block_predictor = True.

BlockType

alias of mxnet.gluon.block.SymbolBlock

as_symbol_block_predictor(batch: Dict[str, Any]) → gluonts.model.predictor.SymbolBlockPredictor[source]

Returns a variant of the current GluonPredictor backed by a Gluon SymbolBlock. If the current predictor is already a SymbolBlockPredictor, it just returns itself.

Parameters:batch – A batch of data to use for the required forward pass after the hybridize() call of the underlying network.
Returns:A predictor derived from the current one backed by a SymbolBlock.
Return type:SymbolBlockPredictor
classmethod deserialize(path: pathlib.Path, ctx: Optional[mxnet.context.Context] = None) → gluonts.model.predictor.SymbolBlockPredictor[source]

Load a serialized predictor from the given path

Parameters:
  • path – Path to the serialized files predictor.
  • ctx – Optional mxnet context to be used with the predictor. If nothing is passed will use the GPU if available and CPU otherwise.
serialize(path: pathlib.Path) → None[source]
serialize_prediction_net(path: pathlib.Path) → None[source]
class gluonts.model.predictor.WorkerError(msg)[source]

Bases: object

gluonts.model.predictor.fallback(fallback_cls: Type[gluonts.model.predictor.FallbackPredictor])[source]