Skip to content

Conversation

shchur
Copy link
Collaborator

@shchur shchur commented Apr 17, 2025

Issue #, if available: #4852

Description of changes:

  • Add an optional argument horizon_weight: list[float] | None to the TimeSeriesPredictor and all forecasting metrics that allows assigning custom weights to each time step in the forecast horizon when computing the metric.
  • When computing all metrics, we create an array of raw error values of shape [num_items, prediction_length]. We then multiply this array with horizon_weight.reshape[1, prediction_length], before applying the final aggregation step.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@shchur shchur requested a review from abdulfatir April 17, 2025 07:36
if quantile_levels is None:
quantile_levels = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
self.quantile_levels = sorted(quantile_levels)
self._learner: TimeSeriesLearner = self._learner_type(
path_context=self.path,
eval_metric=eval_metric,
eval_metric_seasonal_period=eval_metric_seasonal_period,
horizon_weight=self.horizon_weight,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One potential discussion point: Currently we inject the horizon_weight all the way through TimeSeriesPredictor -> TimeSeriesLearner -> TimeSeriesTrainer -> AbstractTimeSeriesModel (same logic as with eval_metric_seasonal_period).

Alternatively, we could "attach" the horizon_weight to the eval_metric object inside the predictor, and then only pass around the eval_metric object. On the one hand, this removed the need to use horizon_weight as a kwarg in all internal methods. On the other hand, we now need to be extra careful that we are actually passing the eval_metric object (a TimeSeriesScorer) and at no point accidentally serialize it as a str (e.g., "WQL") because that will remove the horizon_weight attribute.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abdulfatir does this make sense?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I missed your comment somehow. Both approaches make sense, although I agree that passing the horizon_weight so deep is a bit unappetizing.

On the other hand, we now need to be extra careful that we are actually passing the eval_metric object (a TimeSeriesScorer) and at no point accidentally serialize it as a str (e.g., "WQL") because that will remove the horizon_weight attribute.

I think as long as the external API allows user to pass the eval_metric as a string, it should be fine.

Overall, I think that the alternative that you suggested is cleaner in some sense. If you decide to do that instead, happy to review again.

Copy link

Job PR-5058-34a54ac is done.
Docs are uploaded to http://autogluon-staging.s3-website-us-west-2.amazonaws.com/PR-5058/34a54ac/index.html

Copy link
Collaborator

@abdulfatir abdulfatir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @shchur! Left some minor comments.

Copy link

Job PR-5058-23504a6 is done.
Docs are uploaded to http://autogluon-staging.s3-website-us-west-2.amazonaws.com/PR-5058/23504a6/index.html

@shchur shchur merged commit cc74302 into autogluon:master Apr 22, 2025
27 checks passed
@shchur shchur deleted the horizon-weight branch April 22, 2025 08:15
@shchur shchur restored the horizon-weight branch April 22, 2025 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants