gluonts.model.forecast module#
- class gluonts.model.forecast.ExponentialTailApproximation(x_coord: List[float], y_coord: List[numpy.ndarray], tol: float = 1e-08)[source]#
Bases:
object
Approximate function on tails based on knots and make a inference on query point. Can be used for either interpolation or extrapolation on tails.
- Parameters
x_coord – x-coordinates of the data points must be in increasing order.
y_coord – y-coordinates of the data points - may be a higher numpy array.
tol – tolerance when performing the division and computing the log in the exponential extrapolation.
- init_exponential_tail_weights() Tuple[float, float] [source]#
Initialize the weight of exponentially decaying tail functions based on two extreme points on the left and right, respectively.
- Returns
beta coefficient for left and right tails.
- Return type
Tuple
- left(x: float) numpy.ndarray [source]#
Return the inference made on exponentially decaying tail functions.
For left tail, x = exp(beta * (q - alpha)) For right tail, x = 1 - exp(-beta * (q - alpha))
E.g. for x = self.x_coord[0] or self.x_coord[1], return value is exactly self.y_coord[0] or self.y_coord[1], respectively.
- Parameters
x – x-coordinate to evaluate the right tail.
- right(x: float) numpy.ndarray [source]#
Return the inference made on exponentially decaying tail functions.
For left tail, x = exp(beta * (q - alpha)) For right tail, x = 1 - exp(-beta * (q - alpha))
E.g. for x = self.x_coord[-1] or self.x_coord[-2] , return value is exactly self.y_coord[-1] or self.y_coord[-2] respectively. :param x: x-coordinate to evaluate the right tail.
- class gluonts.model.forecast.Forecast[source]#
Bases:
object
Abstract class representing predictions.
- copy_aggregate(agg_fun: Callable)[source]#
Return a new Forecast object with a time series aggregated over the dimension axis.
- Parameters
agg_fun – Aggregation function that defines the aggregation operation (typically mean or sum).
- copy_dim(dim: int)[source]#
Return a new Forecast object with only the selected sub-dimension.
- Parameters
dim – The returned forecast object will only represent this dimension.
- property freq#
- property index: pandas.core.indexes.period.PeriodIndex#
- info: Optional[Dict]#
- item_id: Optional[str]#
- property mean: numpy.ndarray#
- property median: numpy.ndarray#
- plot(*, intervals=(0.5, 0.9), ax=None, color=None, name=None, show_label=False)[source]#
Plot median forecast and prediction intervals using
matplotlib
.By default the 0.5 and 0.9 prediction intervals are plotted. Other intervals can be choosen by setting intervals.
This plots to the current axes object (via
plt.gca()
), or toax
if provided. Similarly, the color is using matplotlibs internal color cycle, if no explicitcolor
is set.One can set
name
to use it as thelabel
for the median forecast. Intervals are not labeled, unlessshow_label
is set toTrue
.
- prediction_length: int#
- quantile(q: Union[float, str]) numpy.ndarray [source]#
Compute a quantile from the predicted distribution.
- Parameters
q – Quantile to compute.
- Returns
Value of the quantile across the prediction range.
- Return type
numpy.ndarray
- start_date: pandas._libs.tslibs.period.Period#
- class gluonts.model.forecast.Quantile(value: float, name: str)[source]#
Bases:
object
- classmethod from_float(quantile: float) gluonts.model.forecast.Quantile [source]#
- classmethod from_str(quantile: str) gluonts.model.forecast.Quantile [source]#
- name: str#
- classmethod parse(quantile: Union[gluonts.model.forecast.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 ‘p10’.
- Returns
A tuple containing both a float and a string representation of the input quantile level.
- Return type
- value: float#
- class gluonts.model.forecast.QuantileForecast(forecast_arrays: numpy.ndarray, start_date: pandas._libs.tslibs.period.Period, 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 (pandas._libs.tslibs.period.Period) – start of the forecast
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.
item_id (Optional[str]) – Identifier of the item being forecasted.
info (Optional[Dict]) – Additional information that the forecaster may provide e.g. estimated parameters, number of iterations ran etc.
- copy_dim(dim: int) gluonts.model.forecast.QuantileForecast [source]#
Return a new Forecast object with only the selected sub-dimension.
- Parameters
dim – The returned forecast object will only represent this dimension.
- info: Optional[Dict]#
- item_id: Optional[str]#
- property mean: numpy.ndarray#
Forecast mean.
- prediction_length: int#
- quantile(inference_quantile: Union[float, str]) numpy.ndarray [source]#
Compute a quantile from the predicted distribution.
- Parameters
q – Quantile to compute.
- Returns
Value of the quantile across the prediction range.
- Return type
numpy.ndarray
- start_date: pandas._libs.tslibs.period.Period#
- class gluonts.model.forecast.SampleForecast(samples: numpy.ndarray, start_date: pandas._libs.tslibs.period.Period, 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) (1D case) or (num_samples, prediction_length, target_dim) (multivariate case)
start_date (pandas._libs.tslibs.period.Period) – Start of the forecast.
item_id (Optional[str]) – Identifier of the item being forecasted.
info (Optional[Dict]) – Additional information that the forecaster may provide e.g. estimated parameters, number of iterations ran etc.
- copy_aggregate(agg_fun: Callable) gluonts.model.forecast.SampleForecast [source]#
Return a new Forecast object with a time series aggregated over the dimension axis.
- Parameters
agg_fun – Aggregation function that defines the aggregation operation (typically mean or sum).
- copy_dim(dim: int) gluonts.model.forecast.SampleForecast [source]#
Return a new Forecast object with only the selected sub-dimension.
- Parameters
dim – The returned forecast object will only represent this dimension.
- info: Optional[Dict]#
- item_id: Optional[str]#
- property mean: numpy.ndarray#
Forecast mean.
- property mean_ts: pandas.core.series.Series#
Forecast mean, as a pandas.Series object.
- property num_samples#
The number of samples representing the forecast.
- property prediction_length#
Time length of the forecast.
- quantile(q: Union[float, str]) numpy.ndarray [source]#
Compute a quantile from the predicted distribution.
- Parameters
q – Quantile to compute.
- Returns
Value of the quantile across the prediction range.
- Return type
numpy.ndarray
- start_date: pandas._libs.tslibs.period.Period#
- to_quantile_forecast(quantiles: List[str]) gluonts.model.forecast.QuantileForecast [source]#