autogluon.timeseries 1.2.1b20250416__py3-none-any.whl → 1.2.1b20250418__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.
Files changed (28) hide show
  1. autogluon/timeseries/learner.py +8 -6
  2. autogluon/timeseries/metrics/abstract.py +1 -1
  3. autogluon/timeseries/metrics/point.py +4 -4
  4. autogluon/timeseries/metrics/quantile.py +2 -2
  5. autogluon/timeseries/models/abstract/abstract_timeseries_model.py +123 -204
  6. autogluon/timeseries/models/autogluon_tabular/mlforecast.py +9 -9
  7. autogluon/timeseries/models/chronos/model.py +37 -30
  8. autogluon/timeseries/models/gluonts/abstract_gluonts.py +34 -30
  9. autogluon/timeseries/models/gluonts/torch/models.py +8 -8
  10. autogluon/timeseries/models/local/abstract_local_model.py +1 -1
  11. autogluon/timeseries/models/local/naive.py +2 -2
  12. autogluon/timeseries/models/multi_window/multi_window_model.py +0 -3
  13. autogluon/timeseries/models/presets.py +2 -2
  14. autogluon/timeseries/predictor.py +76 -59
  15. autogluon/timeseries/regressor.py +5 -4
  16. autogluon/timeseries/trainer.py +14 -13
  17. autogluon/timeseries/utils/features.py +5 -2
  18. autogluon/timeseries/utils/forecast.py +13 -8
  19. autogluon/timeseries/version.py +1 -1
  20. {autogluon.timeseries-1.2.1b20250416.dist-info → autogluon.timeseries-1.2.1b20250418.dist-info}/METADATA +4 -4
  21. {autogluon.timeseries-1.2.1b20250416.dist-info → autogluon.timeseries-1.2.1b20250418.dist-info}/RECORD +28 -28
  22. /autogluon.timeseries-1.2.1b20250416-py3.9-nspkg.pth → /autogluon.timeseries-1.2.1b20250418-py3.9-nspkg.pth +0 -0
  23. {autogluon.timeseries-1.2.1b20250416.dist-info → autogluon.timeseries-1.2.1b20250418.dist-info}/LICENSE +0 -0
  24. {autogluon.timeseries-1.2.1b20250416.dist-info → autogluon.timeseries-1.2.1b20250418.dist-info}/NOTICE +0 -0
  25. {autogluon.timeseries-1.2.1b20250416.dist-info → autogluon.timeseries-1.2.1b20250418.dist-info}/WHEEL +0 -0
  26. {autogluon.timeseries-1.2.1b20250416.dist-info → autogluon.timeseries-1.2.1b20250418.dist-info}/namespace_packages.txt +0 -0
  27. {autogluon.timeseries-1.2.1b20250416.dist-info → autogluon.timeseries-1.2.1b20250418.dist-info}/top_level.txt +0 -0
  28. {autogluon.timeseries-1.2.1b20250416.dist-info → autogluon.timeseries-1.2.1b20250418.dist-info}/zip-safe +0 -0
@@ -228,7 +228,7 @@ class ChronosModel(AbstractTimeSeriesModel):
228
228
  fine_tune_ckpt_path = Path(model.path) / cls.fine_tuned_ckpt_name
229
229
  if fine_tune_ckpt_path.exists():
230
230
  logger.debug(f"\tFine-tuned checkpoint exists, setting model_path to {fine_tune_ckpt_path}")
231
- model.model_path = fine_tune_ckpt_path
231
+ model.model_path = str(fine_tune_ckpt_path)
232
232
 
233
233
  return model
234
234
 
@@ -249,8 +249,10 @@ class ChronosModel(AbstractTimeSeriesModel):
249
249
  """The default configuration of the model used by AutoGluon if the model is one of those
250
250
  defined in MODEL_CONFIGS. For now, these are ``autogluon/chronos-t5-*`` family of models.
251
251
  """
252
- model_name = str(self.model_path).split("/")[-1]
253
- return MODEL_CONFIGS.get(model_name, {})
252
+ for k in MODEL_CONFIGS:
253
+ if k in self.model_path:
254
+ return MODEL_CONFIGS[k]
255
+ return {}
254
256
 
255
257
  @property
256
258
  def min_num_gpus(self) -> int:
@@ -314,28 +316,38 @@ class ChronosModel(AbstractTimeSeriesModel):
314
316
 
315
317
  return torch.cuda.is_available() and torch.cuda.get_device_capability()[0] >= 8
316
318
 
317
- def _get_model_params(self) -> dict:
319
+ def get_hyperparameters(self) -> dict:
318
320
  """Gets params that are passed to the inner model."""
319
- init_args = super()._get_model_params().copy()
320
-
321
- init_args.setdefault("batch_size", self.default_batch_size)
322
- init_args.setdefault("num_samples", self.default_num_samples)
323
- init_args.setdefault("device", None)
324
- # if the model requires a GPU, set the torch dtype to bfloat16
325
- init_args.setdefault("torch_dtype", self.default_torch_dtype)
326
- init_args.setdefault("data_loader_num_workers", 0)
327
- init_args.setdefault("context_length", None)
328
- init_args.setdefault("optimization_strategy", None)
329
- init_args.setdefault("fine_tune", False)
330
- init_args.setdefault("keep_transformers_logs", False)
331
- init_args.setdefault("fine_tune_lr", 1e-5)
332
- init_args.setdefault("fine_tune_steps", 1000)
333
- init_args.setdefault("fine_tune_batch_size", 32)
334
- init_args.setdefault("eval_during_fine_tune", False)
335
- init_args.setdefault("fine_tune_eval_max_items", 256)
336
- init_args.setdefault("fine_tune_shuffle_buffer_size", 10_000)
321
+ init_args = super().get_hyperparameters()
337
322
 
338
323
  eval_during_fine_tune = init_args["eval_during_fine_tune"]
324
+ fine_tune_trainer_kwargs = self._get_fine_tune_trainer_kwargs(init_args, eval_during_fine_tune)
325
+ user_fine_tune_trainer_kwargs = init_args.get("fine_tune_trainer_kwargs", {})
326
+ fine_tune_trainer_kwargs.update(user_fine_tune_trainer_kwargs)
327
+ init_args["fine_tune_trainer_kwargs"] = fine_tune_trainer_kwargs
328
+
329
+ return init_args.copy()
330
+
331
+ def _get_default_hyperparameters(self) -> Dict:
332
+ return {
333
+ "batch_size": self.default_batch_size,
334
+ "num_samples": self.default_num_samples,
335
+ "device": None,
336
+ "torch_dtype": self.default_torch_dtype,
337
+ "data_loader_num_workers": 0,
338
+ "context_length": None,
339
+ "optimization_strategy": None,
340
+ "fine_tune": False,
341
+ "keep_transformers_logs": False,
342
+ "fine_tune_lr": 1e-5,
343
+ "fine_tune_steps": 1000,
344
+ "fine_tune_batch_size": 32,
345
+ "eval_during_fine_tune": False,
346
+ "fine_tune_eval_max_items": 256,
347
+ "fine_tune_shuffle_buffer_size": 10_000,
348
+ }
349
+
350
+ def _get_fine_tune_trainer_kwargs(self, init_args, eval_during_fine_tune: bool):
339
351
  output_dir = Path(self.path) / "transformers_logs"
340
352
  fine_tune_trainer_kwargs = dict(
341
353
  output_dir=str(output_dir),
@@ -364,12 +376,8 @@ class ChronosModel(AbstractTimeSeriesModel):
364
376
  load_best_model_at_end=True if eval_during_fine_tune else False,
365
377
  metric_for_best_model="eval_loss" if eval_during_fine_tune else None,
366
378
  )
367
- user_fine_tune_trainer_kwargs = init_args.get("fine_tune_trainer_kwargs", {})
368
- fine_tune_trainer_kwargs.update(user_fine_tune_trainer_kwargs)
369
379
 
370
- init_args["fine_tune_trainer_kwargs"] = fine_tune_trainer_kwargs
371
-
372
- return init_args
380
+ return fine_tune_trainer_kwargs
373
381
 
374
382
  def _validate_and_assign_attributes(self, model_params: dict):
375
383
  # we validate the params here because their values are concrete,
@@ -432,8 +440,7 @@ class ChronosModel(AbstractTimeSeriesModel):
432
440
  transformers_logger.setLevel(logging.ERROR if verbosity <= 3 else logging.INFO)
433
441
 
434
442
  self._check_fit_params()
435
-
436
- model_params = self._get_model_params()
443
+ model_params = self.get_hyperparameters()
437
444
  self._validate_and_assign_attributes(model_params)
438
445
  do_fine_tune = model_params["fine_tune"]
439
446
 
@@ -655,7 +662,7 @@ class ChronosModel(AbstractTimeSeriesModel):
655
662
  return TimeSeriesDataFrame(df)
656
663
 
657
664
  def _more_tags(self) -> Dict:
658
- do_fine_tune = self._get_model_params()["fine_tune"]
665
+ do_fine_tune = self.get_hyperparameters()["fine_tune"]
659
666
  return {
660
667
  "allow_nan": True,
661
668
  "can_use_train_data": do_fine_tune,
@@ -245,26 +245,26 @@ class AbstractGluonTSModel(AbstractTimeSeriesModel):
245
245
  def _get_hpo_backend(self):
246
246
  return RAY_BACKEND
247
247
 
248
- def _deferred_init_params_aux(self, dataset: TimeSeriesDataFrame) -> None:
249
- """Update GluonTS specific parameters with information available only at training time."""
250
- model_params = self._get_model_params()
248
+ def _deferred_init_hyperparameters(self, dataset: TimeSeriesDataFrame) -> None:
249
+ """Update GluonTS specific hyperparameters with information available only at training time."""
250
+ model_params = self.get_hyperparameters()
251
251
  disable_static_features = model_params.get("disable_static_features", False)
252
252
  if not disable_static_features:
253
- self.num_feat_static_cat = len(self.metadata.static_features_cat)
254
- self.num_feat_static_real = len(self.metadata.static_features_real)
253
+ self.num_feat_static_cat = len(self.covariate_metadata.static_features_cat)
254
+ self.num_feat_static_real = len(self.covariate_metadata.static_features_real)
255
255
  if self.num_feat_static_cat > 0:
256
256
  assert dataset.static_features is not None, (
257
257
  "Static features must be provided if num_feat_static_cat > 0"
258
258
  )
259
- feat_static_cat = dataset.static_features[self.metadata.static_features_cat]
259
+ feat_static_cat = dataset.static_features[self.covariate_metadata.static_features_cat]
260
260
  self.feat_static_cat_cardinality = feat_static_cat.nunique().tolist()
261
261
 
262
262
  disable_known_covariates = model_params.get("disable_known_covariates", False)
263
263
  if not disable_known_covariates and self.supports_known_covariates:
264
- self.num_feat_dynamic_cat = len(self.metadata.known_covariates_cat)
265
- self.num_feat_dynamic_real = len(self.metadata.known_covariates_real)
264
+ self.num_feat_dynamic_cat = len(self.covariate_metadata.known_covariates_cat)
265
+ self.num_feat_dynamic_real = len(self.covariate_metadata.known_covariates_real)
266
266
  if self.num_feat_dynamic_cat > 0:
267
- feat_dynamic_cat = dataset[self.metadata.known_covariates_cat]
267
+ feat_dynamic_cat = dataset[self.covariate_metadata.known_covariates_cat]
268
268
  if self.supports_cat_covariates:
269
269
  self.feat_dynamic_cat_cardinality = feat_dynamic_cat.nunique().tolist()
270
270
  else:
@@ -280,10 +280,10 @@ class AbstractGluonTSModel(AbstractTimeSeriesModel):
280
280
 
281
281
  disable_past_covariates = model_params.get("disable_past_covariates", False)
282
282
  if not disable_past_covariates and self.supports_past_covariates:
283
- self.num_past_feat_dynamic_cat = len(self.metadata.past_covariates_cat)
284
- self.num_past_feat_dynamic_real = len(self.metadata.past_covariates_real)
283
+ self.num_past_feat_dynamic_cat = len(self.covariate_metadata.past_covariates_cat)
284
+ self.num_past_feat_dynamic_real = len(self.covariate_metadata.past_covariates_real)
285
285
  if self.num_past_feat_dynamic_cat > 0:
286
- past_feat_dynamic_cat = dataset[self.metadata.past_covariates_cat]
286
+ past_feat_dynamic_cat = dataset[self.covariate_metadata.past_covariates_cat]
287
287
  if self.supports_cat_covariates:
288
288
  self.past_feat_dynamic_cat_cardinality = past_feat_dynamic_cat.nunique().tolist()
289
289
  else:
@@ -301,7 +301,7 @@ class AbstractGluonTSModel(AbstractTimeSeriesModel):
301
301
 
302
302
  self.negative_data = (dataset[self.target] < 0).any()
303
303
 
304
- def _get_default_params(self):
304
+ def _get_default_hyperparameters(self):
305
305
  """Gets default parameters for GluonTS estimator initialization that are available after
306
306
  AbstractTimeSeriesModel initialization (i.e., before deferred initialization). Models may
307
307
  override this method to update default parameters.
@@ -319,7 +319,7 @@ class AbstractGluonTSModel(AbstractTimeSeriesModel):
319
319
  "covariate_scaler": "global",
320
320
  }
321
321
 
322
- def _get_model_params(self) -> dict:
322
+ def get_hyperparameters(self) -> dict:
323
323
  """Gets params that are passed to the inner model."""
324
324
  # for backward compatibility with the old GluonTS MXNet API
325
325
  parameter_name_aliases = {
@@ -327,7 +327,7 @@ class AbstractGluonTSModel(AbstractTimeSeriesModel):
327
327
  "learning_rate": "lr",
328
328
  }
329
329
 
330
- init_args = super()._get_model_params()
330
+ init_args = super().get_hyperparameters()
331
331
  for alias, actual in parameter_name_aliases.items():
332
332
  if alias in init_args:
333
333
  if actual in init_args:
@@ -335,12 +335,12 @@ class AbstractGluonTSModel(AbstractTimeSeriesModel):
335
335
  else:
336
336
  init_args[actual] = init_args.pop(alias)
337
337
 
338
- return self._get_default_params() | init_args
338
+ return self._get_default_hyperparameters() | init_args
339
339
 
340
340
  def _get_estimator_init_args(self) -> Dict[str, Any]:
341
- """Get GluonTS specific constructor arguments for estimator objects, an alias to `self._get_model_params`
341
+ """Get GluonTS specific constructor arguments for estimator objects, an alias to `self.get_hyperparameters`
342
342
  for better readability."""
343
- return self._get_model_params()
343
+ return self.get_hyperparameters()
344
344
 
345
345
  def _get_estimator_class(self) -> Type[GluonTSEstimator]:
346
346
  raise NotImplementedError
@@ -400,7 +400,9 @@ class AbstractGluonTSModel(AbstractTimeSeriesModel):
400
400
  assert time_series_df.static_features is not None, (
401
401
  "Static features must be provided if num_feat_static_cat > 0"
402
402
  )
403
- feat_static_cat = time_series_df.static_features[self.metadata.static_features_cat].to_numpy()
403
+ feat_static_cat = time_series_df.static_features[
404
+ self.covariate_metadata.static_features_cat
405
+ ].to_numpy()
404
406
  else:
405
407
  feat_static_cat = None
406
408
 
@@ -408,7 +410,9 @@ class AbstractGluonTSModel(AbstractTimeSeriesModel):
408
410
  assert time_series_df.static_features is not None, (
409
411
  "Static features must be provided if num_feat_static_real > 0"
410
412
  )
411
- feat_static_real = time_series_df.static_features[self.metadata.static_features_real].to_numpy()
413
+ feat_static_real = time_series_df.static_features[
414
+ self.covariate_metadata.static_features_real
415
+ ].to_numpy()
412
416
  else:
413
417
  feat_static_real = None
414
418
 
@@ -418,31 +422,31 @@ class AbstractGluonTSModel(AbstractTimeSeriesModel):
418
422
  if known_covariates is not None:
419
423
  known_covariates = pd.DataFrame(known_covariates) # type: ignore
420
424
  if self.num_feat_dynamic_cat > 0:
421
- feat_dynamic_cat = df[self.metadata.known_covariates_cat].to_numpy()
425
+ feat_dynamic_cat = df[self.covariate_metadata.known_covariates_cat].to_numpy()
422
426
  if known_covariates is not None:
423
427
  feat_dynamic_cat = np.concatenate(
424
- [feat_dynamic_cat, known_covariates[self.metadata.known_covariates_cat].to_numpy()]
428
+ [feat_dynamic_cat, known_covariates[self.covariate_metadata.known_covariates_cat].to_numpy()]
425
429
  )
426
430
  assert len(feat_dynamic_cat) == expected_known_covariates_len
427
431
  else:
428
432
  feat_dynamic_cat = None
429
433
 
430
434
  if self.num_feat_dynamic_real > 0:
431
- feat_dynamic_real = df[self.metadata.known_covariates_real].to_numpy()
435
+ feat_dynamic_real = df[self.covariate_metadata.known_covariates_real].to_numpy()
432
436
  # Append future values of known covariates
433
437
  if known_covariates is not None:
434
438
  feat_dynamic_real = np.concatenate(
435
- [feat_dynamic_real, known_covariates[self.metadata.known_covariates_real].to_numpy()]
439
+ [feat_dynamic_real, known_covariates[self.covariate_metadata.known_covariates_real].to_numpy()]
436
440
  )
437
441
  assert len(feat_dynamic_real) == expected_known_covariates_len
438
442
  # Categorical covariates are one-hot-encoded as real
439
443
  if self._ohe_generator_known is not None:
440
444
  feat_dynamic_cat_ohe: np.ndarray = self._ohe_generator_known.transform(
441
- df[self.metadata.known_covariates_cat]
445
+ df[self.covariate_metadata.known_covariates_cat]
442
446
  ) # type: ignore
443
447
  if known_covariates is not None:
444
448
  future_dynamic_cat_ohe: np.ndarray = self._ohe_generator_known.transform( # type: ignore
445
- known_covariates[self.metadata.known_covariates_cat]
449
+ known_covariates[self.covariate_metadata.known_covariates_cat]
446
450
  )
447
451
  feat_dynamic_cat_ohe = np.concatenate([feat_dynamic_cat_ohe, future_dynamic_cat_ohe])
448
452
  assert len(feat_dynamic_cat_ohe) == expected_known_covariates_len
@@ -451,15 +455,15 @@ class AbstractGluonTSModel(AbstractTimeSeriesModel):
451
455
  feat_dynamic_real = None
452
456
 
453
457
  if self.num_past_feat_dynamic_cat > 0:
454
- past_feat_dynamic_cat = df[self.metadata.past_covariates_cat].to_numpy()
458
+ past_feat_dynamic_cat = df[self.covariate_metadata.past_covariates_cat].to_numpy()
455
459
  else:
456
460
  past_feat_dynamic_cat = None
457
461
 
458
462
  if self.num_past_feat_dynamic_real > 0:
459
- past_feat_dynamic_real = df[self.metadata.past_covariates_real].to_numpy()
463
+ past_feat_dynamic_real = df[self.covariate_metadata.past_covariates_real].to_numpy()
460
464
  if self._ohe_generator_past is not None:
461
465
  past_feat_dynamic_cat_ohe: np.ndarray = self._ohe_generator_past.transform( # type: ignore
462
- df[self.metadata.past_covariates_cat]
466
+ df[self.covariate_metadata.past_covariates_cat]
463
467
  )
464
468
  past_feat_dynamic_real = np.concatenate(
465
469
  [past_feat_dynamic_real, past_feat_dynamic_cat_ohe], axis=1
@@ -517,7 +521,7 @@ class AbstractGluonTSModel(AbstractTimeSeriesModel):
517
521
  time_limit=time_limit,
518
522
  early_stopping_patience=None if val_data is None else init_args["early_stopping_patience"],
519
523
  )
520
- self._deferred_init_params_aux(train_data)
524
+ self._deferred_init_hyperparameters(train_data)
521
525
 
522
526
  estimator = self._get_estimator()
523
527
  with warning_filter(), disable_root_logger(), gluonts.core.settings.let(gluonts_env, use_tqdm=False):
@@ -208,8 +208,8 @@ class TemporalFusionTransformerModel(AbstractGluonTSModel):
208
208
 
209
209
  return TemporalFusionTransformerEstimator
210
210
 
211
- def _get_default_params(self):
212
- return super()._get_default_params() | {
211
+ def _get_default_hyperparameters(self):
212
+ return super()._get_default_hyperparameters() | {
213
213
  "context_length": min(512, max(64, 2 * self.prediction_length)),
214
214
  }
215
215
 
@@ -281,8 +281,8 @@ class DLinearModel(AbstractGluonTSModel):
281
281
  If True, ``lightning_logs`` directory will NOT be removed after the model finished training.
282
282
  """
283
283
 
284
- def _get_default_params(self):
285
- return super()._get_default_params() | {
284
+ def _get_default_hyperparameters(self):
285
+ return super()._get_default_hyperparameters() | {
286
286
  "context_length": 96,
287
287
  }
288
288
 
@@ -346,8 +346,8 @@ class PatchTSTModel(AbstractGluonTSModel):
346
346
 
347
347
  return PatchTSTEstimator
348
348
 
349
- def _get_default_params(self):
350
- return super()._get_default_params() | {"context_length": 96, "patch_len": 16}
349
+ def _get_default_hyperparameters(self):
350
+ return super()._get_default_hyperparameters() | {"context_length": 96, "patch_len": 16}
351
351
 
352
352
  def _get_estimator_init_args(self) -> Dict[str, Any]:
353
353
  init_kwargs = super()._get_estimator_init_args()
@@ -515,8 +515,8 @@ class TiDEModel(AbstractGluonTSModel):
515
515
 
516
516
  return TiDEEstimator
517
517
 
518
- def _get_default_params(self):
519
- return super()._get_default_params() | {
518
+ def _get_default_hyperparameters(self):
519
+ return super()._get_default_hyperparameters() | {
520
520
  "context_length": min(512, max(64, 2 * self.prediction_length)),
521
521
  "encoder_hidden_dim": 64,
522
522
  "decoder_hidden_dim": 64,
@@ -112,7 +112,7 @@ class AbstractLocalModel(AbstractTimeSeriesModel):
112
112
  raise TimeLimitExceeded
113
113
 
114
114
  # Initialize parameters passed to each local model
115
- raw_local_model_args = self._get_model_params().copy()
115
+ raw_local_model_args = self.get_hyperparameters().copy()
116
116
 
117
117
  unused_local_model_args = []
118
118
  local_model_args = {}
@@ -85,7 +85,7 @@ class SeasonalNaiveModel(AbstractLocalModel):
85
85
 
86
86
 
87
87
  class AverageModel(AbstractLocalModel):
88
- """Baseline model that sets the forecast equal to the historic average or quantile.
88
+ """Baseline model that sets the forecast equal to the historical average or quantile.
89
89
 
90
90
  Other Parameters
91
91
  ----------------
@@ -117,7 +117,7 @@ class AverageModel(AbstractLocalModel):
117
117
 
118
118
 
119
119
  class SeasonalAverageModel(AbstractLocalModel):
120
- """Baseline model that sets the forecast equal to the historic average or quantile in the same season.
120
+ """Baseline model that sets the forecast equal to the historical average or quantile in the same season.
121
121
 
122
122
  Other Parameters
123
123
  ----------------
@@ -212,9 +212,6 @@ class MultiWindowBacktestingModel(AbstractTimeSeriesModel):
212
212
  if store_predict_time:
213
213
  assert self.predict_time is not None
214
214
 
215
- def get_user_params(self) -> dict:
216
- return self.model_base.get_user_params()
217
-
218
215
  def _get_search_space(self):
219
216
  return self.model_base._get_search_space()
220
217
 
@@ -186,7 +186,7 @@ def get_preset_models(
186
186
  eval_metric_seasonal_period: Optional[int],
187
187
  hyperparameters: Union[str, Dict, None],
188
188
  hyperparameter_tune: bool,
189
- metadata: CovariateMetadata,
189
+ covariate_metadata: CovariateMetadata,
190
190
  all_assigned_names: List[str],
191
191
  excluded_model_types: Optional[List[str]],
192
192
  multi_window: bool = False,
@@ -261,7 +261,7 @@ def get_preset_models(
261
261
  prediction_length=prediction_length,
262
262
  eval_metric=eval_metric,
263
263
  eval_metric_seasonal_period=eval_metric_seasonal_period,
264
- metadata=metadata,
264
+ covariate_metadata=covariate_metadata,
265
265
  hyperparameters=model_hps,
266
266
  **kwargs,
267
267
  )
@@ -27,6 +27,7 @@ from autogluon.timeseries.learner import TimeSeriesLearner
27
27
  from autogluon.timeseries.metrics import TimeSeriesScorer, check_get_evaluation_metric
28
28
  from autogluon.timeseries.splitter import ExpandingWindowSplitter
29
29
  from autogluon.timeseries.trainer import TimeSeriesTrainer
30
+ from autogluon.timeseries.utils.forecast import make_future_data_frame
30
31
 
31
32
  logger = logging.getLogger("autogluon.timeseries")
32
33
 
@@ -305,11 +306,11 @@ class TimeSeriesPredictor:
305
306
  return df
306
307
 
307
308
  def _check_data_for_evaluation(self, data: TimeSeriesDataFrame, name: str = "data") -> None:
308
- """Make sure that provided evaluation data includes both historic and future time series values."""
309
+ """Make sure that provided evaluation data includes both historical and future time series values."""
309
310
  if data.num_timesteps_per_item().min() <= self.prediction_length:
310
311
  raise ValueError(
311
312
  f"Cannot reserve last prediction_length={self.prediction_length} time steps for evaluation in some "
312
- f"time series in {name}. Please make sure that {name} includes both historic and future data, and that"
313
+ f"time series in {name}. Please make sure that {name} includes both historical and future data, and that"
313
314
  f"all time series have length > prediction_length (at least {self.prediction_length + 1})"
314
315
  )
315
316
 
@@ -441,9 +442,8 @@ class TimeSeriesPredictor:
441
442
 
442
443
  data.static_features["store_id"] = data.static_features["store_id"].astype("category")
443
444
 
444
- If provided data is a path or a pandas.DataFrame, AutoGluon will attempt to automatically convert it to a
445
- ``TimeSeriesDataFrame``.
446
-
445
+ If provided data is a `pandas.DataFrame`, AutoGluon will attempt to convert it to a `TimeSeriesDataFrame`.
446
+ If a `str` or a `Path` is provided, AutoGluon will attempt to load this file.
447
447
  tuning_data : Union[TimeSeriesDataFrame, pd.DataFrame, Path, str], optional
448
448
  Data reserved for model selection and hyperparameter tuning, rather than training individual models. Also
449
449
  used to compute the validation scores. Note that only the last ``prediction_length`` time steps of each
@@ -455,16 +455,10 @@ class TimeSeriesPredictor:
455
455
  Leaving this argument empty and letting AutoGluon automatically generate the validation set from
456
456
  ``train_data`` is a good default.
457
457
 
458
- If ``known_covariates_names`` were specified when creating the predictor, ``tuning_data`` must also include
459
- the columns listed in ``known_covariates_names`` with the covariates values aligned with the target time
460
- series.
461
-
462
- If ``train_data`` has past covariates or static features, ``tuning_data`` must have also include them (with
463
- same columns names and dtypes).
464
-
465
- If provided data is a path or a pandas.DataFrame, AutoGluon will attempt to automatically convert it to a
466
- ``TimeSeriesDataFrame``.
458
+ The names and dtypes of columns and static features in ``tuning_data`` must match the ``train_data``.
467
459
 
460
+ If provided data is a `pandas.DataFrame`, AutoGluon will attempt to convert it to a `TimeSeriesDataFrame`.
461
+ If a `str` or a `Path` is provided, AutoGluon will attempt to load this file.
468
462
  time_limit : int, optional
469
463
  Approximately how long :meth:`~autogluon.timeseries.TimeSeriesPredictor.fit` will run (wall-clock time in
470
464
  seconds). If not specified, :meth:`~autogluon.timeseries.TimeSeriesPredictor.fit` will run until all models
@@ -775,23 +769,23 @@ class TimeSeriesPredictor:
775
769
  Parameters
776
770
  ----------
777
771
  data : Union[TimeSeriesDataFrame, pd.DataFrame, Path, str]
778
- Time series data to forecast with.
779
-
780
- If ``known_covariates_names`` were specified when creating the predictor, ``data`` must include the columns
781
- listed in ``known_covariates_names`` with the covariates values aligned with the target time series.
772
+ Historical time series data for which the forecast needs to be made.
782
773
 
783
- If ``train_data`` used to train the predictor contained past covariates or static features, then ``data``
784
- must also include them (with same column names and dtypes).
774
+ The names and dtypes of columns and static features in ``data`` must match the ``train_data`` used to train
775
+ the predictor.
785
776
 
786
- If provided data is an instance of pandas DataFrame, AutoGluon will attempt to automatically convert it
787
- to a ``TimeSeriesDataFrame``.
777
+ If provided data is a `pandas.DataFrame`, AutoGluon will attempt to convert it to a `TimeSeriesDataFrame`.
778
+ If a `str` or a `Path` is provided, AutoGluon will attempt to load this file.
788
779
  known_covariates : Union[TimeSeriesDataFrame, pd.DataFrame, Path, str], optional
789
780
  If ``known_covariates_names`` were specified when creating the predictor, it is necessary to provide the
790
- values of the known covariates for each time series during the forecast horizon. That is:
781
+ values of the known covariates for each time series during the forecast horizon. Specifically:
791
782
 
792
- - The columns must include all columns listed in ``known_covariates_names``
793
- - The ``item_id`` index must include all item ids present in ``data``
794
- - The ``timestamp`` index must include the values for ``prediction_length`` many time steps into the future from the end of each time series in ``data``
783
+ - Must contain all columns listed in ``known_covariates_names``.
784
+ - Must include all ``item_id`` values present in the input ``data``.
785
+ - Must include ``timestamp`` values for the full forecast horizon (i.e., ``prediction_length`` time steps) following the end of each series in the input ``data``.
786
+
787
+ You can use :meth:`autogluon.timeseries.TimeSeriesPredictor.make_future_data_frame` to generate a template
788
+ containing the required ``item_id`` and ``timestamp`` combinations for the `known_covariates` data frame.
795
789
 
796
790
  See example below.
797
791
  model : str, optional
@@ -872,17 +866,14 @@ class TimeSeriesPredictor:
872
866
  The data to evaluate the best model on. The last ``prediction_length`` time steps of each time series in
873
867
  ``data`` will be held out for prediction and forecast accuracy will be calculated on these time steps.
874
868
 
875
- Must include both historic and future data (i.e., length of all time series in ``data`` must be at least
869
+ Must include both historical and future data (i.e., length of all time series in ``data`` must be at least
876
870
  ``prediction_length + 1``).
877
871
 
878
- If ``known_covariates_names`` were specified when creating the predictor, ``data`` must include the columns
879
- listed in ``known_covariates_names`` with the covariates values aligned with the target time series.
880
-
881
- If ``train_data`` used to train the predictor contained past covariates or static features, then ``data``
882
- must also include them (with same column names and dtypes).
872
+ The names and dtypes of columns and static features in ``data`` must match the ``train_data`` used to train
873
+ the predictor.
883
874
 
884
- If provided data is an instance of pandas DataFrame, AutoGluon will attempt to automatically convert it
885
- to a ``TimeSeriesDataFrame``.
875
+ If provided data is a `pandas.DataFrame`, AutoGluon will attempt to convert it to a `TimeSeriesDataFrame`.
876
+ If a `str` or a `Path` is provided, AutoGluon will attempt to load this file.
886
877
  model : str, optional
887
878
  Name of the model that you would like to evaluate. By default, the best model during training
888
879
  (with highest validation score) will be used.
@@ -948,15 +939,11 @@ class TimeSeriesPredictor:
948
939
  item, will be held out for prediction and forecast accuracy will be calculated on these time steps.
949
940
  More accurate feature importances will be obtained from new data that was held-out during ``fit()``.
950
941
 
951
- If ``known_covariates_names`` were specified when creating the predictor, ``data`` must include the columns
952
- listed in ``known_covariates_names`` with the covariates values aligned with the target time series.
953
- This data must contain the label column with the same column name as specified during ``fit()``.
954
-
955
- If ``train_data`` used to train the predictor contained past covariates or static features, then ``data``
956
- must also include them (with same column names and dtypes).
942
+ The names and dtypes of columns and static features in ``data`` must match the ``train_data`` used to train
943
+ the predictor.
957
944
 
958
- If provided data is an instance of pandas DataFrame, AutoGluon will attempt to automatically convert it
959
- to a ``TimeSeriesDataFrame``. If str or Path is passed, ``data`` will be loaded using the str value as the file path.
945
+ If provided data is a `pandas.DataFrame`, AutoGluon will attempt to convert it to a `TimeSeriesDataFrame`.
946
+ If a `str` or a `Path` is provided, AutoGluon will attempt to load this file.
960
947
 
961
948
  If ``data`` is not provided, then validation (tuning) data provided during training (or the held out data used for
962
949
  validation if ``tuning_data`` was not explicitly provided ``fit()``) will be used.
@@ -1228,18 +1215,14 @@ class TimeSeriesPredictor:
1228
1215
  Parameters
1229
1216
  ----------
1230
1217
  data : Union[TimeSeriesDataFrame, pd.DataFrame, Path, str], optional
1231
- dataset used for additional evaluation. Must include both historic and future data (i.e., length of all
1218
+ dataset used for additional evaluation. Must include both historical and future data (i.e., length of all
1232
1219
  time series in ``data`` must be at least ``prediction_length + 1``).
1233
1220
 
1234
- If ``known_covariates_names`` were specified when creating the predictor, ``data`` must include the columns
1235
- listed in ``known_covariates_names`` with the covariates values aligned with the target time series.
1236
-
1237
- If ``train_data`` used to train the predictor contained past covariates or static features, then ``data``
1238
- must also include them (with same column names and dtypes).
1239
-
1240
- If provided data is a path or a pandas.DataFrame, AutoGluon will attempt to automatically convert it to a
1241
- ``TimeSeriesDataFrame``.
1221
+ The names and dtypes of columns and static features in ``data`` must match the ``train_data`` used to train
1222
+ the predictor.
1242
1223
 
1224
+ If provided data is a `pandas.DataFrame`, AutoGluon will attempt to convert it to a `TimeSeriesDataFrame`.
1225
+ If a `str` or a `Path` is provided, AutoGluon will attempt to load this file.
1243
1226
  extra_info : bool, default = False
1244
1227
  If True, the leaderboard will contain an additional column `hyperparameters` with the hyperparameters used
1245
1228
  by each model during training. An empty dictionary `{}` means that the model was trained with default
@@ -1288,6 +1271,44 @@ class TimeSeriesPredictor:
1288
1271
  print(leaderboard)
1289
1272
  return leaderboard
1290
1273
 
1274
+ def make_future_data_frame(self, data: Union[TimeSeriesDataFrame, pd.DataFrame, Path, str]) -> pd.DataFrame:
1275
+ """Generate a data frame with the `item_id` and `timestamp` values corresponding to the forecast horizon.
1276
+
1277
+ Parameters
1278
+ ----------
1279
+ data : Union[TimeSeriesDataFrame, pd.DataFrame, Path, str]
1280
+ Historical time series data.
1281
+
1282
+ Returns
1283
+ -------
1284
+ forecast_horizon : pd.DataFrame
1285
+ Data frame with columns `item_id` and `timestamp` corresponding to the forecast horizon. For each item ID
1286
+ in `data`, `forecast_horizon` will contain the timestamps for the next `prediction_length` time steps,
1287
+ following the end of each series in the input data.
1288
+
1289
+ Examples
1290
+ --------
1291
+ >>> print(data)
1292
+ target
1293
+ item_id timestamp
1294
+ A 2024-01-01 0
1295
+ 2024-01-02 1
1296
+ 2024-01-03 2
1297
+ B 2024-04-07 3
1298
+ 2024-04-08 4
1299
+ >>> predictor = TimeSeriesPredictor(prediction_length=2, freq="D")
1300
+ >>> print(predictor.make_future_data_frame(data))
1301
+ item_id timestamp
1302
+ 0 A 2024-01-04
1303
+ 0 A 2024-01-05
1304
+ 1 B 2024-04-09
1305
+ 1 B 2024-04-10
1306
+ """
1307
+ if self.freq is None:
1308
+ raise ValueError("Please fit the predictor before calling `make_future_data_frame`")
1309
+ data = self._check_and_prepare_data_frame(data)
1310
+ return make_future_data_frame(data, prediction_length=self.prediction_length, freq=self.freq)
1311
+
1291
1312
  def fit_summary(self, verbosity: int = 1) -> Dict[str, Any]:
1292
1313
  """Output summary of information about models produced during
1293
1314
  :meth:`~autogluon.timeseries.TimeSeriesPredictor.fit`.
@@ -1323,7 +1344,7 @@ class TimeSeriesPredictor:
1323
1344
  model_hyperparams = {}
1324
1345
  for model_name in self.model_names():
1325
1346
  model_obj = self._trainer.load_model(model_name)
1326
- model_hyperparams[model_name] = model_obj.params
1347
+ model_hyperparams[model_name] = model_obj.get_hyperparameters()
1327
1348
 
1328
1349
  results["model_hyperparams"] = model_hyperparams
1329
1350
  results["leaderboard"] = self._learner.leaderboard()
@@ -1400,11 +1421,6 @@ class TimeSeriesPredictor:
1400
1421
  )
1401
1422
  return refit_full_dict
1402
1423
 
1403
- def __dir__(self) -> List[str]:
1404
- # This hides method from IPython autocomplete, but not VSCode autocomplete
1405
- deprecated = ["score", "get_model_best", "get_model_names"]
1406
- return [d for d in super().__dir__() if d not in deprecated]
1407
-
1408
1424
  def _simulation_artifact(self, test_data: TimeSeriesDataFrame) -> dict:
1409
1425
  """[Advanced] Computes and returns the necessary information to perform offline ensemble simulation."""
1410
1426
 
@@ -1428,7 +1444,8 @@ class TimeSeriesPredictor:
1428
1444
  }
1429
1445
 
1430
1446
  past_data, known_covariates = test_data.get_model_inputs_for_scoring(
1431
- prediction_length=self.prediction_length, known_covariates_names=trainer.metadata.known_covariates
1447
+ prediction_length=self.prediction_length,
1448
+ known_covariates_names=trainer.covariate_metadata.known_covariates,
1432
1449
  )
1433
1450
  pred_proba_dict_test, _ = trainer.get_model_pred_dict(
1434
1451
  base_model_names, data=past_data, known_covariates=known_covariates
@@ -1463,7 +1480,7 @@ class TimeSeriesPredictor:
1463
1480
  point_forecast_column: Optional[str] = None,
1464
1481
  matplotlib_rc_params: Optional[dict] = None,
1465
1482
  ):
1466
- """Plot historic time series values and the forecasts.
1483
+ """Plot historical time series values and the forecasts.
1467
1484
 
1468
1485
  Parameters
1469
1486
  ----------