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

[ENH] Expose seasonality parameters of ProphetPiecewiseLinearTrendForecaster #5834

Merged
merged 11 commits into from
Feb 18, 2024
49 changes: 46 additions & 3 deletions sktime/forecasting/trend/_pwl_trend_forecaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from sktime.forecasting.base._base import DEFAULT_ALPHA
from sktime.forecasting.base.adapters import _ProphetAdapter
from sktime.utils.warnings import warn


class ProphetPiecewiseLinearTrendForecaster(_ProphetAdapter):
Expand Down Expand Up @@ -51,6 +52,18 @@ class ProphetPiecewiseLinearTrendForecaster(_ProphetAdapter):
automatic changepoint selection. Large values will allow many
changepoints, small values will allow few changepoints.
Recommended to take values within [0.001,0.5].
yearly_seasonality: str or bool or int, default="auto"
Include yearly seasonality in the model. "auto" for automatic determination,
True to enable, False to disable, or an integer specifying the number of terms
to include in the Fourier series.
weekly_seasonality: str or bool or int, default="auto"
Include weekly seasonality in the model. "auto" for automatic determination,
True to enable, False to disable, or an integer specifying the number of terms
to include in the Fourier series.
daily_seasonality: str or bool or int, default="auto"
Include weekly seasonality in the model. "auto" for automatic determination,
True to enable, False to disable, or an integer specifying the number of terms
to include in the Fourier series.

References
----------
Expand Down Expand Up @@ -89,6 +102,9 @@ def __init__(
changepoint_range=0.8,
changepoint_prior_scale=0.05,
verbose=0,
yearly_seasonality="changing_value",
weekly_seasonality="changing_value",
daily_seasonality="changing_value",
):
self.freq = None
self.add_seasonality = None
Expand All @@ -99,9 +115,9 @@ def __init__(
self.changepoints = changepoints
self.n_changepoints = n_changepoints
self.changepoint_range = changepoint_range
self.yearly_seasonality = "auto"
self.weekly_seasonality = "auto"
self.daily_seasonality = "auto"
self.yearly_seasonality = yearly_seasonality
self.weekly_seasonality = weekly_seasonality
self.daily_seasonality = daily_seasonality
self.holidays = None
self.seasonality_mode = "additive"
self.seasonality_prior_scale = 10.0
Expand All @@ -114,6 +130,33 @@ def __init__(
self.verbose = verbose

super().__init__()
# TODO (release 0.28.0)
# set yearly_seasonality = False in __init__
# set weekly_seasonality = False in __init__
# set daily_seasonality = False in __init__
# remove the following 4 'if' checks
if any(
setting is not False
for setting in [
yearly_seasonality,
weekly_seasonality,
daily_seasonality,
]
):
warn(
"Warning: In sktime 0.28.0, the default value for all seasonality "
"parameters in ProphetPiecewiseLinearTrendForecaster will change from "
"'auto' to 'False'. To retain the prior behavior, set all seasonality "
"parameters to 'auto' explicitly.",
category=DeprecationWarning,
stacklevel=3,
)
if yearly_seasonality == "changing_value":
self.yearly_seasonality = "auto"
if weekly_seasonality == "changing_value":
self.weekly_seasonality = "auto"
if daily_seasonality == "changing_value":
self.daily_seasonality = "auto"

# import inside method to avoid hard dependency
from prophet.forecaster import Prophet as _Prophet
Expand Down
Loading