autogluon.timeseries 1.4.1b20250821__py3-none-any.whl → 1.4.1b20250822__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/dataset/ts_dataframe.py +9 -9
- autogluon/timeseries/learner.py +14 -14
- autogluon/timeseries/metrics/__init__.py +5 -5
- autogluon/timeseries/metrics/abstract.py +9 -9
- autogluon/timeseries/models/abstract/abstract_timeseries_model.py +39 -41
- autogluon/timeseries/models/abstract/tunable.py +6 -6
- autogluon/timeseries/models/autogluon_tabular/mlforecast.py +30 -30
- autogluon/timeseries/models/autogluon_tabular/per_step.py +12 -12
- autogluon/timeseries/models/chronos/model.py +10 -10
- autogluon/timeseries/models/chronos/pipeline/base.py +8 -8
- autogluon/timeseries/models/chronos/pipeline/chronos.py +12 -12
- autogluon/timeseries/models/chronos/pipeline/chronos_bolt.py +12 -12
- autogluon/timeseries/models/chronos/pipeline/utils.py +12 -12
- autogluon/timeseries/models/ensemble/abstract.py +19 -19
- autogluon/timeseries/models/ensemble/basic.py +8 -8
- autogluon/timeseries/models/ensemble/greedy.py +13 -13
- autogluon/timeseries/models/gluonts/abstract.py +24 -24
- autogluon/timeseries/models/gluonts/dataset.py +2 -2
- autogluon/timeseries/models/gluonts/models.py +7 -7
- autogluon/timeseries/models/local/abstract_local_model.py +12 -12
- autogluon/timeseries/models/local/statsforecast.py +11 -11
- autogluon/timeseries/models/multi_window/multi_window_model.py +4 -4
- autogluon/timeseries/models/presets.py +14 -14
- autogluon/timeseries/models/registry.py +3 -3
- autogluon/timeseries/predictor.py +35 -35
- autogluon/timeseries/regressor.py +13 -13
- autogluon/timeseries/splitter.py +6 -6
- autogluon/timeseries/trainer.py +50 -49
- autogluon/timeseries/transforms/covariate_scaler.py +3 -3
- autogluon/timeseries/transforms/target_scaler.py +7 -7
- autogluon/timeseries/utils/datetime/lags.py +2 -2
- autogluon/timeseries/utils/datetime/time_features.py +2 -2
- autogluon/timeseries/utils/features.py +31 -31
- autogluon/timeseries/version.py +1 -1
- {autogluon.timeseries-1.4.1b20250821.dist-info → autogluon.timeseries-1.4.1b20250822.dist-info}/METADATA +5 -5
- autogluon.timeseries-1.4.1b20250822.dist-info/RECORD +72 -0
- autogluon.timeseries-1.4.1b20250821.dist-info/RECORD +0 -72
- /autogluon.timeseries-1.4.1b20250821-py3.9-nspkg.pth → /autogluon.timeseries-1.4.1b20250822-py3.9-nspkg.pth +0 -0
- {autogluon.timeseries-1.4.1b20250821.dist-info → autogluon.timeseries-1.4.1b20250822.dist-info}/LICENSE +0 -0
- {autogluon.timeseries-1.4.1b20250821.dist-info → autogluon.timeseries-1.4.1b20250822.dist-info}/NOTICE +0 -0
- {autogluon.timeseries-1.4.1b20250821.dist-info → autogluon.timeseries-1.4.1b20250822.dist-info}/WHEEL +0 -0
- {autogluon.timeseries-1.4.1b20250821.dist-info → autogluon.timeseries-1.4.1b20250822.dist-info}/namespace_packages.txt +0 -0
- {autogluon.timeseries-1.4.1b20250821.dist-info → autogluon.timeseries-1.4.1b20250822.dist-info}/top_level.txt +0 -0
- {autogluon.timeseries-1.4.1b20250821.dist-info → autogluon.timeseries-1.4.1b20250822.dist-info}/zip-safe +0 -0
@@ -7,7 +7,7 @@ import reprlib
|
|
7
7
|
from collections.abc import Iterable
|
8
8
|
from itertools import islice
|
9
9
|
from pathlib import Path
|
10
|
-
from typing import TYPE_CHECKING, Any,
|
10
|
+
from typing import TYPE_CHECKING, Any, Optional, Type, Union, overload
|
11
11
|
|
12
12
|
import numpy as np
|
13
13
|
import pandas as pd
|
@@ -118,7 +118,7 @@ class TimeSeriesDataFrame(pd.DataFrame):
|
|
118
118
|
|
119
119
|
"""
|
120
120
|
|
121
|
-
index: pd.MultiIndex
|
121
|
+
index: pd.MultiIndex # type: ignore
|
122
122
|
_metadata = ["_static_features"]
|
123
123
|
|
124
124
|
def __init__(
|
@@ -572,7 +572,7 @@ class TimeSeriesDataFrame(pd.DataFrame):
|
|
572
572
|
self.static_features = other._static_features
|
573
573
|
return self
|
574
574
|
|
575
|
-
def split_by_time(self, cutoff_time: pd.Timestamp) ->
|
575
|
+
def split_by_time(self, cutoff_time: pd.Timestamp) -> tuple[TimeSeriesDataFrame, TimeSeriesDataFrame]:
|
576
576
|
"""Split dataframe to two different ``TimeSeriesDataFrame`` s before and after a certain ``cutoff_time``.
|
577
577
|
|
578
578
|
Parameters
|
@@ -900,15 +900,15 @@ class TimeSeriesDataFrame(pd.DataFrame):
|
|
900
900
|
return super().sort_index(*args, **kwargs) # type: ignore
|
901
901
|
|
902
902
|
def get_model_inputs_for_scoring(
|
903
|
-
self, prediction_length: int, known_covariates_names: Optional[
|
904
|
-
) ->
|
903
|
+
self, prediction_length: int, known_covariates_names: Optional[list[str]] = None
|
904
|
+
) -> tuple[TimeSeriesDataFrame, Optional[TimeSeriesDataFrame]]:
|
905
905
|
"""Prepare model inputs necessary to predict the last ``prediction_length`` time steps of each time series in the dataset.
|
906
906
|
|
907
907
|
Parameters
|
908
908
|
----------
|
909
909
|
prediction_length : int
|
910
910
|
The forecast horizon, i.e., How many time steps into the future must be predicted.
|
911
|
-
known_covariates_names :
|
911
|
+
known_covariates_names : list[str], optional
|
912
912
|
Names of the dataframe columns that contain covariates known in the future.
|
913
913
|
See ``known_covariates_names`` of :class:`~autogluon.timeseries.TimeSeriesPredictor` for more details.
|
914
914
|
|
@@ -933,7 +933,7 @@ class TimeSeriesDataFrame(pd.DataFrame):
|
|
933
933
|
prediction_length: int,
|
934
934
|
end_index: Optional[int] = None,
|
935
935
|
suffix: Optional[str] = None,
|
936
|
-
) ->
|
936
|
+
) -> tuple[TimeSeriesDataFrame, TimeSeriesDataFrame]:
|
937
937
|
"""Generate a train/test split from the given dataset.
|
938
938
|
|
939
939
|
This method can be used to generate splits for multi-window backtesting.
|
@@ -1083,7 +1083,7 @@ class TimeSeriesDataFrame(pd.DataFrame):
|
|
1083
1083
|
iterable = iter(iterable)
|
1084
1084
|
return iter(lambda: tuple(islice(iterable, size)), ())
|
1085
1085
|
|
1086
|
-
def resample_chunk(chunk: Iterable[
|
1086
|
+
def resample_chunk(chunk: Iterable[tuple[str, pd.DataFrame]]) -> pd.DataFrame:
|
1087
1087
|
resampled_dfs = []
|
1088
1088
|
for item_id, df in chunk:
|
1089
1089
|
resampled_df = df.resample(offset, level=TIMESTAMP, **kwargs).agg(aggregation)
|
@@ -1139,6 +1139,6 @@ class TimeSeriesDataFrame(pd.DataFrame):
|
|
1139
1139
|
...
|
1140
1140
|
|
1141
1141
|
@overload
|
1142
|
-
def __getitem__(self, items:
|
1142
|
+
def __getitem__(self, items: list[str]) -> Self: ... # type: ignore
|
1143
1143
|
@overload
|
1144
1144
|
def __getitem__(self, item: str) -> pd.Series: ... # type: ignore
|
autogluon/timeseries/learner.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import logging
|
2
2
|
import reprlib
|
3
3
|
import time
|
4
|
-
from typing import Any,
|
4
|
+
from typing import Any, Literal, Optional, Type, Union
|
5
5
|
|
6
6
|
import pandas as pd
|
7
7
|
|
@@ -26,7 +26,7 @@ class TimeSeriesLearner(AbstractLearner):
|
|
26
26
|
self,
|
27
27
|
path_context: str,
|
28
28
|
target: str = "target",
|
29
|
-
known_covariates_names: Optional[
|
29
|
+
known_covariates_names: Optional[list[str]] = None,
|
30
30
|
trainer_type: Type[TimeSeriesTrainer] = TimeSeriesTrainer,
|
31
31
|
eval_metric: Union[str, TimeSeriesScorer, None] = None,
|
32
32
|
prediction_length: int = 1,
|
@@ -56,7 +56,7 @@ class TimeSeriesLearner(AbstractLearner):
|
|
56
56
|
def fit(
|
57
57
|
self,
|
58
58
|
train_data: TimeSeriesDataFrame,
|
59
|
-
hyperparameters: Union[str,
|
59
|
+
hyperparameters: Union[str, dict],
|
60
60
|
val_data: Optional[TimeSeriesDataFrame] = None,
|
61
61
|
hyperparameter_tune_kwargs: Optional[Union[str, dict]] = None,
|
62
62
|
time_limit: Optional[float] = None,
|
@@ -194,9 +194,9 @@ class TimeSeriesLearner(AbstractLearner):
|
|
194
194
|
self,
|
195
195
|
data: TimeSeriesDataFrame,
|
196
196
|
model: Optional[str] = None,
|
197
|
-
metrics: Optional[Union[str, TimeSeriesScorer,
|
197
|
+
metrics: Optional[Union[str, TimeSeriesScorer, list[Union[str, TimeSeriesScorer]]]] = None,
|
198
198
|
use_cache: bool = True,
|
199
|
-
) ->
|
199
|
+
) -> dict[str, float]:
|
200
200
|
data = self.feature_generator.transform(data)
|
201
201
|
return self.load_trainer().evaluate(data=data, model=model, metrics=metrics, use_cache=use_cache)
|
202
202
|
|
@@ -205,7 +205,7 @@ class TimeSeriesLearner(AbstractLearner):
|
|
205
205
|
data: Optional[TimeSeriesDataFrame] = None,
|
206
206
|
model: Optional[str] = None,
|
207
207
|
metric: Optional[Union[str, TimeSeriesScorer]] = None,
|
208
|
-
features: Optional[
|
208
|
+
features: Optional[list[str]] = None,
|
209
209
|
time_limit: Optional[float] = None,
|
210
210
|
method: Literal["naive", "permutation"] = "permutation",
|
211
211
|
subsample_size: int = 50,
|
@@ -273,7 +273,7 @@ class TimeSeriesLearner(AbstractLearner):
|
|
273
273
|
self,
|
274
274
|
data: Optional[TimeSeriesDataFrame] = None,
|
275
275
|
extra_info: bool = False,
|
276
|
-
extra_metrics: Optional[
|
276
|
+
extra_metrics: Optional[list[Union[str, TimeSeriesScorer]]] = None,
|
277
277
|
use_cache: bool = True,
|
278
278
|
) -> pd.DataFrame:
|
279
279
|
if data is not None:
|
@@ -282,7 +282,7 @@ class TimeSeriesLearner(AbstractLearner):
|
|
282
282
|
data, extra_info=extra_info, extra_metrics=extra_metrics, use_cache=use_cache
|
283
283
|
)
|
284
284
|
|
285
|
-
def get_info(self, include_model_info: bool = False, **kwargs) ->
|
285
|
+
def get_info(self, include_model_info: bool = False, **kwargs) -> dict[str, Any]:
|
286
286
|
learner_info = super().get_info(include_model_info=include_model_info)
|
287
287
|
trainer = self.load_trainer()
|
288
288
|
trainer_info = trainer.get_info(include_model_info=include_model_info)
|
@@ -300,31 +300,31 @@ class TimeSeriesLearner(AbstractLearner):
|
|
300
300
|
return learner_info
|
301
301
|
|
302
302
|
def persist_trainer(
|
303
|
-
self, models: Union[Literal["all", "best"],
|
304
|
-
) ->
|
303
|
+
self, models: Union[Literal["all", "best"], list[str]] = "all", with_ancestors: bool = False
|
304
|
+
) -> list[str]:
|
305
305
|
"""Loads models and trainer in memory so that they don't have to be
|
306
306
|
loaded during predictions
|
307
307
|
|
308
308
|
Returns
|
309
309
|
-------
|
310
|
-
list_of_models
|
310
|
+
list_of_models
|
311
311
|
List of models persisted in memory
|
312
312
|
"""
|
313
313
|
self.trainer = self.load_trainer()
|
314
314
|
return self.trainer.persist(models, with_ancestors=with_ancestors)
|
315
315
|
|
316
|
-
def unpersist_trainer(self) ->
|
316
|
+
def unpersist_trainer(self) -> list[str]:
|
317
317
|
"""Unloads models and trainer from memory. Models will have to be reloaded from disk
|
318
318
|
when predicting.
|
319
319
|
|
320
320
|
Returns
|
321
321
|
-------
|
322
|
-
list_of_models
|
322
|
+
list_of_models
|
323
323
|
List of models removed from memory
|
324
324
|
"""
|
325
325
|
unpersisted_models = self.load_trainer().unpersist()
|
326
326
|
self.trainer = None # type: ignore
|
327
327
|
return unpersisted_models
|
328
328
|
|
329
|
-
def refit_full(self, model: str = "all") ->
|
329
|
+
def refit_full(self, model: str = "all") -> dict[str, str]:
|
330
330
|
return self.load_trainer().refit_full(model=model)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
3
|
from pprint import pformat
|
4
|
-
from typing import Any,
|
4
|
+
from typing import Any, Optional, Sequence, Type, Union
|
5
5
|
|
6
6
|
import numpy as np
|
7
7
|
|
@@ -28,7 +28,7 @@ __all__ = [
|
|
28
28
|
|
29
29
|
DEFAULT_METRIC_NAME = "WQL"
|
30
30
|
|
31
|
-
AVAILABLE_METRICS:
|
31
|
+
AVAILABLE_METRICS: dict[str, Type[TimeSeriesScorer]] = {
|
32
32
|
"MASE": MASE,
|
33
33
|
"MAPE": MAPE,
|
34
34
|
"SMAPE": SMAPE,
|
@@ -48,7 +48,7 @@ DEPRECATED_METRICS = {
|
|
48
48
|
}
|
49
49
|
|
50
50
|
# Experimental metrics that are not yet user facing
|
51
|
-
EXPERIMENTAL_METRICS:
|
51
|
+
EXPERIMENTAL_METRICS: dict[str, Type[TimeSeriesScorer]] = {
|
52
52
|
"WCD": WCD,
|
53
53
|
}
|
54
54
|
|
@@ -63,7 +63,7 @@ def check_get_evaluation_metric(
|
|
63
63
|
|
64
64
|
Returns
|
65
65
|
-------
|
66
|
-
scorer
|
66
|
+
scorer
|
67
67
|
A `TimeSeriesScorer` object based on the provided `eval_metric`.
|
68
68
|
|
69
69
|
`scorer.prediction_length` is always set to the `prediction_length` provided to this method.
|
@@ -75,7 +75,7 @@ def check_get_evaluation_metric(
|
|
75
75
|
value of `horizon_weight` is kept.
|
76
76
|
"""
|
77
77
|
scorer: TimeSeriesScorer
|
78
|
-
metric_kwargs:
|
78
|
+
metric_kwargs: dict[str, Any] = dict(
|
79
79
|
prediction_length=prediction_length, seasonal_period=seasonal_period, horizon_weight=horizon_weight
|
80
80
|
)
|
81
81
|
if isinstance(eval_metric, TimeSeriesScorer):
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import warnings
|
2
|
-
from typing import Optional, Sequence,
|
2
|
+
from typing import Optional, Sequence, Union, overload
|
3
3
|
|
4
4
|
import numpy as np
|
5
5
|
import numpy.typing as npt
|
@@ -200,14 +200,14 @@ class TimeSeriesScorer:
|
|
200
200
|
@staticmethod
|
201
201
|
def _get_point_forecast_score_inputs(
|
202
202
|
data_future: TimeSeriesDataFrame, predictions: TimeSeriesDataFrame, target: str = "target"
|
203
|
-
) ->
|
203
|
+
) -> tuple[pd.Series, pd.Series]:
|
204
204
|
"""Get inputs necessary to compute point forecast metrics.
|
205
205
|
|
206
206
|
Returns
|
207
207
|
-------
|
208
|
-
y_true
|
208
|
+
y_true
|
209
209
|
Target time series values during the forecast horizon.
|
210
|
-
y_pred
|
210
|
+
y_pred
|
211
211
|
Predicted time series values during the forecast horizon.
|
212
212
|
"""
|
213
213
|
y_true = data_future[target]
|
@@ -217,16 +217,16 @@ class TimeSeriesScorer:
|
|
217
217
|
@staticmethod
|
218
218
|
def _get_quantile_forecast_score_inputs(
|
219
219
|
data_future: TimeSeriesDataFrame, predictions: TimeSeriesDataFrame, target: str = "target"
|
220
|
-
) ->
|
220
|
+
) -> tuple[pd.Series, pd.DataFrame, np.ndarray]:
|
221
221
|
"""Get inputs necessary to compute quantile forecast metrics.
|
222
222
|
|
223
223
|
Returns
|
224
224
|
-------
|
225
|
-
y_true
|
225
|
+
y_true
|
226
226
|
Target time series values during the forecast horizon.
|
227
|
-
q_pred
|
227
|
+
q_pred
|
228
228
|
Quantile forecast for each predicted quantile level. Column order corresponds to ``quantile_levels``.
|
229
|
-
quantile_levels
|
229
|
+
quantile_levels
|
230
230
|
Quantile levels for which the forecasts are generated (as floats).
|
231
231
|
"""
|
232
232
|
quantile_columns = [col for col in predictions.columns if col != "mean"]
|
@@ -253,7 +253,7 @@ class TimeSeriesScorer:
|
|
253
253
|
|
254
254
|
Returns
|
255
255
|
-------
|
256
|
-
horizon_weight
|
256
|
+
horizon_weight
|
257
257
|
None if the input is None, otherwise a numpy array of shape [1, prediction_length].
|
258
258
|
"""
|
259
259
|
if horizon_weight is None:
|
@@ -1,12 +1,10 @@
|
|
1
|
-
from __future__ import annotations
|
2
|
-
|
3
1
|
import copy
|
4
2
|
import logging
|
5
3
|
import os
|
6
4
|
import re
|
7
5
|
import time
|
8
6
|
from abc import ABC, abstractmethod
|
9
|
-
from typing import Any,
|
7
|
+
from typing import Any, Optional, Sequence, Union
|
10
8
|
|
11
9
|
import pandas as pd
|
12
10
|
from typing_extensions import Self
|
@@ -38,27 +36,27 @@ class TimeSeriesModelBase(ModelBase, ABC):
|
|
38
36
|
|
39
37
|
Parameters
|
40
38
|
----------
|
41
|
-
path
|
39
|
+
path
|
42
40
|
Directory location to store all outputs.
|
43
41
|
If None, a new unique time-stamped directory is chosen.
|
44
|
-
freq
|
42
|
+
freq
|
45
43
|
Frequency string (cf. gluonts frequency strings) describing the frequency
|
46
44
|
of the time series data. For example, "h" for hourly or "D" for daily data.
|
47
|
-
prediction_length
|
45
|
+
prediction_length
|
48
46
|
Length of the prediction horizon, i.e., the number of time steps the model
|
49
47
|
is fit to forecast.
|
50
|
-
name
|
48
|
+
name
|
51
49
|
Name of the subdirectory inside path where model will be saved.
|
52
50
|
The final model directory will be os.path.join(path, name)
|
53
51
|
If None, defaults to the model's class name: self.__class__.__name__
|
54
|
-
covariate_metadata
|
52
|
+
covariate_metadata
|
55
53
|
A mapping of different covariate types known to autogluon.timeseries to column names
|
56
54
|
in the data set.
|
57
|
-
eval_metric
|
55
|
+
eval_metric
|
58
56
|
Metric by which predictions will be ultimately evaluated on future test data. This only impacts
|
59
57
|
``model.score()``, as eval_metric is not used during training. Available metrics can be found in
|
60
58
|
``autogluon.timeseries.metrics``.
|
61
|
-
hyperparameters
|
59
|
+
hyperparameters
|
62
60
|
Hyperparameters that will be used by the model (can be search spaces instead of fixed values).
|
63
61
|
If None, model defaults are used. This is identical to passing an empty dictionary.
|
64
62
|
"""
|
@@ -79,7 +77,7 @@ class TimeSeriesModelBase(ModelBase, ABC):
|
|
79
77
|
self,
|
80
78
|
path: Optional[str] = None,
|
81
79
|
name: Optional[str] = None,
|
82
|
-
hyperparameters: Optional[
|
80
|
+
hyperparameters: Optional[dict[str, Any]] = None,
|
83
81
|
freq: Optional[str] = None,
|
84
82
|
prediction_length: int = 1,
|
85
83
|
covariate_metadata: Optional[CovariateMetadata] = None,
|
@@ -119,7 +117,7 @@ class TimeSeriesModelBase(ModelBase, ABC):
|
|
119
117
|
else:
|
120
118
|
self.must_drop_median = False
|
121
119
|
|
122
|
-
self._oof_predictions: Optional[
|
120
|
+
self._oof_predictions: Optional[list[TimeSeriesDataFrame]] = None
|
123
121
|
|
124
122
|
# user provided hyperparameters and extra arguments that are used during model training
|
125
123
|
self._hyperparameters, self._extra_ag_args = self._check_and_split_hyperparameters(hyperparameters)
|
@@ -147,22 +145,21 @@ class TimeSeriesModelBase(ModelBase, ABC):
|
|
147
145
|
|
148
146
|
@classmethod
|
149
147
|
def _check_and_split_hyperparameters(
|
150
|
-
cls, hyperparameters: Optional[
|
151
|
-
) ->
|
152
|
-
"""
|
153
|
-
Given the user-specified hyperparameters, split into `hyperparameters` and `extra_ag_args`, intended
|
148
|
+
cls, hyperparameters: Optional[dict[str, Any]] = None
|
149
|
+
) -> tuple[dict[str, Any], dict[str, Any]]:
|
150
|
+
"""Given the user-specified hyperparameters, split into `hyperparameters` and `extra_ag_args`, intended
|
154
151
|
to be used during model initialization.
|
155
152
|
|
156
153
|
Parameters
|
157
154
|
----------
|
158
|
-
hyperparameters
|
155
|
+
hyperparameters
|
159
156
|
The model hyperparameters dictionary provided to the model constructor.
|
160
157
|
|
161
158
|
Returns
|
162
159
|
-------
|
163
|
-
hyperparameters
|
160
|
+
hyperparameters
|
164
161
|
Native model hyperparameters that are passed into the "inner model" AutoGluon wraps
|
165
|
-
extra_ag_args
|
162
|
+
extra_ag_args
|
166
163
|
Special auxiliary parameters that modify the model training process used by AutoGluon
|
167
164
|
"""
|
168
165
|
hyperparameters = copy.deepcopy(hyperparameters) if hyperparameters is not None else dict()
|
@@ -214,7 +211,7 @@ class TimeSeriesModelBase(ModelBase, ABC):
|
|
214
211
|
return model
|
215
212
|
|
216
213
|
@classmethod
|
217
|
-
def load_oof_predictions(cls, path: str, verbose: bool = True) ->
|
214
|
+
def load_oof_predictions(cls, path: str, verbose: bool = True) -> list[TimeSeriesDataFrame]:
|
218
215
|
"""Load the cached OOF predictions from disk."""
|
219
216
|
return load_pkl.load(path=os.path.join(path, "utils", cls._oof_filename), verbose=verbose)
|
220
217
|
|
@@ -284,7 +281,7 @@ class TimeSeriesModelBase(ModelBase, ABC):
|
|
284
281
|
return False
|
285
282
|
|
286
283
|
@staticmethod
|
287
|
-
def _get_system_resources() ->
|
284
|
+
def _get_system_resources() -> dict[str, Any]:
|
288
285
|
resource_manager = get_resource_manager()
|
289
286
|
system_num_cpus = resource_manager.get_cpu_count()
|
290
287
|
system_num_gpus = resource_manager.get_gpu_count()
|
@@ -306,7 +303,8 @@ class TimeSeriesModelBase(ModelBase, ABC):
|
|
306
303
|
def _more_tags(self) -> dict:
|
307
304
|
"""Encode model properties using tags, similar to sklearn & autogluon.tabular.
|
308
305
|
|
309
|
-
For more details, see `autogluon.core.models.abstract.AbstractModel._get_tags()` and
|
306
|
+
For more details, see `autogluon.core.models.abstract.AbstractModel._get_tags()` and
|
307
|
+
https://scikit-learn.org/stable/_sources/developers/develop.rst.txt.
|
310
308
|
|
311
309
|
List of currently supported tags:
|
312
310
|
- allow_nan: Can the model handle data with missing values represented by np.nan?
|
@@ -388,7 +386,7 @@ class AbstractTimeSeriesModel(TimeSeriesModelBase, TimeSeriesTunable, metaclass=
|
|
388
386
|
self,
|
389
387
|
path: Optional[str] = None,
|
390
388
|
name: Optional[str] = None,
|
391
|
-
hyperparameters: Optional[
|
389
|
+
hyperparameters: Optional[dict[str, Any]] = None,
|
392
390
|
freq: Optional[str] = None,
|
393
391
|
prediction_length: int = 1,
|
394
392
|
covariate_metadata: Optional[CovariateMetadata] = None,
|
@@ -428,7 +426,7 @@ class AbstractTimeSeriesModel(TimeSeriesModelBase, TimeSeriesTunable, metaclass=
|
|
428
426
|
)
|
429
427
|
|
430
428
|
@property
|
431
|
-
def allowed_hyperparameters(self) ->
|
429
|
+
def allowed_hyperparameters(self) -> list[str]:
|
432
430
|
"""List of hyperparameters allowed by the model."""
|
433
431
|
return ["target_scaler", "covariate_regressor", "covariate_scaler"]
|
434
432
|
|
@@ -445,32 +443,32 @@ class AbstractTimeSeriesModel(TimeSeriesModelBase, TimeSeriesTunable, metaclass=
|
|
445
443
|
Models should not override the `fit` method, but instead override the `_fit` method which
|
446
444
|
has the same arguments.
|
447
445
|
|
448
|
-
|
449
|
-
|
450
|
-
train_data
|
446
|
+
Parameters
|
447
|
+
----------
|
448
|
+
train_data
|
451
449
|
The training data provided in the library's `autogluon.timeseries.dataset.TimeSeriesDataFrame`
|
452
450
|
format.
|
453
|
-
val_data
|
451
|
+
val_data
|
454
452
|
The validation data set in the same format as training data.
|
455
|
-
time_limit
|
453
|
+
time_limit
|
456
454
|
Time limit in seconds to adhere to when fitting model.
|
457
455
|
Ideally, model should early stop during fit to avoid going over the time limit if specified.
|
458
|
-
num_cpus
|
456
|
+
num_cpus
|
459
457
|
How many CPUs to use during fit.
|
460
458
|
This is counted in virtual cores, not in physical cores.
|
461
459
|
If 'auto', model decides.
|
462
|
-
num_gpus
|
460
|
+
num_gpus
|
463
461
|
How many GPUs to use during fit.
|
464
462
|
If 'auto', model decides.
|
465
|
-
verbosity
|
463
|
+
verbosity
|
466
464
|
Verbosity levels range from 0 to 4 and control how much information is printed.
|
467
465
|
Higher levels correspond to more detailed print statements (you can set verbosity = 0 to suppress warnings).
|
468
|
-
**kwargs
|
466
|
+
**kwargs
|
469
467
|
Any additional fit arguments a model supports.
|
470
468
|
|
471
469
|
Returns
|
472
470
|
-------
|
473
|
-
model
|
471
|
+
model
|
474
472
|
The fitted model object
|
475
473
|
"""
|
476
474
|
start_time = time.monotonic()
|
@@ -553,7 +551,7 @@ class AbstractTimeSeriesModel(TimeSeriesModelBase, TimeSeriesTunable, metaclass=
|
|
553
551
|
"as hyperparameters when initializing or use `hyperparameter_tune` instead."
|
554
552
|
)
|
555
553
|
|
556
|
-
def _log_unused_hyperparameters(self, extra_allowed_hyperparameters: list[str]
|
554
|
+
def _log_unused_hyperparameters(self, extra_allowed_hyperparameters: Optional[list[str]] = None) -> None:
|
557
555
|
"""Log a warning if unused hyperparameters were provided to the model."""
|
558
556
|
allowed_hyperparameters = self.allowed_hyperparameters
|
559
557
|
if extra_allowed_hyperparameters is not None:
|
@@ -581,15 +579,15 @@ class AbstractTimeSeriesModel(TimeSeriesModelBase, TimeSeriesTunable, metaclass=
|
|
581
579
|
|
582
580
|
Parameters
|
583
581
|
----------
|
584
|
-
data
|
582
|
+
data
|
585
583
|
The dataset where each time series is the "context" for predictions. For ensemble models that depend on
|
586
584
|
the predictions of other models, this method may accept a dictionary of previous models' predictions.
|
587
|
-
known_covariates
|
585
|
+
known_covariates
|
588
586
|
A TimeSeriesDataFrame containing the values of the known covariates during the forecast horizon.
|
589
587
|
|
590
588
|
Returns
|
591
589
|
-------
|
592
|
-
predictions
|
590
|
+
predictions
|
593
591
|
pandas dataframes with a timestamp index, where each input item from the input
|
594
592
|
data is given as a separate forecast item in the dictionary, keyed by the `item_id`s
|
595
593
|
of input items.
|
@@ -705,12 +703,12 @@ class AbstractTimeSeriesModel(TimeSeriesModelBase, TimeSeriesTunable, metaclass=
|
|
705
703
|
|
706
704
|
Parameters
|
707
705
|
----------
|
708
|
-
data
|
706
|
+
data
|
709
707
|
Dataset used for scoring.
|
710
708
|
|
711
709
|
Returns
|
712
710
|
-------
|
713
|
-
score
|
711
|
+
score
|
714
712
|
The computed forecast evaluation score on the last `self.prediction_length`
|
715
713
|
time steps of each time series.
|
716
714
|
"""
|
@@ -745,6 +743,6 @@ class AbstractTimeSeriesModel(TimeSeriesModelBase, TimeSeriesTunable, metaclass=
|
|
745
743
|
known_covariates: Optional[TimeSeriesDataFrame] = None,
|
746
744
|
is_train: bool = False,
|
747
745
|
**kwargs,
|
748
|
-
) ->
|
746
|
+
) -> tuple[TimeSeriesDataFrame, Optional[TimeSeriesDataFrame]]:
|
749
747
|
"""Method that implements model-specific preprocessing logic."""
|
750
748
|
return data, known_covariates
|
@@ -5,7 +5,7 @@ import os
|
|
5
5
|
import time
|
6
6
|
from abc import ABC, abstractmethod
|
7
7
|
from contextlib import nullcontext
|
8
|
-
from typing import Any,
|
8
|
+
from typing import Any, Optional, Union
|
9
9
|
|
10
10
|
from typing_extensions import Self
|
11
11
|
|
@@ -43,7 +43,7 @@ class TimeSeriesTunable(Tunable, ABC):
|
|
43
43
|
refit_every_n_windows: Optional[int] = 1,
|
44
44
|
hyperparameter_tune_kwargs: Union[str, dict] = "auto",
|
45
45
|
time_limit: Optional[float] = None,
|
46
|
-
) ->
|
46
|
+
) -> tuple[dict[str, Any], Any]:
|
47
47
|
hpo_executor = self._get_default_hpo_executor()
|
48
48
|
hpo_executor.initialize(
|
49
49
|
hyperparameter_tune_kwargs, default_num_trials=default_num_trials, time_limit=time_limit
|
@@ -144,14 +144,14 @@ class TimeSeriesTunable(Tunable, ABC):
|
|
144
144
|
"""
|
145
145
|
return None
|
146
146
|
|
147
|
-
def get_minimum_resources(self, is_gpu_available: bool = False) ->
|
147
|
+
def get_minimum_resources(self, is_gpu_available: bool = False) -> dict[str, Union[int, float]]:
|
148
148
|
return {
|
149
149
|
"num_cpus": 1,
|
150
150
|
}
|
151
151
|
|
152
152
|
def _save_with_data(
|
153
153
|
self, train_data: TimeSeriesDataFrame, val_data: Optional[TimeSeriesDataFrame]
|
154
|
-
) ->
|
154
|
+
) -> tuple[str, str]:
|
155
155
|
self.path = os.path.abspath(self.path)
|
156
156
|
self.path_root = self.path.rsplit(self.name, 1)[0]
|
157
157
|
|
@@ -173,7 +173,7 @@ class TimeSeriesTunable(Tunable, ABC):
|
|
173
173
|
pass
|
174
174
|
|
175
175
|
@abstractmethod
|
176
|
-
def _get_search_space(self) ->
|
176
|
+
def _get_search_space(self) -> dict[str, Any]:
|
177
177
|
pass
|
178
178
|
|
179
179
|
@abstractmethod
|
@@ -185,5 +185,5 @@ class TimeSeriesTunable(Tunable, ABC):
|
|
185
185
|
|
186
186
|
@staticmethod
|
187
187
|
@abstractmethod
|
188
|
-
def _get_system_resources() ->
|
188
|
+
def _get_system_resources() -> dict[str, Any]:
|
189
189
|
pass
|