gluonts.zebras package#
- class gluonts.zebras.BatchSplitFrame(_past: 'dict', _future: 'dict', index: 'List[Optional[Periods]]', static: 'dict', past_length: 'int', future_length: 'int', tdims: 'dict', metadata: 'List[Optional[dict]]', _pad: 'List[Pad]')[source]#
Bases:
object- property batch_size#
- property future#
- future_length: int#
- metadata: List[Optional[dict]]#
- property past#
- past_length: int#
- static: dict#
- tdims: dict#
- class gluonts.zebras.BatchTimeFrame(columns: 'dict', index: 'Collection[Optional[Periods]]', static: 'dict', length: 'int', tdims: 'dict', metadata: 'Collection[Optional[dict]]', _pad: 'Collection[Pad]')[source]#
Bases:
object- property batch_size#
- columns: dict#
- length: int#
- metadata: Collection[Optional[dict]]#
- static: dict#
- tdims: dict#
- class gluonts.zebras.BatchTimeSeries(values: 'np.ndarray', index: 'List[Optional[Periods]]', name: 'List[Optional[str]]', tdim: 'int', metadata: 'List[Optional[dict]]', _pad: 'List[Pad]')[source]#
Bases:
TimeBase- property batch_size#
- metadata: List[Optional[dict]]#
- name: List[Optional[str]]#
- pad(value, left: int = 0, right: int = 0) TimeSeries[source]#
- property shape: Tuple[int, ...]#
- tdim: int#
- values: ndarray#
- class gluonts.zebras.Freq(name: str, n: int, suffix: Optional[str] = None)[source]#
Bases:
objectA class representing frequencies, such as n-days.
Note: Use
freqto construct instances ofFreq.We use frequency aliases from pandas over frequency names defined by numpy. For example, the name for minutely is either “min” or “T”, while “m” and “M” represent monthly frequencies. In contrast numpy uses “m” for minutely and “M” for monthly. In addition, pandas defines some frequencies which do not exist in numpy, for example quarterly frequencies.
However, internally we use
numpy.datetime64objects and thus we must support numpy’s frequency names as well. To do this we generally use base frequencies (multiple = 1), since numpy otherwise aligns timestamps for us which we don’t want.Weekly frequency needs to be handled specially, since numpy counts the number of weeks since Thu Jan 1 1970 and uses Thursday and aligns the timestamp to Thursday. We therefore use daily frequency internally and align to Monday.
- align(timestamp: datetime64) datetime64[source]#
Align
timestampaccording to the frequency.For example, for daily frequency, any timestamps that fall into the same day align to the same value.
- n: int#
- name: str#
- property np_freq: Tuple[str, int]#
- property step#
- suffix: Optional[str] = None#
- class gluonts.zebras.Period(data: 'np.datetime64', freq: 'Freq')[source]#
Bases:
_BasePeriod- data: datetime64#
- property shape: Tuple[int, ...]#
- class gluonts.zebras.Periods(data: 'np.ndarray', freq: 'Freq')[source]#
Bases:
_BasePeriod- data: ndarray#
- property end: Period#
Last timestamp.
>>> p = periods("2021", "D", 365) >>> assert p.end == period("2021-12-31", "D")
- extend(count: int) Periods[source]#
Copy which contains
countfuture timestamps.>>> p = periods("2021", "D", 365) >>> assert p.extend(5) == periods("2021", "D", 370)
- classmethod from_pandas(index)[source]#
Turn
pandas.PeriodIndexorpandas.DatetimeIndexintoPeriods.
- future(count: int) Periods[source]#
Next
counttimestamps.>>> p = periods("2021", "D", 365) >>> assert p.future(5) == periods("2022-01-01", "D", 5)
- head(count: int) Periods[source]#
First
counttimestamps.>>> p = periods("2021", "D", 365) >>> assert p.head(5) == periods("2021-01-01", "D", 5)
- index_of(period: Union[str, Period])[source]#
Return the index of
period>>> p = periods("2021", "D", 365) >>> assert p.index_of(period("2021-02-01", "D")) == 31
- past(count: int) Periods[source]#
Previous
counttimestamps.>>> p = periods("2021", "D", 365) >>> assert p.past(5) == periods("2020-12-27", "D", 5)
- prepend(count: int) Periods[source]#
Copy which contains
countpast timestamps.>>> p = periods("2021", "D", 365) >>> assert p.prepend(5) == periods("2020-12-27", "D", 370)
- property shape: Tuple[int, ...]#
- class gluonts.zebras.SplitFrame(_past: 'dict', _future: 'dict', index: 'Optional[Periods]', static: 'dict', past_length: 'int', future_length: 'int', tdims: 'dict', metadata: 'Optional[dict]' = None, default_tdim: 'int' = -1, _pad: 'Pad' = Pad(left=0, right=0))[source]#
Bases:
object- default_tdim: int = -1#
- property future#
- future_length: int#
- metadata: Optional[dict] = None#
- property past#
- past_length: int#
- resize(past_length: Optional[int] = None, future_length: Optional[int] = None, pad_value=0.0) SplitFrame[source]#
- static: dict#
- tdims: dict#
- class gluonts.zebras.TimeFrame(columns: 'dict', index: 'Optional[Periods]', static: 'dict', length: 'int', tdims: 'dict', metadata: 'Optional[dict]' = None, default_tdim: 'int' = -1, _pad: 'Pad' = Pad(left=0, right=0))[source]#
Bases:
TimeBase- columns: dict#
- default_tdim: int = -1#
- length: int#
- metadata: Optional[dict] = None#
- rename(mapping=None, **kwargs)[source]#
Rename
columnsofTimeFrame.The keys in
mappingdenote the target column names, i.e.rename({"target": "source"}). For convenience one can use keyword parameters (`.rename(target=”source”)).
- rename_static(mapping=None, **kwargs)[source]#
Rename
staticfields ofTimeFrame.The keys in
mappingdenote the target column names, i.e.rename({"target": "source"}). For convenience one can use keyword parameters (`.rename(target=”source”)).
- rolsplit(index, *, distance: int = 1, past_length: Optional[int] = None, future_length: Optional[int] = None, n: Optional[int] = None, pad_value=0.0)[source]#
Create rolling split of past/future pairs.
- Parameters:
index – Starting index that denominates the cut off point from which splits are generated.
distance – The distance by which pairs are shifted. Defaults to
1. To avoid overlapping examples,distancehas to be set to be at leastpast_length.future_length – Optionally enforce future length. Note that
rolsplitwill never pad values in the future range.optional – Optionally enforce future length. Note that
rolsplitwill never pad values in the future range.past_length – If provided, all pairs past will have
past_length, padded withpad_valueif needed.optional – If provided, all pairs past will have
past_length, padded withpad_valueif needed.n – If provided, limits the number of pairs to
n.optional – If provided, limits the number of pairs to
n.pad_value – Value to pad past if needed, defaults to
0.0.
- Return type:
A stream of
zebras.SplitFrameobjects.
- static: dict#
- tdims: dict#
- class gluonts.zebras.TimeSeries(values: 'np.ndarray', index: 'Optional[Periods]' = None, name: 'Optional[str]' = None, tdim: 'int' = -1, metadata: 'Optional[dict]' = None, _pad: 'Pad' = Pad(left=0, right=0))[source]#
Bases:
TimeBase- metadata: Optional[dict] = None#
- name: Optional[str] = None#
- pad(value, left: int = 0, right: int = 0) TimeSeries[source]#
- property shape: Tuple[int, ...]#
- tdim: int = -1#
- values: ndarray#
- gluonts.zebras.period(data: Union[Period, str], freq: Optional[Union[Freq, str]] = None) Period[source]#
Create a
zebras.Periodobject that represents a period of time.- Parameters:
data – The time period represented by a string (e.g., “2023-01-01”), or another Period object.
freq – The frequency of the period, e.g, “H” for hourly, by default None.
optional – The frequency of the period, e.g, “H” for hourly, by default None.
- Return type:
A
zebras.Periodobject.
- gluonts.zebras.periods(start: Union[Period, str], freq: Union[Freq, str], count: int) Period[source]#
Create a
zebras.Periodsobject that represents multiple consecutive periods of time.- Parameters:
start – The starting time period represented by a string (e.g., “2023-01-01”), or another Period object.
freq – The frequency of the period, e.g, “H” for hourly.
count – The number of periods.
- Return type:
A
zebras.Periodsobject.
- gluonts.zebras.split_frame(full=None, *, past=None, future=None, past_length=None, future_length=None, static=None, index=None, start=None, freq=None, tdims=None, metadata=None, default_tdim=-1)[source]#
Create a
zebras.SplitFramewhere columns can either be past, future or full, which spans both past and future.past_lengthandfuture_lengthis derived from the input data if possible or default to0in case no respective data is available. It is possible to set these values explicitly for enforcing consistency or to provide a length even though no time series spans that range.- Parameters:
full – Time series columns that span past and future.
optional – Time series columns that span past and future.
past – Time series columns that are past only.
optional – Time series columns that are past only.
future – Time series columns that are future only.
optional – Time series columns that are future only.
past_length – Set length of the past section, derived from data if not provided.
optional – Set length of the past section, derived from data if not provided.
future_length – Set length of the future section, derived from data if not provided.
optional – Set length of the future section, derived from data if not provided.
static – Values that are independent of time.
optional – Values that are independent of time.
index – A
zebras.Periodsobject representing timestamps. Must have the same length as full range.optional – A
zebras.Periodsobject representing timestamps. Must have the same length as full range.start – The start time represented by a string (e.g., “2023-01-01”), or a
zebras.Periodobject. An index will be constructed using this start time and the specified frequencyoptional – The start time represented by a string (e.g., “2023-01-01”), or a
zebras.Periodobject. An index will be constructed using this start time and the specified frequencyfreq – The frequency to use for constructing the index.
optional – The frequency to use for constructing the index.
tdims – A dictionary specifying the time dimension for each column, this applies to past, future and full.
optional – A dictionary specifying the time dimension for each column, this applies to past, future and full.
default_tdim – The default time dimension, by default -1
optional – The default time dimension, by default -1
metadata – A dictionary of metadata associated with the TimeFrame, by default None
optional – A dictionary of metadata associated with the TimeFrame, by default None
- Return type:
A
zebras.SplitFrameobject.
- gluonts.zebras.time_frame(columns: Optional[Mapping[str, Collection]] = None, *, index: Optional[Periods] = None, start: Optional[Union[Period, str]] = None, freq: Optional[Union[Freq, str]] = None, static: Optional[Mapping[str, Any]] = None, tdims: Optional[Mapping[str, int]] = None, length: Optional[int] = None, default_tdim: int = -1, metadata: Optional[Mapping] = None)[source]#
Create a
zebras.TimeFrameobject that represents one or more time series.- Parameters:
columns – A dictionary where keys are strings representing column names and values are sequences (e.g., list, numpy arrays). All columns must have the same length in the time dimension, by default None
optional – A dictionary where keys are strings representing column names and values are sequences (e.g., list, numpy arrays). All columns must have the same length in the time dimension, by default None
index – A
zebras.Periodsobject representing timestamps. Must have the same length as the columns, by default Noneoptional – A
zebras.Periodsobject representing timestamps. Must have the same length as the columns, by default Nonestart – The start time represented by a string (e.g., “2023-01-01”), or a
zebras.Periodobject. An index will be constructed using this start time and the specified frequency, by default Noneoptional – The start time represented by a string (e.g., “2023-01-01”), or a
zebras.Periodobject. An index will be constructed using this start time and the specified frequency, by default Nonefreq – The frequency of the period, e.g, “H” for hourly, by default None
optional – The frequency of the period, e.g, “H” for hourly, by default None
static – A dictionary of static-in-time features, by default None
optional – A dictionary of static-in-time features, by default None
tdims – A dictionary specifying the time dimension for each column. The keys should match those in columns. If unspecified for a column, the default_tdim is used, by default None
optional – A dictionary specifying the time dimension for each column. The keys should match those in columns. If unspecified for a column, the default_tdim is used, by default None
length – The length (in time) of the TimeFrame, by default None
optional – The length (in time) of the TimeFrame, by default None
default_tdim – The default time dimension, by default -1
optional – The default time dimension, by default -1
metadata – A dictionary of metadata associated with the TimeFrame, by default None
optional – A dictionary of metadata associated with the TimeFrame, by default None
- Return type:
A
zebras.TimeFrameobject.
- gluonts.zebras.time_series(values: Collection, *, index: Optional[Periods] = None, start: Optional[Union[Period, str]] = None, freq: Optional[str] = None, tdim: int = -1, name: Optional[str] = None, metadata: Optional[Dict] = None)[source]#
Create a
zebras.TimeSeriesobject that represents a time series.- Parameters:
values – A sequence (e.g., list, numpy arrays) representing the values of the time series.
index – A
zebras.Periodsobject representing timestamps. Must have the same length as the values, by default Noneoptional – A
zebras.Periodsobject representing timestamps. Must have the same length as the values, by default Nonestart – The start time represented by a string (e.g., “2023-01-01”), or a
zebras.Periodobject. An index will be constructed using this start time and the specificed frequency, by default Noneoptional – The start time represented by a string (e.g., “2023-01-01”), or a
zebras.Periodobject. An index will be constructed using this start time and the specificed frequency, by default Nonefreq – The frequency of the period, e.g, “H” for hourly, by default None
optional – The frequency of the period, e.g, “H” for hourly, by default None
tdim – The time dimension in values, by default -1
optional – The time dimension in values, by default -1
name (optional) – A description for the time series. This will be the column names when returned from a
TimeFrame.metadata – A dictionary of metadata associated with the time series, by default None
optional – A dictionary of metadata associated with the time series, by default None
- Return type:
A
zebras.TimeSeriesobject.