autogluon.timeseries 1.4.1b20251201__tar.gz → 1.4.1b20251202__tar.gz
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-1.4.1b20251201/src/autogluon.timeseries.egg-info → autogluon_timeseries-1.4.1b20251202}/PKG-INFO +8 -8
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/learner.py +1 -1
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/predictor.py +1 -1
- autogluon_timeseries-1.4.1b20251202/src/autogluon/timeseries/trainer/ensemble_composer.py +429 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/trainer/trainer.py +82 -47
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/version.py +1 -1
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202/src/autogluon.timeseries.egg-info}/PKG-INFO +8 -8
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon.timeseries.egg-info/requires.txt +7 -7
- autogluon_timeseries-1.4.1b20251201/src/autogluon/timeseries/trainer/ensemble_composer.py +0 -221
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/LICENSE +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/NOTICE +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/README.md +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/setup.cfg +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/setup.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/__init__.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/configs/__init__.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/configs/hyperparameter_presets.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/configs/predictor_presets.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/dataset/__init__.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/dataset/ts_dataframe.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/metrics/__init__.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/metrics/abstract.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/metrics/point.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/metrics/quantile.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/metrics/utils.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/__init__.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/abstract/__init__.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/abstract/abstract_timeseries_model.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/abstract/model_trial.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/abstract/tunable.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/autogluon_tabular/__init__.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/autogluon_tabular/mlforecast.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/autogluon_tabular/per_step.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/autogluon_tabular/transforms.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/autogluon_tabular/utils.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/chronos/__init__.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/chronos/model.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/chronos/utils.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/ensemble/__init__.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/ensemble/abstract.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/ensemble/array_based/__init__.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/ensemble/array_based/abstract.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/ensemble/array_based/models.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/ensemble/array_based/regressor/__init__.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/ensemble/array_based/regressor/abstract.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/ensemble/array_based/regressor/linear_stacker.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/ensemble/array_based/regressor/per_quantile_tabular.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/ensemble/array_based/regressor/tabular.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/ensemble/ensemble_selection.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/ensemble/per_item_greedy.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/ensemble/weighted/__init__.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/ensemble/weighted/abstract.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/ensemble/weighted/basic.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/ensemble/weighted/greedy.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/gluonts/__init__.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/gluonts/abstract.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/gluonts/dataset.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/gluonts/models.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/local/__init__.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/local/abstract_local_model.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/local/naive.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/local/npts.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/local/statsforecast.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/multi_window/__init__.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/multi_window/multi_window_model.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/registry.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/toto/__init__.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/toto/_internal/__init__.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/toto/_internal/backbone/__init__.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/toto/_internal/backbone/attention.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/toto/_internal/backbone/backbone.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/toto/_internal/backbone/distribution.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/toto/_internal/backbone/kvcache.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/toto/_internal/backbone/rope.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/toto/_internal/backbone/rotary_embedding_torch.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/toto/_internal/backbone/scaler.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/toto/_internal/backbone/transformer.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/toto/_internal/dataset.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/toto/_internal/forecaster.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/toto/dataloader.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/toto/hf_pretrained_model.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/models/toto/model.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/regressor.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/splitter.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/trainer/__init__.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/trainer/model_set_builder.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/trainer/prediction_cache.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/trainer/utils.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/transforms/__init__.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/transforms/covariate_scaler.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/transforms/target_scaler.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/utils/__init__.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/utils/constants.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/utils/datetime/__init__.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/utils/datetime/base.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/utils/datetime/lags.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/utils/datetime/seasonality.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/utils/datetime/time_features.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/utils/features.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/utils/forecast.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/utils/timer.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon/timeseries/utils/warning_filters.py +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon.timeseries.egg-info/SOURCES.txt +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon.timeseries.egg-info/dependency_links.txt +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon.timeseries.egg-info/namespace_packages.txt +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon.timeseries.egg-info/top_level.txt +0 -0
- {autogluon_timeseries-1.4.1b20251201 → autogluon_timeseries-1.4.1b20251202}/src/autogluon.timeseries.egg-info/zip-safe +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: autogluon.timeseries
|
|
3
|
-
Version: 1.4.
|
|
3
|
+
Version: 1.4.1b20251202
|
|
4
4
|
Summary: Fast and Accurate ML in 3 Lines of Code
|
|
5
5
|
Home-page: https://github.com/autogluon/autogluon
|
|
6
6
|
Author: AutoGluon Community
|
|
@@ -39,7 +39,7 @@ Requires-Dist: joblib<1.7,>=1.2
|
|
|
39
39
|
Requires-Dist: numpy<2.4.0,>=1.25.0
|
|
40
40
|
Requires-Dist: scipy<1.17,>=1.5.4
|
|
41
41
|
Requires-Dist: pandas<2.4.0,>=2.0.0
|
|
42
|
-
Requires-Dist: torch<2.
|
|
42
|
+
Requires-Dist: torch<2.10,>=2.6
|
|
43
43
|
Requires-Dist: lightning<2.6,>=2.5.1
|
|
44
44
|
Requires-Dist: transformers[sentencepiece]<4.50,>=4.38.0
|
|
45
45
|
Requires-Dist: accelerate<2.0,>=0.34.0
|
|
@@ -55,19 +55,19 @@ Requires-Dist: orjson~=3.9
|
|
|
55
55
|
Requires-Dist: einops<1,>=0.7
|
|
56
56
|
Requires-Dist: chronos-forecasting<3,>=2.0.1
|
|
57
57
|
Requires-Dist: tensorboard<3,>=2.9
|
|
58
|
-
Requires-Dist: autogluon.core==1.4.
|
|
59
|
-
Requires-Dist: autogluon.common==1.4.
|
|
60
|
-
Requires-Dist: autogluon.features==1.4.
|
|
61
|
-
Requires-Dist: autogluon.tabular[catboost,lightgbm,xgboost]==1.4.
|
|
58
|
+
Requires-Dist: autogluon.core==1.4.1b20251202
|
|
59
|
+
Requires-Dist: autogluon.common==1.4.1b20251202
|
|
60
|
+
Requires-Dist: autogluon.features==1.4.1b20251202
|
|
61
|
+
Requires-Dist: autogluon.tabular[catboost,lightgbm,xgboost]==1.4.1b20251202
|
|
62
62
|
Provides-Extra: tests
|
|
63
63
|
Requires-Dist: pytest; extra == "tests"
|
|
64
64
|
Requires-Dist: ruff>=0.0.285; extra == "tests"
|
|
65
65
|
Requires-Dist: flaky<4,>=3.7; extra == "tests"
|
|
66
66
|
Requires-Dist: pytest-timeout<3,>=2.1; extra == "tests"
|
|
67
67
|
Provides-Extra: ray
|
|
68
|
-
Requires-Dist: autogluon.core[raytune]==1.4.
|
|
68
|
+
Requires-Dist: autogluon.core[raytune]==1.4.1b20251202; extra == "ray"
|
|
69
69
|
Provides-Extra: all
|
|
70
|
-
Requires-Dist: autogluon.core[raytune]==1.4.
|
|
70
|
+
Requires-Dist: autogluon.core[raytune]==1.4.1b20251202; extra == "all"
|
|
71
71
|
Dynamic: author
|
|
72
72
|
Dynamic: classifier
|
|
73
73
|
Dynamic: description
|
|
@@ -59,7 +59,7 @@ class TimeSeriesLearner(AbstractLearner):
|
|
|
59
59
|
val_data: TimeSeriesDataFrame | None = None,
|
|
60
60
|
hyperparameter_tune_kwargs: str | dict | None = None,
|
|
61
61
|
time_limit: float | None = None,
|
|
62
|
-
num_val_windows: int
|
|
62
|
+
num_val_windows: int = 1,
|
|
63
63
|
val_step_size: int | None = None,
|
|
64
64
|
refit_every_n_windows: int | None = 1,
|
|
65
65
|
random_seed: int | None = None,
|
|
@@ -1678,7 +1678,7 @@ class TimeSeriesPredictor:
|
|
|
1678
1678
|
trainer = self._trainer
|
|
1679
1679
|
train_data = trainer.load_train_data()
|
|
1680
1680
|
val_data = trainer.load_val_data()
|
|
1681
|
-
base_model_names = trainer.get_model_names(
|
|
1681
|
+
base_model_names = trainer.get_model_names(layer=0)
|
|
1682
1682
|
pred_proba_dict_val: dict[str, list[TimeSeriesDataFrame]] = {
|
|
1683
1683
|
model_name: trainer._get_model_oof_predictions(model_name)
|
|
1684
1684
|
for model_name in base_model_names
|
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import os
|
|
3
|
+
import time
|
|
4
|
+
import traceback
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Any, Iterator
|
|
7
|
+
|
|
8
|
+
import networkx as nx
|
|
9
|
+
import numpy as np
|
|
10
|
+
from typing_extensions import Self
|
|
11
|
+
|
|
12
|
+
from autogluon.timeseries import TimeSeriesDataFrame
|
|
13
|
+
from autogluon.timeseries.metrics import TimeSeriesScorer
|
|
14
|
+
from autogluon.timeseries.models.ensemble import (
|
|
15
|
+
AbstractTimeSeriesEnsembleModel,
|
|
16
|
+
PerformanceWeightedEnsemble,
|
|
17
|
+
get_ensemble_class,
|
|
18
|
+
)
|
|
19
|
+
from autogluon.timeseries.utils.timer import SplitTimer
|
|
20
|
+
from autogluon.timeseries.utils.warning_filters import warning_filter
|
|
21
|
+
|
|
22
|
+
from .utils import log_scores_and_times
|
|
23
|
+
|
|
24
|
+
logger = logging.getLogger("autogluon.timeseries.trainer")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class EnsembleComposer:
|
|
28
|
+
"""Helper class for TimeSeriesTrainer to build multi-layer stack ensembles.
|
|
29
|
+
|
|
30
|
+
This class depends on the trainer to provide the necessary initialization parameters, training
|
|
31
|
+
and validation data, as well as having fit the base (non-ensemble) models and persisted their
|
|
32
|
+
out-of-fold predictions which will be used for ensemble training.
|
|
33
|
+
|
|
34
|
+
Parameters
|
|
35
|
+
----------
|
|
36
|
+
path
|
|
37
|
+
Path of the calling TimeSeriesTrainer. EnsembleComposer finds the model objects and their
|
|
38
|
+
out-of-fold prediction artifacts with respect to this path. EnsembleComposer only saves
|
|
39
|
+
ensemble models and their out-of-fold predictions to this folder (i.e., does not pickle
|
|
40
|
+
itself).
|
|
41
|
+
prediction_length
|
|
42
|
+
Number of time steps to forecast.
|
|
43
|
+
eval_metric
|
|
44
|
+
Metric used to evaluate ensemble performance.
|
|
45
|
+
target
|
|
46
|
+
Name of the target column in the time series data.
|
|
47
|
+
num_windows_per_layer
|
|
48
|
+
Number of windows used for training each ensemble layer. Length must match the number of layers
|
|
49
|
+
in ensemble_hyperparameters. Example: (3, 2) means first layer uses 3 windows, second layer uses
|
|
50
|
+
2 windows.
|
|
51
|
+
|
|
52
|
+
Base models must have OOF predictions saved for all sum(num_windows_per_layer) windows, prior
|
|
53
|
+
to this class being called.
|
|
54
|
+
ensemble_hyperparameters
|
|
55
|
+
Ensemble configuration. A list of dicts, one per layer. If an ensemble model should be fitted
|
|
56
|
+
with multiple hyperparameter configurations, a list of dicts may be provided as the value.
|
|
57
|
+
Each layer's dict maps ensemble names to either a single hyperparameter dict or a list of
|
|
58
|
+
hyperparameter dicts.
|
|
59
|
+
|
|
60
|
+
Examples:
|
|
61
|
+
- ``[{"GreedyEnsemble": {}}, {"GreedyEnsemble": {}}]`` for 2 layers of greedy ensembles.
|
|
62
|
+
- ``[{"GreedyEnsemble": [{"ensemble_size": 10}, {"ensemble_size": 20}]}]`` for a single layer of
|
|
63
|
+
two greedy ensembles, with differing ensemble sizes.
|
|
64
|
+
quantile_levels
|
|
65
|
+
Quantile levels for probabilistic forecasting.
|
|
66
|
+
model_graph
|
|
67
|
+
Directed graph containing base models and their metadata (val_score, fit_time, etc.). Only
|
|
68
|
+
base models (nodes without predecessors) are used for ensemble training.
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
def __init__(
|
|
72
|
+
self,
|
|
73
|
+
path: str,
|
|
74
|
+
prediction_length: int,
|
|
75
|
+
eval_metric: TimeSeriesScorer,
|
|
76
|
+
target: str,
|
|
77
|
+
num_windows_per_layer: tuple[int, ...],
|
|
78
|
+
ensemble_hyperparameters: list[dict[str, dict | list[dict]]],
|
|
79
|
+
quantile_levels: list[float],
|
|
80
|
+
model_graph: nx.DiGraph,
|
|
81
|
+
):
|
|
82
|
+
self.eval_metric = eval_metric
|
|
83
|
+
self.path = path
|
|
84
|
+
self.prediction_length = prediction_length
|
|
85
|
+
self.target = target
|
|
86
|
+
self.quantile_levels = quantile_levels
|
|
87
|
+
|
|
88
|
+
self.num_windows_per_layer = num_windows_per_layer
|
|
89
|
+
self.num_layers = len(num_windows_per_layer)
|
|
90
|
+
|
|
91
|
+
if len(ensemble_hyperparameters) != self.num_layers:
|
|
92
|
+
raise ValueError(
|
|
93
|
+
"Number of ensemble_hyperparameters must match the number of layers. "
|
|
94
|
+
f"Received {len(ensemble_hyperparameters)} ensemble_hyperparameters, "
|
|
95
|
+
f"but {self.num_layers} layers."
|
|
96
|
+
)
|
|
97
|
+
self.ensemble_hyperparameters = ensemble_hyperparameters
|
|
98
|
+
|
|
99
|
+
self.banned_model_names = list(model_graph.nodes)
|
|
100
|
+
self.model_graph = self._get_base_model_graph(source_graph=model_graph)
|
|
101
|
+
|
|
102
|
+
@staticmethod
|
|
103
|
+
def _get_base_model_graph(source_graph: nx.DiGraph) -> nx.DiGraph:
|
|
104
|
+
"""Return a model graph by copying only base models (nodes without predecessors).
|
|
105
|
+
|
|
106
|
+
This ensures we start fresh for training ensembles.
|
|
107
|
+
"""
|
|
108
|
+
rootset = EnsembleComposer._get_rootset(source_graph)
|
|
109
|
+
|
|
110
|
+
dst_graph = nx.DiGraph()
|
|
111
|
+
for node in rootset:
|
|
112
|
+
dst_graph.add_node(node, **source_graph.nodes[node])
|
|
113
|
+
|
|
114
|
+
return dst_graph
|
|
115
|
+
|
|
116
|
+
@staticmethod
|
|
117
|
+
def _get_rootset(graph: nx.DiGraph) -> list[str]:
|
|
118
|
+
return [n for n in graph.nodes if not list(graph.predecessors(n))]
|
|
119
|
+
|
|
120
|
+
def _load_model(self, model_name: str) -> Any:
|
|
121
|
+
"""Load a model from the graph by name."""
|
|
122
|
+
attrs = self.model_graph.nodes[model_name]
|
|
123
|
+
model_path = os.path.join(self.path, *attrs["path"])
|
|
124
|
+
return attrs["type"].load(path=model_path)
|
|
125
|
+
|
|
126
|
+
def _iter_models(self, layer: int) -> Iterator[tuple[str, Any]]:
|
|
127
|
+
"""Iterate over models in a specific layer of the model graph.
|
|
128
|
+
|
|
129
|
+
Parameters
|
|
130
|
+
----------
|
|
131
|
+
layer
|
|
132
|
+
Layer index (0 for base models, 1+ for ensemble layers)
|
|
133
|
+
|
|
134
|
+
Yields
|
|
135
|
+
------
|
|
136
|
+
model_name
|
|
137
|
+
Name of the model
|
|
138
|
+
model
|
|
139
|
+
Loaded model instance
|
|
140
|
+
"""
|
|
141
|
+
rootset = self._get_rootset(self.model_graph)
|
|
142
|
+
layer_iter = nx.traversal.bfs_layers(self.model_graph, rootset)
|
|
143
|
+
for layer_idx, layer_keys in enumerate(layer_iter):
|
|
144
|
+
if layer_idx != layer:
|
|
145
|
+
continue
|
|
146
|
+
|
|
147
|
+
for model_name in layer_keys:
|
|
148
|
+
model = self._load_model(model_name)
|
|
149
|
+
yield model_name, model
|
|
150
|
+
|
|
151
|
+
def iter_ensembles(self) -> Iterator[tuple[int, AbstractTimeSeriesEnsembleModel, list[str]]]:
|
|
152
|
+
"""Iterate over trained ensemble models, layer by layer. Used by the Trainer to copy the
|
|
153
|
+
fitted models in EnsembleComposer's ``model_graph``.
|
|
154
|
+
|
|
155
|
+
Yields
|
|
156
|
+
------
|
|
157
|
+
layer_idx
|
|
158
|
+
The layer index of the ensemble.
|
|
159
|
+
model
|
|
160
|
+
The ensemble model object
|
|
161
|
+
base_model_names
|
|
162
|
+
The names of the base models that are part of the ensemble.
|
|
163
|
+
"""
|
|
164
|
+
for layer_idx in range(1, self.num_layers + 1):
|
|
165
|
+
for model_name, model in self._iter_models(layer=layer_idx):
|
|
166
|
+
yield (layer_idx, model, list(self.model_graph.predecessors(model_name)))
|
|
167
|
+
|
|
168
|
+
def fit(
|
|
169
|
+
self,
|
|
170
|
+
data_per_window: list[TimeSeriesDataFrame],
|
|
171
|
+
predictions_per_window: dict[str, list[TimeSeriesDataFrame]],
|
|
172
|
+
time_limit: float | None = None,
|
|
173
|
+
) -> Self:
|
|
174
|
+
base_model_names = [name for name, _ in self._iter_models(layer=0)]
|
|
175
|
+
if not self._can_fit_ensemble(time_limit, len(base_model_names)):
|
|
176
|
+
return self
|
|
177
|
+
|
|
178
|
+
num_ensembles = sum(
|
|
179
|
+
len(list(self.iter_layer_models_and_hps(layer))) for layer in range(1, self.num_layers + 1)
|
|
180
|
+
)
|
|
181
|
+
logger.info(f"Fitting {num_ensembles} ensemble(s), in {self.num_layers} layers.")
|
|
182
|
+
|
|
183
|
+
assert len(data_per_window) == sum(self.num_windows_per_layer)
|
|
184
|
+
|
|
185
|
+
def get_inputs_for_layer(layer_idx, model_names):
|
|
186
|
+
"""Retrieve predictions from previous layer models for current layer training."""
|
|
187
|
+
if layer_idx == 1:
|
|
188
|
+
# we need base models, so we use predictions_per_window provided by the trainer,
|
|
189
|
+
# which contains base model predictions for all windows where ensembles will be
|
|
190
|
+
# trained.
|
|
191
|
+
num_windows = self.num_windows_per_layer[0]
|
|
192
|
+
inputs = {name: predictions_per_window[name][:num_windows] for name in model_names}
|
|
193
|
+
else:
|
|
194
|
+
# if layer_idx > 1, we will be relying on predictions of previously trained ensembles
|
|
195
|
+
window_start = -sum(self.num_windows_per_layer[layer_idx - 1 :])
|
|
196
|
+
window_slice = slice(
|
|
197
|
+
window_start,
|
|
198
|
+
window_start + self.num_windows_per_layer[layer_idx - 1] if layer_idx < self.num_layers else None,
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
inputs = {}
|
|
202
|
+
for model_name in model_names:
|
|
203
|
+
oof_predictions = self._get_model_oof_predictions(model_name)
|
|
204
|
+
inputs[model_name] = oof_predictions[window_slice]
|
|
205
|
+
|
|
206
|
+
return inputs
|
|
207
|
+
|
|
208
|
+
def get_ground_truth_for_layer(layer_idx):
|
|
209
|
+
window_start = sum(self.num_windows_per_layer[: layer_idx - 1])
|
|
210
|
+
window_end = window_start + self.num_windows_per_layer[layer_idx - 1]
|
|
211
|
+
return data_per_window[window_start:window_end]
|
|
212
|
+
|
|
213
|
+
main_loop_timer = SplitTimer(time_limit, rounds=num_ensembles).start()
|
|
214
|
+
|
|
215
|
+
# main loop over layers of ensembles
|
|
216
|
+
for layer_idx in range(1, self.num_layers + 1):
|
|
217
|
+
layer_input_model_names = [name for name, _ in self._iter_models(layer=layer_idx - 1)]
|
|
218
|
+
layer_input_model_scores = {
|
|
219
|
+
name: self.model_graph.nodes[name]["val_score"] for name in layer_input_model_names
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
layer_predictions_per_window = get_inputs_for_layer(layer_idx, model_names=layer_input_model_names)
|
|
223
|
+
layer_data_per_window = get_ground_truth_for_layer(layer_idx)
|
|
224
|
+
|
|
225
|
+
for ensemble_name, ensemble_hp_dict in self.iter_layer_models_and_hps(layer_idx):
|
|
226
|
+
try:
|
|
227
|
+
# train the ensemble model
|
|
228
|
+
time_start = time.monotonic()
|
|
229
|
+
|
|
230
|
+
ensemble = self._fit_single_ensemble(
|
|
231
|
+
model_name=ensemble_name,
|
|
232
|
+
hyperparameters=ensemble_hp_dict,
|
|
233
|
+
predictions_per_window=layer_predictions_per_window,
|
|
234
|
+
data_per_window=layer_data_per_window,
|
|
235
|
+
base_model_scores=layer_input_model_scores,
|
|
236
|
+
layer_idx=layer_idx,
|
|
237
|
+
time_limit=main_loop_timer.round_time_remaining(),
|
|
238
|
+
)
|
|
239
|
+
ensemble.fit_time = time.monotonic() - time_start
|
|
240
|
+
|
|
241
|
+
# for all windows of all layers starting from this layer, predict and save predictions
|
|
242
|
+
predictions = []
|
|
243
|
+
predict_time = 0
|
|
244
|
+
for pred_layer_idx in range(layer_idx, self.num_layers + 1):
|
|
245
|
+
predict_time_start = time.monotonic()
|
|
246
|
+
|
|
247
|
+
pred_base_predictions = get_inputs_for_layer(pred_layer_idx, ensemble.model_names)
|
|
248
|
+
for window_idx in range(self.num_windows_per_layer[pred_layer_idx - 1]):
|
|
249
|
+
prediction = ensemble.predict(
|
|
250
|
+
{n: pred_base_predictions[n][window_idx] for n in ensemble.model_names}
|
|
251
|
+
)
|
|
252
|
+
predictions.append(prediction)
|
|
253
|
+
|
|
254
|
+
predict_time = time.monotonic() - predict_time_start
|
|
255
|
+
|
|
256
|
+
# prediction time is last layer's time + base models
|
|
257
|
+
ensemble.predict_time = predict_time + self._calculate_base_models_predict_time(
|
|
258
|
+
ensemble.model_names
|
|
259
|
+
)
|
|
260
|
+
ensemble.cache_oof_predictions(predictions)
|
|
261
|
+
|
|
262
|
+
# compute validation score using the last layer's validation windows
|
|
263
|
+
last_layer_oof_predictions = ensemble.get_oof_predictions()[-self.num_windows_per_layer[-1] :]
|
|
264
|
+
last_layer_ground_truth = get_ground_truth_for_layer(self.num_layers)
|
|
265
|
+
score_per_fold = [
|
|
266
|
+
self.eval_metric(data, prediction, target=self.target)
|
|
267
|
+
for prediction, data in zip(last_layer_oof_predictions, last_layer_ground_truth)
|
|
268
|
+
]
|
|
269
|
+
ensemble.val_score = float(np.mean(score_per_fold, dtype=np.float64))
|
|
270
|
+
|
|
271
|
+
# log performance and save
|
|
272
|
+
log_scores_and_times(
|
|
273
|
+
ensemble.val_score,
|
|
274
|
+
ensemble.fit_time,
|
|
275
|
+
ensemble.predict_time,
|
|
276
|
+
eval_metric_name=self.eval_metric.name_with_sign,
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
# save ensemble
|
|
280
|
+
self._add_model(ensemble, base_models=ensemble.model_names)
|
|
281
|
+
ensemble.save()
|
|
282
|
+
|
|
283
|
+
# check time and advance round
|
|
284
|
+
if main_loop_timer.timed_out():
|
|
285
|
+
logger.warning(
|
|
286
|
+
"Time limit exceeded during ensemble training, will stop training new ensembles."
|
|
287
|
+
)
|
|
288
|
+
return self
|
|
289
|
+
|
|
290
|
+
except Exception as err: # noqa
|
|
291
|
+
logger.error(
|
|
292
|
+
f"\tWarning: Exception caused {ensemble_name} to fail during training... Skipping this model."
|
|
293
|
+
)
|
|
294
|
+
logger.error(f"\t{err}")
|
|
295
|
+
logger.debug(traceback.format_exc())
|
|
296
|
+
|
|
297
|
+
finally:
|
|
298
|
+
main_loop_timer.next_round()
|
|
299
|
+
|
|
300
|
+
return self
|
|
301
|
+
|
|
302
|
+
def iter_layer_models_and_hps(self, layer_idx: int):
|
|
303
|
+
layer_hps = self.ensemble_hyperparameters[layer_idx - 1]
|
|
304
|
+
|
|
305
|
+
for model_name, hps in layer_hps.items():
|
|
306
|
+
if isinstance(hps, list):
|
|
307
|
+
# If a list is provided, create one ensemble per hyperparameter dict
|
|
308
|
+
for hp in hps:
|
|
309
|
+
yield model_name, hp
|
|
310
|
+
else:
|
|
311
|
+
yield model_name, hps
|
|
312
|
+
|
|
313
|
+
def _fit_single_ensemble(
|
|
314
|
+
self,
|
|
315
|
+
model_name: str,
|
|
316
|
+
hyperparameters: dict,
|
|
317
|
+
predictions_per_window: dict[str, list[TimeSeriesDataFrame]],
|
|
318
|
+
data_per_window: list[TimeSeriesDataFrame],
|
|
319
|
+
base_model_scores: dict[str, float],
|
|
320
|
+
layer_idx: int,
|
|
321
|
+
time_limit: float | None = None,
|
|
322
|
+
) -> AbstractTimeSeriesEnsembleModel:
|
|
323
|
+
ensemble_class = get_ensemble_class(model_name)
|
|
324
|
+
|
|
325
|
+
# TODO: remove this after PerformanceWeightedEnsemble is removed. This is a temporary fix
|
|
326
|
+
# to make sure PerformanceWeightedEnsemble is not fit on the validation scores of future
|
|
327
|
+
# out-of-fold splits.
|
|
328
|
+
if layer_idx < self.num_layers and ensemble_class is PerformanceWeightedEnsemble:
|
|
329
|
+
raise RuntimeError(
|
|
330
|
+
"PerformanceWeightedEnsemble is not supported for multilayer stack ensembles, except "
|
|
331
|
+
"when it's used in the last layer of the ensemble."
|
|
332
|
+
)
|
|
333
|
+
|
|
334
|
+
ensemble: AbstractTimeSeriesEnsembleModel = ensemble_class(
|
|
335
|
+
eval_metric=self.eval_metric,
|
|
336
|
+
target=self.target,
|
|
337
|
+
prediction_length=self.prediction_length,
|
|
338
|
+
path=self.path,
|
|
339
|
+
freq=data_per_window[0].freq,
|
|
340
|
+
quantile_levels=self.quantile_levels,
|
|
341
|
+
hyperparameters=hyperparameters,
|
|
342
|
+
)
|
|
343
|
+
|
|
344
|
+
# update name to prevent name collisions
|
|
345
|
+
old_name = ensemble.name
|
|
346
|
+
ensemble.name = self._get_ensemble_model_name(ensemble.name, layer_idx)
|
|
347
|
+
if ensemble.name != old_name:
|
|
348
|
+
path_obj = Path(ensemble.path)
|
|
349
|
+
ensemble.path = str(path_obj.parent / ensemble.name)
|
|
350
|
+
|
|
351
|
+
with warning_filter():
|
|
352
|
+
ensemble.fit(
|
|
353
|
+
predictions_per_window=predictions_per_window,
|
|
354
|
+
data_per_window=data_per_window,
|
|
355
|
+
model_scores=base_model_scores,
|
|
356
|
+
time_limit=time_limit,
|
|
357
|
+
)
|
|
358
|
+
|
|
359
|
+
return ensemble
|
|
360
|
+
|
|
361
|
+
def _get_model_oof_predictions(self, model_name: str) -> list[TimeSeriesDataFrame]:
|
|
362
|
+
model_attrs = self.model_graph.nodes[model_name]
|
|
363
|
+
model_path = os.path.join(self.path, *model_attrs["path"])
|
|
364
|
+
return model_attrs["type"].load_oof_predictions(path=model_path)
|
|
365
|
+
|
|
366
|
+
def _add_model(self, model, base_models: list[str]):
|
|
367
|
+
self.model_graph.add_node(
|
|
368
|
+
model.name,
|
|
369
|
+
path=os.path.relpath(model.path, self.path).split(os.sep),
|
|
370
|
+
type=type(model),
|
|
371
|
+
fit_time=model.fit_time,
|
|
372
|
+
predict_time=model.predict_time,
|
|
373
|
+
val_score=model.val_score,
|
|
374
|
+
)
|
|
375
|
+
for base_model in base_models:
|
|
376
|
+
self.model_graph.add_edge(base_model, model.name)
|
|
377
|
+
self.banned_model_names.append(model.name)
|
|
378
|
+
|
|
379
|
+
def _can_fit_ensemble(
|
|
380
|
+
self,
|
|
381
|
+
time_limit: float | None,
|
|
382
|
+
num_models_available_for_ensemble: int,
|
|
383
|
+
) -> bool:
|
|
384
|
+
if time_limit is not None and time_limit <= 0:
|
|
385
|
+
logger.info(f"Not fitting ensemble due to lack of time remaining. Time left: {time_limit:.1f} seconds")
|
|
386
|
+
return False
|
|
387
|
+
|
|
388
|
+
if num_models_available_for_ensemble <= 1:
|
|
389
|
+
logger.info(
|
|
390
|
+
"Not fitting ensemble as "
|
|
391
|
+
+ (
|
|
392
|
+
"no models were successfully trained."
|
|
393
|
+
if not num_models_available_for_ensemble
|
|
394
|
+
else "only 1 model was trained."
|
|
395
|
+
)
|
|
396
|
+
)
|
|
397
|
+
return False
|
|
398
|
+
|
|
399
|
+
return True
|
|
400
|
+
|
|
401
|
+
def _get_ensemble_model_name(self, name: str, layer_idx: int) -> str:
|
|
402
|
+
"""Revise name for an ensemble model, ensuring we don't have name collisions"""
|
|
403
|
+
base_name = name
|
|
404
|
+
layer_suffix = f"_L{layer_idx + 1}" if self.num_layers > 1 else ""
|
|
405
|
+
name = f"{base_name}" + layer_suffix
|
|
406
|
+
increment = 1
|
|
407
|
+
while name in self.banned_model_names:
|
|
408
|
+
increment += 1
|
|
409
|
+
name = f"{base_name}_{increment}" + layer_suffix
|
|
410
|
+
return name
|
|
411
|
+
|
|
412
|
+
def _calculate_base_models_predict_time(self, model_names: list[str]) -> float:
|
|
413
|
+
"""Calculate ensemble predict time as sum of base model predict times."""
|
|
414
|
+
return sum(self.model_graph.nodes[name]["predict_time"] for name in model_names)
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
def validate_ensemble_hyperparameters(hyperparameters: list[dict[str, dict | list[dict]]]) -> None:
|
|
418
|
+
if not isinstance(hyperparameters, list):
|
|
419
|
+
raise ValueError(f"ensemble_hyperparameters must be list, got {type(hyperparameters)}")
|
|
420
|
+
|
|
421
|
+
for layer_idx, layer_hp in enumerate(hyperparameters):
|
|
422
|
+
if not isinstance(layer_hp, dict):
|
|
423
|
+
raise ValueError(f"Layer {layer_idx} hyperparameters must be dict, got {type(layer_hp)}")
|
|
424
|
+
for ensemble_name, ensemble_hp in layer_hp.items():
|
|
425
|
+
get_ensemble_class(ensemble_name) # Will raise if unknown
|
|
426
|
+
hp_is_dict = isinstance(ensemble_hp, dict)
|
|
427
|
+
hp_is_valid_list = isinstance(ensemble_hp, list) and all(isinstance(d, dict) for d in ensemble_hp)
|
|
428
|
+
if not (hp_is_dict or hp_is_valid_list):
|
|
429
|
+
raise ValueError(f"Hyperparameters for {ensemble_name} must be dict or list, got {type(ensemble_hp)}")
|