Table Of Contents
Table Of Contents

gluonts.model.forecast module

class gluonts.model.forecast.Config[source]

Bases: pydantic.main.BaseModel

class Config[source]

Bases: object

allow_population_by_alias = True
class gluonts.model.forecast.DistributionForecast(distribution: gluonts.distribution.distribution.Distribution, start_date, freq, item_id: Optional[str] = None, info: Optional[Dict] = None)[source]

Bases: gluonts.model.forecast.Forecast

A Forecast object that uses a GluonTS distribution directly. This can for instance be used to represent marginal probability distributions for each time point – although joint distributions are also possible, e.g. when using MultiVariateGaussian).

Parameters:
  • distribution

    GluonTS distribution or list of distributions. The distribution should represent the entire prediction length, i.e., if we draw num_samples samples from the distribution, the sample shape should be

    samples = trans_dist.sample(num_samples) samples.shape -> (num_samples, prediction_length)
  • start_date – start of the forecast
  • freq – forecast frequency
  • info – additional information that the forecaster may provide e.g. estimated parameters, number of iterations ran etc.
mean

Forecast mean.

mean_ts

Forecast mean, as a pandas.Series object.

quantile(level)[source]

Computes a quantile from the predicted distribution.

Parameters:q – Quantile to compute.
Returns:Value of the quantile across the prediction range.
Return type:numpy.ndarray
to_sample_forecast(num_samples: int = 200) → gluonts.model.forecast.SampleForecast[source]
class gluonts.model.forecast.Forecast[source]

Bases: object

A abstract class representing predictions.

as_json_dict(config: gluonts.model.forecast.Config) → dict[source]
copy_dim(dim: int)[source]

Returns a new Forecast object with only the selected sub-dimension.

Parameters:dim – The returned forecast object will only have samples of this dimension.
dim() → int[source]

Returns the dimensionality of the forecast object.

index
plot(prediction_intervals=(50.0, 90.0), show_mean=False, color='b', label=None, output_file=None, *args, **kwargs)[source]

Plots the median of the forecast as well as confidence bounds. (requires matplotlib and pandas).

Parameters:
  • prediction_intervals (float or list of floats in [0, 100]) – Confidence interval size(s). If a list, it will stack the error plots for each confidence interval. Only relevant for error styles with “ci” in the name.
  • show_mean (boolean) – Whether to also show the mean of the forecast.
  • color (matplotlib color name or dictionary) – The color used for plotting the forecast.
  • label (string) – A label (prefix) that is used for the forecast
  • output_file (str or None, default None) – Output path for the plot file. If None, plot is not saved to file.
  • args – Other arguments are passed to main plot() call
  • kwargs – Other keyword arguments are passed to main plot() call
quantile(q: Union[float, str]) → numpy.ndarray[source]

Computes a quantile from the predicted distribution.

Parameters:q – Quantile to compute.
Returns:Value of the quantile across the prediction range.
Return type:numpy.ndarray
class gluonts.model.forecast.OutputType[source]

Bases: str, enum.Enum

An enumeration.

mean = 'mean'
quantiles = 'quantiles'
samples = 'samples'
class gluonts.model.forecast.Quantile(value, name)[source]

Bases: tuple

classmethod checked(value: float, name: str) → gluonts.model.forecast.Quantile[source]
coverage_name
classmethod from_float(quantile: float) → gluonts.model.forecast.Quantile[source]
classmethod from_str(quantile: str) → gluonts.model.forecast.Quantile[source]
loss_name
name

Alias for field number 1

classmethod parse(quantile: Union[Quantile, float, str]) → gluonts.model.forecast.Quantile[source]

Produces equivalent float and string representation of a given quantile level.

>>> Quantile.parse(0.1)
Quantile(value=0.1, name='0.1')
>>> Quantile.parse('0.2')
Quantile(value=0.2, name='0.2')
>>> Quantile.parse('0.20')
Quantile(value=0.2, name='0.20')
>>> Quantile.parse('p99')
Quantile(value=0.99, name='0.99')
Parameters:quantile – Quantile, can be a float a str representing a float e.g. ‘0.1’ or a quantile string of the form ‘p0.1’.
Returns:A tuple containing both a float and a string representation of the input quantile level.
Return type:Quantile
value

Alias for field number 0

weighted_loss_name
class gluonts.model.forecast.QuantileForecast(forecast_arrays: numpy.ndarray, start_date: pandas._libs.tslibs.timestamps.Timestamp, freq: str, forecast_keys: List[str], item_id: Optional[str] = None, info: Optional[Dict] = None)[source]

Bases: gluonts.model.forecast.Forecast

A Forecast that contains arrays (i.e. time series) for quantiles and mean

Parameters:
  • forecast_arrays – An array of forecasts
  • start_date – start of the forecast
  • freq – forecast frequency
  • forecast_keys – A list of quantiles of the form ‘0.1’, ‘0.9’, etc., and potentially ‘mean’. Each entry corresponds to one array in forecast_arrays.
  • info – additional information that the forecaster may provide e.g. estimated parameters, number of iterations ran etc.
dim() → int[source]

Returns the dimensionality of the forecast object.

mean

Forecast mean.

quantile(q: Union[float, str]) → numpy.ndarray[source]

Computes a quantile from the predicted distribution.

Parameters:q – Quantile to compute.
Returns:Value of the quantile across the prediction range.
Return type:numpy.ndarray
class gluonts.model.forecast.SampleForecast(samples: Union[mxnet.ndarray.ndarray.NDArray, numpy.ndarray], start_date, freq, item_id: Optional[str] = None, info: Optional[Dict] = None)[source]

Bases: gluonts.model.forecast.Forecast

A Forecast object, where the predicted distribution is represented internally as samples.

Parameters:
  • samples – Array of size (num_samples, prediction_length)
  • start_date – start of the forecast
  • freq – forecast frequency
  • info – additional information that the forecaster may provide e.g. estimated parameters, number of iterations ran etc.
as_json_dict(config: gluonts.model.forecast.Config) → dict[source]
copy_dim(dim: int)[source]

Returns a new Forecast object with only the selected sub-dimension.

Parameters:dim – The returned forecast object will only have samples of this dimension.
dim() → int[source]

Returns the dimensionality of the forecast object.

mean

Forecast mean.

mean_ts

Forecast mean, as a pandas.Series object.

num_samples

The number of samples representing the forecast.

prediction_length

Time length of the forecast.

quantile(q)[source]

Computes a quantile from the predicted distribution.

Parameters:q – Quantile to compute.
Returns:Value of the quantile across the prediction range.
Return type:numpy.ndarray