autogluon.timeseries 1.4.1b20250820__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.1b20250820.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.1b20250820.dist-info/RECORD +0 -72
- /autogluon.timeseries-1.4.1b20250820-py3.9-nspkg.pth → /autogluon.timeseries-1.4.1b20250822-py3.9-nspkg.pth +0 -0
- {autogluon.timeseries-1.4.1b20250820.dist-info → autogluon.timeseries-1.4.1b20250822.dist-info}/LICENSE +0 -0
- {autogluon.timeseries-1.4.1b20250820.dist-info → autogluon.timeseries-1.4.1b20250822.dist-info}/NOTICE +0 -0
- {autogluon.timeseries-1.4.1b20250820.dist-info → autogluon.timeseries-1.4.1b20250822.dist-info}/WHEEL +0 -0
- {autogluon.timeseries-1.4.1b20250820.dist-info → autogluon.timeseries-1.4.1b20250822.dist-info}/namespace_packages.txt +0 -0
- {autogluon.timeseries-1.4.1b20250820.dist-info → autogluon.timeseries-1.4.1b20250822.dist-info}/top_level.txt +0 -0
- {autogluon.timeseries-1.4.1b20250820.dist-info → autogluon.timeseries-1.4.1b20250822.dist-info}/zip-safe +0 -0
@@ -1,5 +1,5 @@
|
|
1
1
|
import logging
|
2
|
-
from typing import Any,
|
2
|
+
from typing import Any, Optional, Type
|
3
3
|
|
4
4
|
import numpy as np
|
5
5
|
import pandas as pd
|
@@ -14,7 +14,7 @@ class AbstractStatsForecastModel(AbstractLocalModel):
|
|
14
14
|
|
15
15
|
init_time_in_seconds = 15 # numba compilation for the first run
|
16
16
|
|
17
|
-
def _update_local_model_args(self, local_model_args:
|
17
|
+
def _update_local_model_args(self, local_model_args: dict[str, Any]) -> dict[str, Any]:
|
18
18
|
seasonal_period = local_model_args.pop("seasonal_period")
|
19
19
|
local_model_args["season_length"] = seasonal_period
|
20
20
|
return local_model_args
|
@@ -22,7 +22,7 @@ class AbstractStatsForecastModel(AbstractLocalModel):
|
|
22
22
|
def _get_model_type(self, variant: Optional[str] = None) -> Type:
|
23
23
|
raise NotImplementedError
|
24
24
|
|
25
|
-
def _get_local_model(self, local_model_args:
|
25
|
+
def _get_local_model(self, local_model_args: dict):
|
26
26
|
local_model_args = local_model_args.copy()
|
27
27
|
variant = local_model_args.pop("variant", None)
|
28
28
|
model_type = self._get_model_type(variant)
|
@@ -31,7 +31,7 @@ class AbstractStatsForecastModel(AbstractLocalModel):
|
|
31
31
|
def _get_point_forecast(
|
32
32
|
self,
|
33
33
|
time_series: pd.Series,
|
34
|
-
local_model_args:
|
34
|
+
local_model_args: dict,
|
35
35
|
) -> np.ndarray:
|
36
36
|
return self._get_local_model(local_model_args).forecast(
|
37
37
|
h=self.prediction_length, y=time_series.values.ravel()
|
@@ -176,9 +176,9 @@ class ARIMAModel(AbstractProbabilisticStatsForecastModel):
|
|
176
176
|
|
177
177
|
Other Parameters
|
178
178
|
----------------
|
179
|
-
order:
|
179
|
+
order: tuple[int, int, int], default = (1, 1, 1)
|
180
180
|
The (p, d, q) order of the model for the number of AR parameters, differences, and MA parameters to use.
|
181
|
-
seasonal_order:
|
181
|
+
seasonal_order: tuple[int, int, int], default = (0, 0, 0)
|
182
182
|
The (P, D, Q) parameters of the seasonal ARIMA model. Setting to (0, 0, 0) disables seasonality.
|
183
183
|
include_mean : bool, default = True
|
184
184
|
Should the ARIMA model include a mean term?
|
@@ -194,7 +194,7 @@ class ARIMAModel(AbstractProbabilisticStatsForecastModel):
|
|
194
194
|
method : {"CSS-ML", "CSS", "ML"}, default = "CSS-ML"
|
195
195
|
Fitting method: CSS (conditional sum of squares), ML (maximum likelihood), CSS-ML (initialize with CSS, then
|
196
196
|
optimize with ML).
|
197
|
-
fixed :
|
197
|
+
fixed : dict[str, float], optional
|
198
198
|
Dictionary containing fixed coefficients for the ARIMA model.
|
199
199
|
seasonal_period : int or None, default = None
|
200
200
|
Number of time steps in a complete seasonal cycle for seasonal models. For example, 7 for daily data with a
|
@@ -449,7 +449,7 @@ class AbstractConformalizedStatsForecastModel(AbstractStatsForecastModel):
|
|
449
449
|
def _get_nonconformity_scores(
|
450
450
|
self,
|
451
451
|
time_series: pd.Series,
|
452
|
-
local_model_args:
|
452
|
+
local_model_args: dict,
|
453
453
|
) -> np.ndarray:
|
454
454
|
h = self.prediction_length
|
455
455
|
y = time_series.values.ravel()
|
@@ -556,7 +556,7 @@ class AutoCESModel(AbstractProbabilisticStatsForecastModel):
|
|
556
556
|
local_model_args.setdefault("model", "Z")
|
557
557
|
return local_model_args
|
558
558
|
|
559
|
-
def _get_point_forecast(self, time_series: pd.Series, local_model_args:
|
559
|
+
def _get_point_forecast(self, time_series: pd.Series, local_model_args: dict):
|
560
560
|
# Disable seasonality if time series too short for chosen season_length or season_length == 1,
|
561
561
|
# otherwise model will crash
|
562
562
|
if len(time_series) < 5:
|
@@ -568,7 +568,7 @@ class AutoCESModel(AbstractProbabilisticStatsForecastModel):
|
|
568
568
|
|
569
569
|
|
570
570
|
class AbstractStatsForecastIntermittentDemandModel(AbstractConformalizedStatsForecastModel):
|
571
|
-
def _update_local_model_args(self, local_model_args:
|
571
|
+
def _update_local_model_args(self, local_model_args: dict[str, Any]) -> dict[str, Any]:
|
572
572
|
_ = local_model_args.pop("seasonal_period")
|
573
573
|
return local_model_args
|
574
574
|
|
@@ -733,6 +733,6 @@ class ZeroModel(AbstractStatsForecastIntermittentDemandModel):
|
|
733
733
|
def _get_point_forecast(
|
734
734
|
self,
|
735
735
|
time_series: pd.Series,
|
736
|
-
local_model_args:
|
736
|
+
local_model_args: dict,
|
737
737
|
):
|
738
738
|
return np.zeros(self.prediction_length)
|
@@ -4,7 +4,7 @@ import logging
|
|
4
4
|
import math
|
5
5
|
import os
|
6
6
|
import time
|
7
|
-
from typing import Any,
|
7
|
+
from typing import Any, Optional, Type, Union
|
8
8
|
|
9
9
|
import numpy as np
|
10
10
|
|
@@ -25,10 +25,10 @@ class MultiWindowBacktestingModel(AbstractTimeSeriesModel):
|
|
25
25
|
|
26
26
|
Parameters
|
27
27
|
----------
|
28
|
-
model_base
|
28
|
+
model_base
|
29
29
|
The base model to repeatedly train. If a AbstractTimeSeriesModel class, then also provide model_base_kwargs
|
30
30
|
which will be used to initialize the model via model_base(**model_base_kwargs).
|
31
|
-
model_base_kwargs
|
31
|
+
model_base_kwargs
|
32
32
|
kwargs used to initialize model_base if model_base is a class.
|
33
33
|
"""
|
34
34
|
|
@@ -38,7 +38,7 @@ class MultiWindowBacktestingModel(AbstractTimeSeriesModel):
|
|
38
38
|
def __init__(
|
39
39
|
self,
|
40
40
|
model_base: Union[AbstractTimeSeriesModel, Type[AbstractTimeSeriesModel]],
|
41
|
-
model_base_kwargs: Optional[
|
41
|
+
model_base_kwargs: Optional[dict[str, Any]] = None,
|
42
42
|
**kwargs,
|
43
43
|
):
|
44
44
|
if inspect.isclass(model_base) and issubclass(model_base, AbstractTimeSeriesModel):
|
@@ -2,7 +2,7 @@ import copy
|
|
2
2
|
import logging
|
3
3
|
import re
|
4
4
|
from collections import defaultdict
|
5
|
-
from typing import Any,
|
5
|
+
from typing import Any, Optional, Type, Union
|
6
6
|
|
7
7
|
from autogluon.common import space
|
8
8
|
from autogluon.core import constants
|
@@ -15,7 +15,7 @@ from .registry import ModelRegistry
|
|
15
15
|
|
16
16
|
logger = logging.getLogger(__name__)
|
17
17
|
|
18
|
-
ModelHyperparameters =
|
18
|
+
ModelHyperparameters = dict[str, Any]
|
19
19
|
|
20
20
|
|
21
21
|
VALID_AG_ARGS_KEYS = {
|
@@ -92,11 +92,11 @@ def get_preset_models(
|
|
92
92
|
prediction_length: int,
|
93
93
|
path: str,
|
94
94
|
eval_metric: Union[str, TimeSeriesScorer],
|
95
|
-
hyperparameters: Union[str,
|
95
|
+
hyperparameters: Union[str, dict, None],
|
96
96
|
hyperparameter_tune: bool,
|
97
97
|
covariate_metadata: CovariateMetadata,
|
98
|
-
all_assigned_names:
|
99
|
-
excluded_model_types: Optional[
|
98
|
+
all_assigned_names: list[str],
|
99
|
+
excluded_model_types: Optional[list[str]],
|
100
100
|
multi_window: bool = False,
|
101
101
|
**kwargs,
|
102
102
|
):
|
@@ -140,7 +140,7 @@ def get_preset_models(
|
|
140
140
|
)
|
141
141
|
model_name_base = get_model_name(ag_args, model_type)
|
142
142
|
|
143
|
-
model_type_kwargs:
|
143
|
+
model_type_kwargs: dict[str, Any] = dict(
|
144
144
|
name=model_name_base,
|
145
145
|
path=path,
|
146
146
|
freq=freq,
|
@@ -169,7 +169,7 @@ def get_preset_models(
|
|
169
169
|
return models
|
170
170
|
|
171
171
|
|
172
|
-
def get_excluded_models(excluded_model_types: Optional[
|
172
|
+
def get_excluded_models(excluded_model_types: Optional[list[str]]) -> set[str]:
|
173
173
|
excluded_models = set()
|
174
174
|
if excluded_model_types is not None and len(excluded_model_types) > 0:
|
175
175
|
if not isinstance(excluded_model_types, list):
|
@@ -183,9 +183,9 @@ def get_excluded_models(excluded_model_types: Optional[List[str]]) -> Set[str]:
|
|
183
183
|
|
184
184
|
|
185
185
|
def get_hyperparameter_dict(
|
186
|
-
hyperparameters: Union[str,
|
186
|
+
hyperparameters: Union[str, dict[str, Union[ModelHyperparameters, list[ModelHyperparameters]]], None],
|
187
187
|
hyperparameter_tune: bool,
|
188
|
-
) ->
|
188
|
+
) -> dict[str, list[ModelHyperparameters]]:
|
189
189
|
hyperparameter_dict = {}
|
190
190
|
|
191
191
|
if hyperparameters is None:
|
@@ -215,9 +215,9 @@ def normalize_model_type_name(model_name: str) -> str:
|
|
215
215
|
|
216
216
|
|
217
217
|
def check_and_clean_hyperparameters(
|
218
|
-
hyperparameters:
|
218
|
+
hyperparameters: dict[str, Union[ModelHyperparameters, list[ModelHyperparameters]]],
|
219
219
|
must_contain_searchspace: bool,
|
220
|
-
) ->
|
220
|
+
) -> dict[str, list[ModelHyperparameters]]:
|
221
221
|
"""Convert the hyperparameters dictionary to a unified format:
|
222
222
|
- Remove 'Model' suffix from model names, if present
|
223
223
|
- Make sure that each value in the hyperparameters dict is a list with model configurations
|
@@ -240,7 +240,7 @@ def check_and_clean_hyperparameters(
|
|
240
240
|
return dict(hyperparameters_clean)
|
241
241
|
|
242
242
|
|
243
|
-
def get_model_name(ag_args:
|
243
|
+
def get_model_name(ag_args: dict[str, Any], model_type: Type[AbstractTimeSeriesModel]) -> str:
|
244
244
|
name = ag_args.get("name")
|
245
245
|
if name is None:
|
246
246
|
name_stem = re.sub(r"Model$", "", model_type.__name__)
|
@@ -257,7 +257,7 @@ def contains_searchspace(model_hyperparameters: ModelHyperparameters) -> bool:
|
|
257
257
|
return False
|
258
258
|
|
259
259
|
|
260
|
-
def verify_contains_at_least_one_searchspace(hyperparameters:
|
260
|
+
def verify_contains_at_least_one_searchspace(hyperparameters: dict[str, list[ModelHyperparameters]]):
|
261
261
|
for model, model_hps_list in hyperparameters.items():
|
262
262
|
for model_hps in model_hps_list:
|
263
263
|
if contains_searchspace(model_hps):
|
@@ -270,7 +270,7 @@ def verify_contains_at_least_one_searchspace(hyperparameters: Dict[str, List[Mod
|
|
270
270
|
)
|
271
271
|
|
272
272
|
|
273
|
-
def verify_contains_no_searchspaces(hyperparameters:
|
273
|
+
def verify_contains_no_searchspaces(hyperparameters: dict[str, list[ModelHyperparameters]]):
|
274
274
|
for model, model_hps_list in hyperparameters.items():
|
275
275
|
for model_hps in model_hps_list:
|
276
276
|
if contains_searchspace(model_hps):
|
@@ -1,7 +1,7 @@
|
|
1
1
|
from abc import ABCMeta
|
2
2
|
from dataclasses import dataclass
|
3
3
|
from inspect import isabstract
|
4
|
-
from typing import
|
4
|
+
from typing import Union
|
5
5
|
|
6
6
|
|
7
7
|
@dataclass
|
@@ -18,7 +18,7 @@ class ModelRegistry(ABCMeta):
|
|
18
18
|
See, https://github.com/faif/python-patterns.
|
19
19
|
"""
|
20
20
|
|
21
|
-
REGISTRY:
|
21
|
+
REGISTRY: dict[str, ModelRecord] = {}
|
22
22
|
|
23
23
|
def __new__(cls, name, bases, attrs):
|
24
24
|
new_cls = super().__new__(cls, name, bases, attrs)
|
@@ -61,5 +61,5 @@ class ModelRegistry(ABCMeta):
|
|
61
61
|
return cls._get_model_record(alias).ag_priority
|
62
62
|
|
63
63
|
@classmethod
|
64
|
-
def available_aliases(cls) ->
|
64
|
+
def available_aliases(cls) -> list[str]:
|
65
65
|
return sorted(cls.REGISTRY.keys())
|
@@ -5,7 +5,7 @@ import os
|
|
5
5
|
import pprint
|
6
6
|
import time
|
7
7
|
from pathlib import Path
|
8
|
-
from typing import Any,
|
8
|
+
from typing import Any, Literal, Optional, Type, Union, cast
|
9
9
|
|
10
10
|
import numpy as np
|
11
11
|
import pandas as pd
|
@@ -93,7 +93,7 @@ class TimeSeriesPredictor:
|
|
93
93
|
eval_metric_seasonal_period : int, optional
|
94
94
|
Seasonal period used to compute some evaluation metrics such as mean absolute scaled error (MASE). Defaults to
|
95
95
|
``None``, in which case the seasonal period is computed based on the data frequency.
|
96
|
-
horizon_weight :
|
96
|
+
horizon_weight : list[float], optional
|
97
97
|
Weight assigned to each time step in the forecast horizon when computing the ``eval_metric``. If provided, this
|
98
98
|
must be a list with ``prediction_length`` non-negative values, where at least some values are greater than zero.
|
99
99
|
AutoGluon will automatically normalize the weights so that they sum up to ``prediction_length``. By default, all
|
@@ -101,7 +101,7 @@ class TimeSeriesPredictor:
|
|
101
101
|
|
102
102
|
This parameter only affects model selection and ensemble construction; it has no effect on the loss function of
|
103
103
|
the individual forecasting models.
|
104
|
-
known_covariates_names:
|
104
|
+
known_covariates_names: list[str], optional
|
105
105
|
Names of the covariates that are known in advance for all time steps in the forecast horizon. These are also
|
106
106
|
known as dynamic features, exogenous variables, additional regressors or related time series. Examples of such
|
107
107
|
covariates include holidays, promotions or weather forecasts.
|
@@ -111,7 +111,7 @@ class TimeSeriesPredictor:
|
|
111
111
|
- :meth:`~autogluon.timeseries.TimeSeriesPredictor.fit`, :meth:`~autogluon.timeseries.TimeSeriesPredictor.evaluate`, and :meth:`~autogluon.timeseries.TimeSeriesPredictor.leaderboard` will expect a dataframe with columns listed in ``known_covariates_names`` (in addition to the ``target`` column).
|
112
112
|
- :meth:`~autogluon.timeseries.TimeSeriesPredictor.predict` will expect an additional keyword argument ``known_covariates`` containing the future values of the known covariates in ``TimeSeriesDataFrame`` format.
|
113
113
|
|
114
|
-
quantile_levels :
|
114
|
+
quantile_levels : list[float], optional
|
115
115
|
List of increasing decimals that specifies which quantiles should be estimated when making distributional
|
116
116
|
forecasts. Defaults to ``[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]``.
|
117
117
|
path : str or pathlib.Path, optional
|
@@ -147,17 +147,17 @@ class TimeSeriesPredictor:
|
|
147
147
|
def __init__(
|
148
148
|
self,
|
149
149
|
target: Optional[str] = None,
|
150
|
-
known_covariates_names: Optional[
|
150
|
+
known_covariates_names: Optional[list[str]] = None,
|
151
151
|
prediction_length: int = 1,
|
152
152
|
freq: Optional[str] = None,
|
153
153
|
eval_metric: Union[str, TimeSeriesScorer, None] = None,
|
154
154
|
eval_metric_seasonal_period: Optional[int] = None,
|
155
|
-
horizon_weight: Optional[
|
155
|
+
horizon_weight: Optional[list[float]] = None,
|
156
156
|
path: Optional[Union[str, Path]] = None,
|
157
157
|
verbosity: int = 2,
|
158
158
|
log_to_file: bool = True,
|
159
159
|
log_file_path: Union[str, Path] = "auto",
|
160
|
-
quantile_levels: Optional[
|
160
|
+
quantile_levels: Optional[list[float]] = None,
|
161
161
|
cache_predictions: bool = True,
|
162
162
|
label: Optional[str] = None,
|
163
163
|
**kwargs,
|
@@ -439,9 +439,9 @@ class TimeSeriesPredictor:
|
|
439
439
|
tuning_data: Optional[Union[TimeSeriesDataFrame, pd.DataFrame, Path, str]] = None,
|
440
440
|
time_limit: Optional[int] = None,
|
441
441
|
presets: Optional[str] = None,
|
442
|
-
hyperparameters: Optional[Union[str,
|
443
|
-
hyperparameter_tune_kwargs: Optional[Union[str,
|
444
|
-
excluded_model_types: Optional[
|
442
|
+
hyperparameters: Optional[Union[str, dict[Union[str, Type], Any]]] = None,
|
443
|
+
hyperparameter_tune_kwargs: Optional[Union[str, dict]] = None,
|
444
|
+
excluded_model_types: Optional[list[str]] = None,
|
445
445
|
num_val_windows: int = 1,
|
446
446
|
val_step_size: Optional[int] = None,
|
447
447
|
refit_every_n_windows: Optional[int] = 1,
|
@@ -614,7 +614,7 @@ class TimeSeriesPredictor:
|
|
614
614
|
"scheduler": "local",
|
615
615
|
},
|
616
616
|
)
|
617
|
-
excluded_model_types:
|
617
|
+
excluded_model_types: list[str], optional
|
618
618
|
Banned subset of model types to avoid training during ``fit()``, even if present in ``hyperparameters``.
|
619
619
|
For example, the following code will train all models included in the ``high_quality`` presets except ``DeepAR``::
|
620
620
|
|
@@ -779,7 +779,7 @@ class TimeSeriesPredictor:
|
|
779
779
|
self.save()
|
780
780
|
return self
|
781
781
|
|
782
|
-
def model_names(self) ->
|
782
|
+
def model_names(self) -> list[str]:
|
783
783
|
"""Returns the list of model names trained by this predictor object."""
|
784
784
|
return self._trainer.get_model_names()
|
785
785
|
|
@@ -872,11 +872,11 @@ class TimeSeriesPredictor:
|
|
872
872
|
self,
|
873
873
|
data: Union[TimeSeriesDataFrame, pd.DataFrame, Path, str],
|
874
874
|
model: Optional[str] = None,
|
875
|
-
metrics: Optional[Union[str, TimeSeriesScorer,
|
875
|
+
metrics: Optional[Union[str, TimeSeriesScorer, list[Union[str, TimeSeriesScorer]]]] = None,
|
876
876
|
cutoff: Optional[int] = None,
|
877
877
|
display: bool = False,
|
878
878
|
use_cache: bool = True,
|
879
|
-
) ->
|
879
|
+
) -> dict[str, float]:
|
880
880
|
"""Evaluate the forecast accuracy for given dataset.
|
881
881
|
|
882
882
|
This method measures the forecast accuracy using the last ``self.prediction_length`` time steps of each time
|
@@ -907,7 +907,7 @@ class TimeSeriesPredictor:
|
|
907
907
|
model : str, optional
|
908
908
|
Name of the model that you would like to evaluate. By default, the best model during training
|
909
909
|
(with highest validation score) will be used.
|
910
|
-
metrics : str, TimeSeriesScorer or
|
910
|
+
metrics : str, TimeSeriesScorer or list[Union[str, TimeSeriesScorer]], optional
|
911
911
|
Metric or a list of metrics to compute scores with. Defaults to ``self.eval_metric``. Supports both
|
912
912
|
metric names as strings and custom metrics based on TimeSeriesScorer.
|
913
913
|
cutoff : int, optional
|
@@ -923,7 +923,7 @@ class TimeSeriesPredictor:
|
|
923
923
|
|
924
924
|
Returns
|
925
925
|
-------
|
926
|
-
scores_dict :
|
926
|
+
scores_dict : dict[str, float]
|
927
927
|
Dictionary where keys = metrics, values = performance along each metric. For consistency, error metrics
|
928
928
|
will have their signs flipped to obey this convention. For example, negative MAPE values will be reported.
|
929
929
|
To get the ``eval_metric`` score, do ``output[predictor.eval_metric.name]``.
|
@@ -943,7 +943,7 @@ class TimeSeriesPredictor:
|
|
943
943
|
data: Optional[Union[TimeSeriesDataFrame, pd.DataFrame, Path, str]] = None,
|
944
944
|
model: Optional[str] = None,
|
945
945
|
metric: Optional[Union[str, TimeSeriesScorer]] = None,
|
946
|
-
features: Optional[
|
946
|
+
features: Optional[list[str]] = None,
|
947
947
|
time_limit: Optional[float] = None,
|
948
948
|
method: Literal["naive", "permutation"] = "permutation",
|
949
949
|
subsample_size: int = 50,
|
@@ -990,7 +990,7 @@ class TimeSeriesPredictor:
|
|
990
990
|
metric : str or TimeSeriesScorer, optional
|
991
991
|
Metric to be used for computing feature importance. If None, the ``eval_metric`` specified during initialization of
|
992
992
|
the ``TimeSeriesPredictor`` will be used.
|
993
|
-
features :
|
993
|
+
features : list[str], optional
|
994
994
|
List of feature names that feature importances are calculated for and returned. By default, all feature importances
|
995
995
|
will be returned.
|
996
996
|
method : {"permutation", "naive"}, default = "permutation"
|
@@ -1168,7 +1168,7 @@ class TimeSeriesPredictor:
|
|
1168
1168
|
self._learner = tmp_learner
|
1169
1169
|
self._save_version_file()
|
1170
1170
|
|
1171
|
-
def info(self) ->
|
1171
|
+
def info(self) -> dict[str, Any]:
|
1172
1172
|
"""Returns a dictionary of objects each describing an attribute of the training process and trained models."""
|
1173
1173
|
return self._learner.get_info(include_model_info=True)
|
1174
1174
|
|
@@ -1182,8 +1182,8 @@ class TimeSeriesPredictor:
|
|
1182
1182
|
return self._trainer.get_model_best()
|
1183
1183
|
|
1184
1184
|
def persist(
|
1185
|
-
self, models: Union[Literal["all", "best"],
|
1186
|
-
) ->
|
1185
|
+
self, models: Union[Literal["all", "best"], list[str]] = "best", with_ancestors: bool = True
|
1186
|
+
) -> list[str]:
|
1187
1187
|
"""Persist models in memory for reduced inference latency. This is particularly important if the models are being used for online
|
1188
1188
|
inference where low latency is critical. If models are not persisted in memory, they are loaded from disk every time they are
|
1189
1189
|
asked to make predictions. This is especially cumbersome for large deep learning based models which have to be loaded into
|
@@ -1203,12 +1203,12 @@ class TimeSeriesPredictor:
|
|
1203
1203
|
|
1204
1204
|
Returns
|
1205
1205
|
-------
|
1206
|
-
list_of_models :
|
1206
|
+
list_of_models : list[str]
|
1207
1207
|
List of persisted model names.
|
1208
1208
|
"""
|
1209
1209
|
return self._learner.persist_trainer(models=models, with_ancestors=with_ancestors)
|
1210
1210
|
|
1211
|
-
def unpersist(self) ->
|
1211
|
+
def unpersist(self) -> list[str]:
|
1212
1212
|
"""Unpersist models in memory for reduced memory usage. If models are not persisted in memory, they are loaded from
|
1213
1213
|
disk every time they are asked to make predictions.
|
1214
1214
|
|
@@ -1217,7 +1217,7 @@ class TimeSeriesPredictor:
|
|
1217
1217
|
|
1218
1218
|
Returns
|
1219
1219
|
-------
|
1220
|
-
list_of_models :
|
1220
|
+
list_of_models : list[str]
|
1221
1221
|
List of unpersisted model names.
|
1222
1222
|
"""
|
1223
1223
|
return self._learner.unpersist_trainer()
|
@@ -1227,7 +1227,7 @@ class TimeSeriesPredictor:
|
|
1227
1227
|
data: Optional[Union[TimeSeriesDataFrame, pd.DataFrame, Path, str]] = None,
|
1228
1228
|
cutoff: Optional[int] = None,
|
1229
1229
|
extra_info: bool = False,
|
1230
|
-
extra_metrics: Optional[
|
1230
|
+
extra_metrics: Optional[list[Union[str, TimeSeriesScorer]]] = None,
|
1231
1231
|
display: bool = False,
|
1232
1232
|
use_cache: bool = True,
|
1233
1233
|
**kwargs,
|
@@ -1271,7 +1271,7 @@ class TimeSeriesPredictor:
|
|
1271
1271
|
If True, the leaderboard will contain an additional column ``hyperparameters`` with the hyperparameters used
|
1272
1272
|
by each model during training. An empty dictionary ``{}`` means that the model was trained with default
|
1273
1273
|
hyperparameters.
|
1274
|
-
extra_metrics :
|
1274
|
+
extra_metrics : list[Union[str, TimeSeriesScorer]], optional
|
1275
1275
|
A list of metrics to calculate scores for and include in the output DataFrame.
|
1276
1276
|
|
1277
1277
|
Only valid when ``data`` is specified. The scores refer to the scores on ``data`` (same data as used to
|
@@ -1355,7 +1355,7 @@ class TimeSeriesPredictor:
|
|
1355
1355
|
data = self._check_and_prepare_data_frame(data)
|
1356
1356
|
return make_future_data_frame(data, prediction_length=self.prediction_length, freq=self.freq)
|
1357
1357
|
|
1358
|
-
def fit_summary(self, verbosity: int = 1) ->
|
1358
|
+
def fit_summary(self, verbosity: int = 1) -> dict[str, Any]:
|
1359
1359
|
"""Output summary of information about models produced during
|
1360
1360
|
:meth:`~autogluon.timeseries.TimeSeriesPredictor.fit`.
|
1361
1361
|
|
@@ -1366,7 +1366,7 @@ class TimeSeriesPredictor:
|
|
1366
1366
|
|
1367
1367
|
Returns
|
1368
1368
|
-------
|
1369
|
-
summary_dict :
|
1369
|
+
summary_dict : dict[str, Any]
|
1370
1370
|
Dict containing various detailed information. We do not recommend directly printing this dict as it may
|
1371
1371
|
be very large.
|
1372
1372
|
"""
|
@@ -1405,7 +1405,7 @@ class TimeSeriesPredictor:
|
|
1405
1405
|
print("****************** End of fit() summary ******************")
|
1406
1406
|
return results
|
1407
1407
|
|
1408
|
-
def refit_full(self, model: str = "all", set_best_to_refit_full: bool = True) ->
|
1408
|
+
def refit_full(self, model: str = "all", set_best_to_refit_full: bool = True) -> dict[str, str]:
|
1409
1409
|
"""Retrain model on all of the data (training + validation).
|
1410
1410
|
|
1411
1411
|
This method can only be used if no ``tuning_data`` was passed to :meth:`~autogluon.timeseries.TimeSeriesPredictor.fit`.
|
@@ -1483,7 +1483,7 @@ class TimeSeriesPredictor:
|
|
1483
1483
|
train_data = trainer.load_train_data()
|
1484
1484
|
val_data = trainer.load_val_data()
|
1485
1485
|
base_model_names = trainer.get_model_names(level=0)
|
1486
|
-
pred_proba_dict_val:
|
1486
|
+
pred_proba_dict_val: dict[str, list[TimeSeriesDataFrame]] = {
|
1487
1487
|
model_name: trainer._get_model_oof_predictions(model_name)
|
1488
1488
|
for model_name in base_model_names
|
1489
1489
|
if "_FULL" not in model_name
|
@@ -1497,7 +1497,7 @@ class TimeSeriesPredictor:
|
|
1497
1497
|
base_model_names, data=past_data, known_covariates=known_covariates
|
1498
1498
|
)
|
1499
1499
|
|
1500
|
-
y_val:
|
1500
|
+
y_val: list[TimeSeriesDataFrame] = [
|
1501
1501
|
select_target(df) for df in trainer._get_ensemble_oof_data(train_data=train_data, val_data=val_data)
|
1502
1502
|
]
|
1503
1503
|
y_test: TimeSeriesDataFrame = select_target(test_data)
|
@@ -1520,8 +1520,8 @@ class TimeSeriesPredictor:
|
|
1520
1520
|
self,
|
1521
1521
|
data: Union[TimeSeriesDataFrame, pd.DataFrame, Path, str],
|
1522
1522
|
predictions: Optional[TimeSeriesDataFrame] = None,
|
1523
|
-
quantile_levels: Optional[
|
1524
|
-
item_ids: Optional[
|
1523
|
+
quantile_levels: Optional[list[float]] = None,
|
1524
|
+
item_ids: Optional[list[Union[str, int]]] = None,
|
1525
1525
|
max_num_item_ids: int = 8,
|
1526
1526
|
max_history_length: Optional[int] = None,
|
1527
1527
|
point_forecast_column: Optional[str] = None,
|
@@ -1535,10 +1535,10 @@ class TimeSeriesPredictor:
|
|
1535
1535
|
Observed time series data.
|
1536
1536
|
predictions : TimeSeriesDataFrame, optional
|
1537
1537
|
Predictions generated by calling :meth:`~autogluon.timeseries.TimeSeriesPredictor.predict`.
|
1538
|
-
quantile_levels :
|
1538
|
+
quantile_levels : list[float], optional
|
1539
1539
|
Quantile levels for which to plot the prediction intervals. Defaults to lowest & highest quantile levels
|
1540
1540
|
available in ``predictions``.
|
1541
|
-
item_ids :
|
1541
|
+
item_ids : list[Union[str, int]], optional
|
1542
1542
|
If provided, plots will only be generated for time series with these item IDs. By default (if set to
|
1543
1543
|
``None``), item IDs are selected randomly. In either case, plots are generated for at most
|
1544
1544
|
``max_num_item_ids`` time series.
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import logging
|
2
2
|
import time
|
3
|
-
from typing import Any,
|
3
|
+
from typing import Any, Optional, Protocol, Union, overload, runtime_checkable
|
4
4
|
|
5
5
|
import numpy as np
|
6
6
|
import pandas as pd
|
@@ -40,42 +40,42 @@ class GlobalCovariateRegressor(CovariateRegressor):
|
|
40
40
|
|
41
41
|
Parameters
|
42
42
|
----------
|
43
|
-
model_name
|
43
|
+
model_name
|
44
44
|
Name of the tabular regression model. See ``autogluon.tabular.registry.ag_model_registry`` or
|
45
45
|
`the documentation <https://auto.gluon.ai/stable/api/autogluon.tabular.models.html>`_ for the list of available
|
46
46
|
tabular models.
|
47
|
-
model_hyperparameters
|
47
|
+
model_hyperparameters
|
48
48
|
Hyperparameters passed to the tabular regression model.
|
49
|
-
eval_metric
|
49
|
+
eval_metric
|
50
50
|
Metric provided as ``eval_metric`` to the tabular regression model. Must be compatible with `problem_type="regression"`.
|
51
|
-
refit_during_predict
|
51
|
+
refit_during_predict
|
52
52
|
If True, the model will be re-trained every time ``fit_transform`` is called. If False, the model will only be
|
53
53
|
trained the first time that ``fit_transform`` is called, and future calls to ``fit_transform`` will only perform a
|
54
54
|
``transform``.
|
55
|
-
max_num_samples
|
55
|
+
max_num_samples
|
56
56
|
If not None, training dataset passed to regression model will contain at most this many rows.
|
57
|
-
covariate_metadata
|
57
|
+
covariate_metadata
|
58
58
|
Metadata object describing the covariates available in the dataset.
|
59
|
-
target
|
59
|
+
target
|
60
60
|
Name of the target column.
|
61
|
-
validation_fraction
|
61
|
+
validation_fraction
|
62
62
|
Fraction of observations that are reserved as the validation set during training (starting from the end of each
|
63
63
|
time series).
|
64
|
-
fit_time_fraction
|
64
|
+
fit_time_fraction
|
65
65
|
The fraction of the time_limit that will be reserved for model training. The remainder (1 - fit_time_fraction)
|
66
66
|
will be reserved for prediction.
|
67
67
|
|
68
68
|
If the estimated prediction time exceeds ``(1 - fit_time_fraction) * time_limit``, the regressor will be disabled.
|
69
|
-
include_static_features
|
69
|
+
include_static_features
|
70
70
|
If True, static features will be included as features for the regressor.
|
71
|
-
include_item_id
|
71
|
+
include_item_id
|
72
72
|
If True, item_id will be included as a categorical feature for the regressor.
|
73
73
|
"""
|
74
74
|
|
75
75
|
def __init__(
|
76
76
|
self,
|
77
77
|
model_name: str = "CAT",
|
78
|
-
model_hyperparameters: Optional[
|
78
|
+
model_hyperparameters: Optional[dict[str, Any]] = None,
|
79
79
|
eval_metric: str = "mean_absolute_error",
|
80
80
|
refit_during_predict: bool = False,
|
81
81
|
max_num_samples: Optional[int] = 500_000,
|
autogluon/timeseries/splitter.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import Iterator, Optional
|
1
|
+
from typing import Iterator, Optional
|
2
2
|
|
3
3
|
from .dataset.ts_dataframe import TimeSeriesDataFrame
|
4
4
|
|
@@ -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,11 +33,11 @@ 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
|
|
@@ -47,7 +47,7 @@ class ExpandingWindowSplitter(AbstractWindowSplitter):
|
|
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
|