ProphetModel¶
- class ProphetModel(growth: str = 'linear', changepoints: Optional[List[datetime.datetime]] = None, n_changepoints: int = 25, changepoint_range: float = 0.8, yearly_seasonality: Union[str, bool] = 'auto', weekly_seasonality: Union[str, bool] = 'auto', daily_seasonality: Union[str, bool] = 'auto', holidays: Optional[pandas.core.frame.DataFrame] = None, seasonality_mode: str = 'additive', seasonality_prior_scale: float = 10.0, holidays_prior_scale: float = 10.0, changepoint_prior_scale: float = 0.05, mcmc_samples: int = 0, interval_width: float = 0.8, uncertainty_samples: Union[int, bool] = 1000, stan_backend: Optional[str] = None, additional_seasonality_params: Iterable[Dict[str, Union[str, float, int]]] = ())[source]¶
Bases:
etna.models.mixins.PerSegmentModelMixin
,etna.models.mixins.PredictionIntervalContextIgnorantModelMixin
,etna.models.base.PredictionIntervalContextIgnorantAbstractModel
Class for holding Prophet model.
Notes
Original Prophet can use features ‘cap’ and ‘floor’, they should be added to the known_future list on dataset initialization.
This model supports in-sample and out-of-sample forecast decomposition. The number of components in the decomposition depends on model parameters. Main components are: trend, seasonality, holiday and exogenous effects. Seasonal components will be decomposed down to individual periods if fitted. Holiday and exogenous will be present in decomposition if fitted.Corresponding components are obtained directly from the model.
Examples
>>> from etna.datasets import generate_periodic_df >>> from etna.datasets import TSDataset >>> from etna.models import ProphetModel >>> classic_df = generate_periodic_df( ... periods=100, ... start_time="2020-01-01", ... n_segments=4, ... period=7, ... sigma=3 ... ) >>> df = TSDataset.to_dataset(df=classic_df) >>> ts = TSDataset(df, freq="D") >>> future = ts.make_future(7) >>> model = ProphetModel(growth="flat") >>> model.fit(ts=ts) ProphetModel(growth = 'flat', changepoints = None, n_changepoints = 25, changepoint_range = 0.8, yearly_seasonality = 'auto', weekly_seasonality = 'auto', daily_seasonality = 'auto', holidays = None, seasonality_mode = 'additive', seasonality_prior_scale = 10.0, holidays_prior_scale = 10.0, changepoint_prior_scale = 0.05, mcmc_samples = 0, interval_width = 0.8, uncertainty_samples = 1000, stan_backend = None, additional_seasonality_params = (), ) >>> forecast = model.forecast(future) >>> forecast segment segment_0 segment_1 segment_2 segment_3 feature target target target target timestamp 2020-04-10 9.00 9.00 4.00 6.00 2020-04-11 5.00 2.00 7.00 9.00 2020-04-12 0.00 4.00 7.00 9.00 2020-04-13 0.00 5.00 9.00 7.00 2020-04-14 1.00 2.00 1.00 6.00 2020-04-15 5.00 7.00 4.00 7.00 2020-04-16 8.00 6.00 2.00 0.00
Create instance of Prophet model.
- Parameters
growth (str) – Options are ‘linear’ and ‘logistic’. This likely will not be tuned; if there is a known saturating point and growth towards that point it will be included and the logistic trend will be used, otherwise it will be linear.
changepoints (Optional[List[datetime.datetime]]) – List of dates at which to include potential changepoints. If not specified, potential changepoints are selected automatically.
n_changepoints (int) – Number of potential changepoints to include. Not used if input
changepoints
is supplied. Ifchangepoints
is not supplied, thenn_changepoints
potential changepoints are selected uniformly from the firstchangepoint_range
proportion of the history.changepoint_range (float) – Proportion of history in which trend changepoints will be estimated. Defaults to 0.8 for the first 80%. Not used if
changepoints
is specified.yearly_seasonality (Union[str, bool]) – By default (‘auto’) this will turn yearly seasonality on if there is a year of data, and off otherwise. Options are [‘auto’, True, False]. If there is more than a year of data, rather than trying to turn this off during HPO, it will likely be more effective to leave it on and turn down seasonal effects by tuning
seasonality_prior_scale
.weekly_seasonality (Union[str, bool]) – Same as for
yearly_seasonality
.daily_seasonality (Union[str, bool]) – Same as for
yearly_seasonality
.holidays (Optional[pandas.core.frame.DataFrame]) –
pd.DataFrame
with columns holiday (string) and ds (date type) and optionally columns lower_window and upper_window which specify a range of days around the date to be included as holidays.lower_window=-2
will include 2 days prior to the date as holidays. Also optionally can have a columnprior_scale
specifying the prior scale for that holiday.seasonality_mode (str) – ‘additive’ (default) or ‘multiplicative’.
seasonality_prior_scale (float) – Parameter modulating the strength of the seasonality model. Larger values allow the model to fit larger seasonal fluctuations, smaller values dampen the seasonality. Can be specified for individual seasonalities using
add_seasonality
.holidays_prior_scale (float) – Parameter modulating the strength of the holiday components model, unless overridden in the holidays input.
changepoint_prior_scale (float) – Parameter modulating the flexibility of the automatic changepoint selection. Large values will allow many changepoints, small values will allow few changepoints.
mcmc_samples (int) – Integer, if greater than 0, will do full Bayesian inference with the specified number of MCMC samples. If 0, will do MAP estimation.
interval_width (float) – Float, width of the uncertainty intervals provided for the forecast. If
mcmc_samples=0
, this will be only the uncertainty in the trend using the MAP estimate of the extrapolated generative model. Ifmcmc.samples>0
, this will be integrated over all model parameters, which will include uncertainty in seasonality.uncertainty_samples (Union[int, bool]) – Number of simulated draws used to estimate uncertainty intervals. Settings this value to 0 or False will disable uncertainty estimation and speed up the calculation.
stan_backend (Optional[str]) – as defined in StanBackendEnum default: None - will try to iterate over all available backends and find the working one
additional_seasonality_params (Iterable[Dict[str, Union[int, float, str]]]) – parameters that describe additional (not ‘daily’, ‘weekly’, ‘yearly’) seasonality that should be added to model; dict with required keys ‘name’, ‘period’, ‘fourier_order’ and optional ones ‘prior_scale’, ‘mode’, ‘condition_name’ will be used for
prophet.Prophet.add_seasonality()
method call.
- Inherited-members
Methods
fit
(ts)Fit model.
forecast
(ts[, prediction_interval, ...])Make predictions.
get_model
()Get internal models that are used inside etna class.
load
(path)Load an object.
predict
(ts[, prediction_interval, ...])Make predictions with using true values as autoregression context if possible (teacher forcing).
save
(path)Save the object.
set_params
(**params)Return new object instance with modified parameters.
to_dict
()Collect all information about etna object in dict.
Attributes
context_size
Context size of the model.