Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove freq argument in SeasonalNaivePredictor #2932

Merged
merged 6 commits into from
Jun 27, 2023

Conversation

lostella
Copy link
Contributor

@lostella lostella commented Jun 26, 2023

Description of changes: So far, freq was a mandatory argument in constructing SeasonalNaivePredictor. However, its role is not really clear this way: what is it used for? Can the predictor only treat data sampled at frequency freq? No, the frequency information is only used to infer the seasonality in case not directly provided.

This PR fixes this by removing freq altogether: now season_length is required.

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

Please tag this pr with at least one of these labels to make our release process faster: BREAKING, new feature, bug fix, other change, dev setup

@lostella lostella added the BREAKING This is a breaking change (one of pr required labels) label Jun 26, 2023
melopeo
melopeo previously approved these changes Jun 26, 2023
season_length: Optional[int] = None,
imputation_method: Optional[
MissingValueImputation
] = LastValueImputation(),
) -> None:
super().__init__(prediction_length=prediction_length)

assert (freq is not None) or (
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure this would be nicer.

maybe.or_(season_length, freq).expect("You must provide one of `freq` or `season_length`")

Copy link
Contributor

Choose a reason for hiding this comment

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

What is the use of freq, if season_length is passed?

Copy link
Contributor Author

@lostella lostella Jun 26, 2023

Choose a reason for hiding this comment

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

it's ignored (season_length takes precendence); another option is that not both can be specified

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure this would be nicer.

not sure, I find the explicit assertion clearer

Copy link
Contributor

Choose a reason for hiding this comment

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

I would keep the option of both parameters to be given, with season_length taking precedence.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I actually like removing freq as a parameter and require setting season_length (why is it not called seasonality?).

That way things become much more explicit.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I am wrong, but with this modification this model would be the only one that explicitly requires the parameter season_length, and I am not sure this is something we want. I agree that giving priority to season_length is something nice, but in many cases one computes seasonal_naive just as a reference without giving so much thought about the seasonality. For instance, in our metrics we use calculate_seasonal_error and I am not sure to what degree this would then also require an explicit value for season_length.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but with this modification this model would be the only one that explicitly requires the parameter season_length

I think that’s fine. The only thing common to all models really is that they have a fixed prediction length; in general, I think it’s fine that models each have their own set of options, related to how they work internally.

This model has a very simple logic, entirely determined by season_length: specifying this directly has no ambiguity. Adding indirection to translate freq only hides a little bit what the model will end up doing, with no added flexibility.

Then there are the choices for the default seasonality for hourly and daily data, which are completely arbitrary and end up tying together the behavior of different models or components for no reason.

In summary, I tend to agree that if you want to use the naive seasonal method, you should bring your own seasonality parameter. We do provide some heuristics to get that from frequency, and one is free to use them, but should do that explicitly.

@lostella
Copy link
Contributor Author

Removed freq altogether, making season_length mandatory.

@lostella lostella changed the title Make freq argument optional in SeasonalNaivePredictor Remove freq argument in SeasonalNaivePredictor Jun 26, 2023
@lostella
Copy link
Contributor Author

I think naive2 could be simplified in a similar way, see

freq: Optional[str] = None,
season_length: Optional[int] = None,
) -> np.ndarray:
"""
Make seasonality adjusted time series prediction.
If specified, `season_length` takes precedence.
As described here:
https://www.m4.unic.ac.cy/wp-content/uploads/2018/03/M4-Competitors-Guide.pdf
Code based on:
https://github.com/Mcompetitions/M4-methods/blob/master/Benchmarks%20and%20Evaluation.R
"""
assert freq is not None or season_length is not None, (
"Either the frequency or season length of the time series "
"has to be specified. "
)
season_length = (
season_length if season_length is not None else get_seasonality(freq)
)

@jaheba
Copy link
Contributor

jaheba commented Jun 27, 2023

@lostella Do you want to adjust naive2 in a separate PR?

@lostella lostella merged commit f4af090 into awslabs:dev Jun 27, 2023
20 checks passed
@lostella lostella deleted the naive-optional-freq branch June 27, 2023 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BREAKING This is a breaking change (one of pr required labels)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants