autogluon.timeseries 1.2.1b20250224__py3-none-any.whl → 1.4.1b20251215__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of autogluon.timeseries might be problematic. Click here for more details.
- autogluon/timeseries/configs/__init__.py +3 -2
- autogluon/timeseries/configs/hyperparameter_presets.py +62 -0
- autogluon/timeseries/configs/predictor_presets.py +106 -0
- autogluon/timeseries/dataset/ts_dataframe.py +256 -141
- autogluon/timeseries/learner.py +86 -52
- autogluon/timeseries/metrics/__init__.py +42 -8
- autogluon/timeseries/metrics/abstract.py +89 -19
- autogluon/timeseries/metrics/point.py +142 -53
- autogluon/timeseries/metrics/quantile.py +46 -21
- autogluon/timeseries/metrics/utils.py +4 -4
- autogluon/timeseries/models/__init__.py +8 -2
- autogluon/timeseries/models/abstract/__init__.py +2 -2
- autogluon/timeseries/models/abstract/abstract_timeseries_model.py +361 -592
- autogluon/timeseries/models/abstract/model_trial.py +2 -1
- autogluon/timeseries/models/abstract/tunable.py +189 -0
- autogluon/timeseries/models/autogluon_tabular/__init__.py +2 -0
- autogluon/timeseries/models/autogluon_tabular/mlforecast.py +282 -194
- autogluon/timeseries/models/autogluon_tabular/per_step.py +513 -0
- autogluon/timeseries/models/autogluon_tabular/transforms.py +25 -18
- autogluon/timeseries/models/chronos/__init__.py +2 -1
- autogluon/timeseries/models/chronos/chronos2.py +361 -0
- autogluon/timeseries/models/chronos/model.py +219 -138
- autogluon/timeseries/models/chronos/{pipeline/utils.py → utils.py} +81 -50
- autogluon/timeseries/models/ensemble/__init__.py +37 -2
- autogluon/timeseries/models/ensemble/abstract.py +107 -0
- autogluon/timeseries/models/ensemble/array_based/__init__.py +3 -0
- autogluon/timeseries/models/ensemble/array_based/abstract.py +240 -0
- autogluon/timeseries/models/ensemble/array_based/models.py +185 -0
- autogluon/timeseries/models/ensemble/array_based/regressor/__init__.py +12 -0
- autogluon/timeseries/models/ensemble/array_based/regressor/abstract.py +88 -0
- autogluon/timeseries/models/ensemble/array_based/regressor/linear_stacker.py +186 -0
- autogluon/timeseries/models/ensemble/array_based/regressor/per_quantile_tabular.py +94 -0
- autogluon/timeseries/models/ensemble/array_based/regressor/tabular.py +107 -0
- autogluon/timeseries/models/ensemble/ensemble_selection.py +167 -0
- autogluon/timeseries/models/ensemble/per_item_greedy.py +172 -0
- autogluon/timeseries/models/ensemble/weighted/__init__.py +8 -0
- autogluon/timeseries/models/ensemble/weighted/abstract.py +45 -0
- autogluon/timeseries/models/ensemble/weighted/basic.py +91 -0
- autogluon/timeseries/models/ensemble/weighted/greedy.py +62 -0
- autogluon/timeseries/models/gluonts/__init__.py +1 -1
- autogluon/timeseries/models/gluonts/{abstract_gluonts.py → abstract.py} +148 -208
- autogluon/timeseries/models/gluonts/dataset.py +109 -0
- autogluon/timeseries/models/gluonts/{torch/models.py → models.py} +38 -22
- autogluon/timeseries/models/local/__init__.py +0 -7
- autogluon/timeseries/models/local/abstract_local_model.py +71 -74
- autogluon/timeseries/models/local/naive.py +13 -9
- autogluon/timeseries/models/local/npts.py +9 -2
- autogluon/timeseries/models/local/statsforecast.py +52 -36
- autogluon/timeseries/models/multi_window/multi_window_model.py +65 -45
- autogluon/timeseries/models/registry.py +64 -0
- autogluon/timeseries/models/toto/__init__.py +3 -0
- autogluon/timeseries/models/toto/_internal/__init__.py +9 -0
- autogluon/timeseries/models/toto/_internal/backbone/__init__.py +3 -0
- autogluon/timeseries/models/toto/_internal/backbone/attention.py +196 -0
- autogluon/timeseries/models/toto/_internal/backbone/backbone.py +262 -0
- autogluon/timeseries/models/toto/_internal/backbone/distribution.py +70 -0
- autogluon/timeseries/models/toto/_internal/backbone/kvcache.py +136 -0
- autogluon/timeseries/models/toto/_internal/backbone/rope.py +89 -0
- autogluon/timeseries/models/toto/_internal/backbone/rotary_embedding_torch.py +342 -0
- autogluon/timeseries/models/toto/_internal/backbone/scaler.py +305 -0
- autogluon/timeseries/models/toto/_internal/backbone/transformer.py +333 -0
- autogluon/timeseries/models/toto/_internal/dataset.py +165 -0
- autogluon/timeseries/models/toto/_internal/forecaster.py +423 -0
- autogluon/timeseries/models/toto/dataloader.py +108 -0
- autogluon/timeseries/models/toto/hf_pretrained_model.py +200 -0
- autogluon/timeseries/models/toto/model.py +249 -0
- autogluon/timeseries/predictor.py +685 -297
- autogluon/timeseries/regressor.py +94 -44
- autogluon/timeseries/splitter.py +8 -32
- autogluon/timeseries/trainer/__init__.py +3 -0
- autogluon/timeseries/trainer/ensemble_composer.py +444 -0
- autogluon/timeseries/trainer/model_set_builder.py +256 -0
- autogluon/timeseries/trainer/prediction_cache.py +149 -0
- autogluon/timeseries/{trainer.py → trainer/trainer.py} +387 -390
- autogluon/timeseries/trainer/utils.py +17 -0
- autogluon/timeseries/transforms/__init__.py +2 -13
- autogluon/timeseries/transforms/covariate_scaler.py +34 -40
- autogluon/timeseries/transforms/target_scaler.py +37 -20
- autogluon/timeseries/utils/constants.py +10 -0
- autogluon/timeseries/utils/datetime/lags.py +3 -5
- autogluon/timeseries/utils/datetime/seasonality.py +1 -3
- autogluon/timeseries/utils/datetime/time_features.py +2 -2
- autogluon/timeseries/utils/features.py +70 -47
- autogluon/timeseries/utils/forecast.py +19 -14
- autogluon/timeseries/utils/timer.py +173 -0
- autogluon/timeseries/utils/warning_filters.py +4 -2
- autogluon/timeseries/version.py +1 -1
- autogluon.timeseries-1.4.1b20251215-py3.11-nspkg.pth +1 -0
- {autogluon.timeseries-1.2.1b20250224.dist-info → autogluon_timeseries-1.4.1b20251215.dist-info}/METADATA +49 -36
- autogluon_timeseries-1.4.1b20251215.dist-info/RECORD +103 -0
- {autogluon.timeseries-1.2.1b20250224.dist-info → autogluon_timeseries-1.4.1b20251215.dist-info}/WHEEL +1 -1
- autogluon/timeseries/configs/presets_configs.py +0 -79
- autogluon/timeseries/evaluator.py +0 -6
- autogluon/timeseries/models/chronos/pipeline/__init__.py +0 -11
- autogluon/timeseries/models/chronos/pipeline/base.py +0 -160
- autogluon/timeseries/models/chronos/pipeline/chronos.py +0 -585
- autogluon/timeseries/models/chronos/pipeline/chronos_bolt.py +0 -518
- autogluon/timeseries/models/ensemble/abstract_timeseries_ensemble.py +0 -78
- autogluon/timeseries/models/ensemble/greedy_ensemble.py +0 -170
- autogluon/timeseries/models/gluonts/torch/__init__.py +0 -0
- autogluon/timeseries/models/presets.py +0 -360
- autogluon.timeseries-1.2.1b20250224-py3.9-nspkg.pth +0 -1
- autogluon.timeseries-1.2.1b20250224.dist-info/RECORD +0 -68
- {autogluon.timeseries-1.2.1b20250224.dist-info → autogluon_timeseries-1.4.1b20251215.dist-info/licenses}/LICENSE +0 -0
- {autogluon.timeseries-1.2.1b20250224.dist-info → autogluon_timeseries-1.4.1b20251215.dist-info/licenses}/NOTICE +0 -0
- {autogluon.timeseries-1.2.1b20250224.dist-info → autogluon_timeseries-1.4.1b20251215.dist-info}/namespace_packages.txt +0 -0
- {autogluon.timeseries-1.2.1b20250224.dist-info → autogluon_timeseries-1.4.1b20251215.dist-info}/top_level.txt +0 -0
- {autogluon.timeseries-1.2.1b20250224.dist-info → autogluon_timeseries-1.4.1b20251215.dist-info}/zip-safe +0 -0
|
@@ -1,76 +1,93 @@
|
|
|
1
1
|
import logging
|
|
2
2
|
import time
|
|
3
|
-
from typing import Any,
|
|
3
|
+
from typing import Any, Protocol, overload, runtime_checkable
|
|
4
4
|
|
|
5
5
|
import numpy as np
|
|
6
6
|
import pandas as pd
|
|
7
7
|
|
|
8
8
|
from autogluon.core.models import AbstractModel
|
|
9
|
-
from autogluon.tabular.
|
|
10
|
-
from autogluon.timeseries.dataset
|
|
9
|
+
from autogluon.tabular.registry import ag_model_registry as tabular_ag_model_registry
|
|
10
|
+
from autogluon.timeseries.dataset import TimeSeriesDataFrame
|
|
11
11
|
from autogluon.timeseries.utils.features import CovariateMetadata
|
|
12
12
|
|
|
13
13
|
logger = logging.getLogger(__name__)
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
@runtime_checkable
|
|
17
|
+
class CovariateRegressor(Protocol):
|
|
18
|
+
def is_fit(self) -> bool: ...
|
|
19
|
+
|
|
20
|
+
def fit(self, data: TimeSeriesDataFrame, time_limit: float | None = None, **kwargs) -> "CovariateRegressor": ...
|
|
21
|
+
|
|
22
|
+
def transform(self, data: TimeSeriesDataFrame) -> TimeSeriesDataFrame: ...
|
|
23
|
+
|
|
24
|
+
def fit_transform(
|
|
25
|
+
self, data: TimeSeriesDataFrame, time_limit: float | None = None, **kwargs
|
|
26
|
+
) -> TimeSeriesDataFrame: ...
|
|
27
|
+
|
|
28
|
+
def inverse_transform(
|
|
29
|
+
self,
|
|
30
|
+
predictions: TimeSeriesDataFrame,
|
|
31
|
+
known_covariates: TimeSeriesDataFrame,
|
|
32
|
+
static_features: pd.DataFrame | None,
|
|
33
|
+
) -> TimeSeriesDataFrame: ...
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class GlobalCovariateRegressor(CovariateRegressor):
|
|
17
37
|
"""Predicts target values from the covariates for the same observation.
|
|
18
38
|
|
|
19
39
|
The model construct the feature matrix using known_covariates and static_features.
|
|
20
40
|
|
|
21
41
|
Parameters
|
|
22
42
|
----------
|
|
23
|
-
model_name
|
|
24
|
-
Name of the tabular regression model. See
|
|
25
|
-
list of available
|
|
26
|
-
|
|
43
|
+
model_name
|
|
44
|
+
Name of the tabular regression model. See ``autogluon.tabular.registry.ag_model_registry`` or
|
|
45
|
+
`the documentation <https://auto.gluon.ai/stable/api/autogluon.tabular.models.html>`_ for the list of available
|
|
46
|
+
tabular models.
|
|
47
|
+
model_hyperparameters
|
|
27
48
|
Hyperparameters passed to the tabular regression model.
|
|
28
|
-
eval_metric
|
|
29
|
-
Metric provided as
|
|
30
|
-
refit_during_predict
|
|
31
|
-
If True, the model will be re-trained every time
|
|
32
|
-
trained the first time that
|
|
33
|
-
|
|
34
|
-
max_num_samples
|
|
49
|
+
eval_metric
|
|
50
|
+
Metric provided as ``eval_metric`` to the tabular regression model. Must be compatible with `problem_type="regression"`.
|
|
51
|
+
refit_during_predict
|
|
52
|
+
If True, the model will be re-trained every time ``fit_transform`` is called. If False, the model will only be
|
|
53
|
+
trained the first time that ``fit_transform`` is called, and future calls to ``fit_transform`` will only perform a
|
|
54
|
+
``transform``.
|
|
55
|
+
max_num_samples
|
|
35
56
|
If not None, training dataset passed to regression model will contain at most this many rows.
|
|
36
|
-
|
|
57
|
+
covariate_metadata
|
|
37
58
|
Metadata object describing the covariates available in the dataset.
|
|
38
|
-
target
|
|
59
|
+
target
|
|
39
60
|
Name of the target column.
|
|
40
|
-
validation_fraction
|
|
61
|
+
validation_fraction
|
|
41
62
|
Fraction of observations that are reserved as the validation set during training (starting from the end of each
|
|
42
63
|
time series).
|
|
43
|
-
fit_time_fraction
|
|
64
|
+
fit_time_fraction
|
|
44
65
|
The fraction of the time_limit that will be reserved for model training. The remainder (1 - fit_time_fraction)
|
|
45
66
|
will be reserved for prediction.
|
|
46
67
|
|
|
47
|
-
If the estimated prediction time exceeds
|
|
48
|
-
include_static_features
|
|
68
|
+
If the estimated prediction time exceeds ``(1 - fit_time_fraction) * time_limit``, the regressor will be disabled.
|
|
69
|
+
include_static_features
|
|
49
70
|
If True, static features will be included as features for the regressor.
|
|
50
|
-
include_item_id
|
|
71
|
+
include_item_id
|
|
51
72
|
If True, item_id will be included as a categorical feature for the regressor.
|
|
52
73
|
"""
|
|
53
74
|
|
|
54
75
|
def __init__(
|
|
55
76
|
self,
|
|
56
77
|
model_name: str = "CAT",
|
|
57
|
-
model_hyperparameters:
|
|
78
|
+
model_hyperparameters: dict[str, Any] | None = None,
|
|
58
79
|
eval_metric: str = "mean_absolute_error",
|
|
59
80
|
refit_during_predict: bool = False,
|
|
60
|
-
max_num_samples:
|
|
61
|
-
|
|
81
|
+
max_num_samples: int | None = 500_000,
|
|
82
|
+
covariate_metadata: CovariateMetadata | None = None,
|
|
62
83
|
target: str = "target",
|
|
63
|
-
validation_fraction:
|
|
84
|
+
validation_fraction: float | None = 0.1,
|
|
64
85
|
fit_time_fraction: float = 0.5,
|
|
65
86
|
include_static_features: bool = True,
|
|
66
87
|
include_item_id: bool = False,
|
|
67
88
|
):
|
|
68
|
-
if model_name not in TABULAR_MODEL_TYPES:
|
|
69
|
-
raise ValueError(
|
|
70
|
-
f"Tabular model {model_name} not supported. Available models: {list(TABULAR_MODEL_TYPES)}"
|
|
71
|
-
)
|
|
72
89
|
self.target = target
|
|
73
|
-
self.model_type =
|
|
90
|
+
self.model_type = tabular_ag_model_registry.key_to_cls(model_name)
|
|
74
91
|
self.model_name = model_name
|
|
75
92
|
self.model_hyperparameters = model_hyperparameters or {}
|
|
76
93
|
self.refit_during_predict = refit_during_predict
|
|
@@ -81,14 +98,14 @@ class CovariateRegressor:
|
|
|
81
98
|
self.include_static_features = include_static_features
|
|
82
99
|
self.include_item_id = include_item_id
|
|
83
100
|
|
|
84
|
-
self.model:
|
|
101
|
+
self.model: AbstractModel | None = None
|
|
85
102
|
self.disabled = False
|
|
86
|
-
self.
|
|
103
|
+
self.covariate_metadata = covariate_metadata or CovariateMetadata()
|
|
87
104
|
|
|
88
105
|
def is_fit(self) -> bool:
|
|
89
106
|
return self.model is not None
|
|
90
107
|
|
|
91
|
-
def fit(self, data: TimeSeriesDataFrame, time_limit:
|
|
108
|
+
def fit(self, data: TimeSeriesDataFrame, time_limit: float | None = None, **kwargs) -> "CovariateRegressor":
|
|
92
109
|
"""Fit the tabular regressor on the target column using covariates as features."""
|
|
93
110
|
start_time = time.monotonic()
|
|
94
111
|
tabular_df = self._get_tabular_df(data, static_features=data.static_features, include_target=True)
|
|
@@ -97,9 +114,9 @@ class CovariateRegressor:
|
|
|
97
114
|
median_ts_length = data.num_timesteps_per_item().median()
|
|
98
115
|
features_to_drop = [self.target]
|
|
99
116
|
if not self.include_item_id:
|
|
100
|
-
features_to_drop += [ITEMID]
|
|
117
|
+
features_to_drop += [TimeSeriesDataFrame.ITEMID]
|
|
101
118
|
if self.validation_fraction is not None:
|
|
102
|
-
grouped_df = tabular_df.groupby(ITEMID, observed=False, sort=False)
|
|
119
|
+
grouped_df = tabular_df.groupby(TimeSeriesDataFrame.ITEMID, observed=False, sort=False)
|
|
103
120
|
val_size = max(int(self.validation_fraction * median_ts_length), 1)
|
|
104
121
|
train_df = self._subsample_df(grouped_df.head(-val_size))
|
|
105
122
|
val_df = self._subsample_df(grouped_df.tail(val_size))
|
|
@@ -124,6 +141,7 @@ class CovariateRegressor:
|
|
|
124
141
|
# Has no effect since the model won't be saved to disk.
|
|
125
142
|
# We provide path to avoid https://github.com/autogluon/autogluon/issues/4832
|
|
126
143
|
path="",
|
|
144
|
+
name=self.model_type.__name__,
|
|
127
145
|
)
|
|
128
146
|
if time_limit is not None:
|
|
129
147
|
time_limit_fit = self.fit_time_fraction * (time_limit - (time.monotonic() - start_time))
|
|
@@ -155,7 +173,7 @@ class CovariateRegressor:
|
|
|
155
173
|
return data
|
|
156
174
|
|
|
157
175
|
def fit_transform(
|
|
158
|
-
self, data: TimeSeriesDataFrame, time_limit:
|
|
176
|
+
self, data: TimeSeriesDataFrame, time_limit: float | None = None, **kwargs
|
|
159
177
|
) -> TimeSeriesDataFrame:
|
|
160
178
|
if not self.is_fit() or self.refit_during_predict:
|
|
161
179
|
self.fit(data=data, time_limit=time_limit, **kwargs)
|
|
@@ -165,7 +183,7 @@ class CovariateRegressor:
|
|
|
165
183
|
self,
|
|
166
184
|
predictions: TimeSeriesDataFrame,
|
|
167
185
|
known_covariates: TimeSeriesDataFrame,
|
|
168
|
-
static_features:
|
|
186
|
+
static_features: pd.DataFrame | None,
|
|
169
187
|
) -> TimeSeriesDataFrame:
|
|
170
188
|
"""Add the tabular regressor predictions to the target column."""
|
|
171
189
|
if not self.disabled:
|
|
@@ -173,27 +191,29 @@ class CovariateRegressor:
|
|
|
173
191
|
predictions = predictions.assign(**{col: predictions[col] + y_pred for col in predictions.columns})
|
|
174
192
|
return predictions
|
|
175
193
|
|
|
176
|
-
def _predict(self, data: TimeSeriesDataFrame, static_features:
|
|
194
|
+
def _predict(self, data: TimeSeriesDataFrame, static_features: pd.DataFrame | None) -> np.ndarray:
|
|
177
195
|
"""Construct the tabular features matrix and make predictions"""
|
|
178
196
|
assert self.model is not None, "CovariateRegressor must be fit before calling predict."
|
|
179
197
|
tabular_df = self._get_tabular_df(data, static_features=static_features)
|
|
180
198
|
if not self.include_item_id:
|
|
181
|
-
tabular_df = tabular_df.drop(columns=[ITEMID])
|
|
199
|
+
tabular_df = tabular_df.drop(columns=[TimeSeriesDataFrame.ITEMID])
|
|
182
200
|
return self.model.predict(X=tabular_df)
|
|
183
201
|
|
|
184
202
|
def _get_tabular_df(
|
|
185
203
|
self,
|
|
186
204
|
data: TimeSeriesDataFrame,
|
|
187
|
-
static_features:
|
|
205
|
+
static_features: pd.DataFrame | None = None,
|
|
188
206
|
include_target: bool = False,
|
|
189
207
|
) -> pd.DataFrame:
|
|
190
208
|
"""Construct a tabular dataframe from known covariates and static features."""
|
|
191
|
-
available_columns = [ITEMID] + self.
|
|
209
|
+
available_columns = [TimeSeriesDataFrame.ITEMID] + self.covariate_metadata.known_covariates
|
|
192
210
|
if include_target:
|
|
193
211
|
available_columns += [self.target]
|
|
194
|
-
tabular_df =
|
|
212
|
+
tabular_df = (
|
|
213
|
+
pd.DataFrame(data).reset_index()[available_columns].astype({TimeSeriesDataFrame.ITEMID: "category"})
|
|
214
|
+
)
|
|
195
215
|
if static_features is not None and self.include_static_features:
|
|
196
|
-
tabular_df = pd.merge(tabular_df, static_features, on=ITEMID)
|
|
216
|
+
tabular_df = pd.merge(tabular_df, static_features, on=TimeSeriesDataFrame.ITEMID)
|
|
197
217
|
return tabular_df
|
|
198
218
|
|
|
199
219
|
def _subsample_df(self, df: pd.DataFrame) -> pd.DataFrame:
|
|
@@ -201,3 +221,33 @@ class CovariateRegressor:
|
|
|
201
221
|
if self.max_num_samples is not None and len(df) > self.max_num_samples:
|
|
202
222
|
df = df.sample(n=self.max_num_samples)
|
|
203
223
|
return df
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
@overload
|
|
227
|
+
def get_covariate_regressor(covariate_regressor: None, target: str, covariate_metadata: CovariateMetadata) -> None: ...
|
|
228
|
+
@overload
|
|
229
|
+
def get_covariate_regressor(
|
|
230
|
+
covariate_regressor: str | dict, target: str, covariate_metadata: CovariateMetadata
|
|
231
|
+
) -> CovariateRegressor: ...
|
|
232
|
+
def get_covariate_regressor(
|
|
233
|
+
covariate_regressor: str | dict | None, target: str, covariate_metadata: CovariateMetadata
|
|
234
|
+
) -> CovariateRegressor | None:
|
|
235
|
+
"""Create a CovariateRegressor object based on the value of the `covariate_regressor` hyperparameter."""
|
|
236
|
+
if covariate_regressor is None:
|
|
237
|
+
return None
|
|
238
|
+
elif len(covariate_metadata.known_covariates + covariate_metadata.static_features) == 0:
|
|
239
|
+
logger.info(
|
|
240
|
+
"\tSkipping covariate_regressor since the dataset contains no known_covariates or static_features."
|
|
241
|
+
)
|
|
242
|
+
return None
|
|
243
|
+
else:
|
|
244
|
+
if isinstance(covariate_regressor, str):
|
|
245
|
+
return GlobalCovariateRegressor(covariate_regressor, target=target, covariate_metadata=covariate_metadata)
|
|
246
|
+
elif isinstance(covariate_regressor, dict):
|
|
247
|
+
return GlobalCovariateRegressor(
|
|
248
|
+
**covariate_regressor, target=target, covariate_metadata=covariate_metadata
|
|
249
|
+
)
|
|
250
|
+
else:
|
|
251
|
+
raise ValueError(
|
|
252
|
+
f"Invalid value for covariate_regressor {covariate_regressor} of type {type(covariate_regressor)}"
|
|
253
|
+
)
|
autogluon/timeseries/splitter.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
from typing import Iterator
|
|
1
|
+
from typing import Iterator
|
|
2
2
|
|
|
3
|
-
from .dataset
|
|
3
|
+
from autogluon.timeseries.dataset import TimeSeriesDataFrame
|
|
4
4
|
|
|
5
5
|
__all__ = [
|
|
6
6
|
"AbstractWindowSplitter",
|
|
@@ -13,7 +13,7 @@ class AbstractWindowSplitter:
|
|
|
13
13
|
self.prediction_length = prediction_length
|
|
14
14
|
self.num_val_windows = num_val_windows
|
|
15
15
|
|
|
16
|
-
def split(self, data: TimeSeriesDataFrame) -> Iterator[
|
|
16
|
+
def split(self, data: TimeSeriesDataFrame) -> Iterator[tuple[TimeSeriesDataFrame, TimeSeriesDataFrame]]:
|
|
17
17
|
raise NotImplementedError
|
|
18
18
|
|
|
19
19
|
|
|
@@ -33,21 +33,21 @@ class ExpandingWindowSplitter(AbstractWindowSplitter):
|
|
|
33
33
|
|
|
34
34
|
Parameters
|
|
35
35
|
----------
|
|
36
|
-
prediction_length
|
|
36
|
+
prediction_length
|
|
37
37
|
Length of the forecast horizon.
|
|
38
|
-
num_val_windows
|
|
38
|
+
num_val_windows
|
|
39
39
|
Number of windows to generate from each time series in the dataset.
|
|
40
|
-
val_step_size
|
|
40
|
+
val_step_size
|
|
41
41
|
The end of each subsequent window is moved this many time steps forward.
|
|
42
42
|
"""
|
|
43
43
|
|
|
44
|
-
def __init__(self, prediction_length: int, num_val_windows: int = 1, val_step_size:
|
|
44
|
+
def __init__(self, prediction_length: int, num_val_windows: int = 1, val_step_size: int | None = None):
|
|
45
45
|
super().__init__(prediction_length=prediction_length, num_val_windows=num_val_windows)
|
|
46
46
|
if val_step_size is None:
|
|
47
47
|
val_step_size = prediction_length
|
|
48
48
|
self.val_step_size = val_step_size
|
|
49
49
|
|
|
50
|
-
def split(self, data: TimeSeriesDataFrame) -> Iterator[
|
|
50
|
+
def split(self, data: TimeSeriesDataFrame) -> Iterator[tuple[TimeSeriesDataFrame, TimeSeriesDataFrame]]:
|
|
51
51
|
"""Generate train and validation folds for a time series dataset."""
|
|
52
52
|
for window_idx in range(1, self.num_val_windows + 1):
|
|
53
53
|
val_end = -(self.num_val_windows - window_idx) * self.val_step_size
|
|
@@ -57,27 +57,3 @@ class ExpandingWindowSplitter(AbstractWindowSplitter):
|
|
|
57
57
|
train_data = data.slice_by_timestep(None, train_end)
|
|
58
58
|
val_data = data.slice_by_timestep(None, val_end)
|
|
59
59
|
yield train_data, val_data
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
class AbstractTimeSeriesSplitter:
|
|
63
|
-
def __init__(self, *args, **kwargs):
|
|
64
|
-
raise ValueError(
|
|
65
|
-
"`AbstractTimeSeriesSplitter` has been deprecated. "
|
|
66
|
-
"Please use `autogluon.timeseries.splitter.ExpandingWindowSplitter` instead."
|
|
67
|
-
)
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
class MultiWindowSplitter(AbstractTimeSeriesSplitter):
|
|
71
|
-
def __init__(self, *args, **kwargs):
|
|
72
|
-
raise ValueError(
|
|
73
|
-
"`MultiWindowSplitter` has been deprecated. "
|
|
74
|
-
"Please use `autogluon.timeseries.splitter.ExpandingWindowSplitter` instead."
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
class LastWindowSplitter(MultiWindowSplitter):
|
|
79
|
-
def __init__(self, *args, **kwargs):
|
|
80
|
-
raise ValueError(
|
|
81
|
-
"`LastWindowSplitter` has been deprecated. "
|
|
82
|
-
"Please use `autogluon.timeseries.splitter.ExpandingWindowSplitter` instead."
|
|
83
|
-
)
|