etna.models.ProphetModel#

class ProphetModel(growth: str = 'linear', changepoints: List[datetime] | None = None, n_changepoints: int = 25, changepoint_range: float = 0.8, yearly_seasonality: str | bool = 'auto', weekly_seasonality: str | bool = 'auto', daily_seasonality: str | bool = 'auto', holidays: DataFrame | None = 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: int | bool = 1000, stan_backend: str | None = None, additional_seasonality_params: Iterable[Dict[str, str | float | int]] = (), timestamp_column: str | None = None)[source]#

Bases: PerSegmentModelMixin, PredictionIntervalContextIgnorantModelMixin, PredictionIntervalContextIgnorantAbstractModel

Class for holding Prophet model.

Note

This model requires prophet extension to be installed. Read more about this at installation page.

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
>>> df = generate_periodic_df(
...     periods=100,
...     start_time="2020-01-01",
...     n_segments=4,
...     period=7,
...     sigma=3
... )
>>> 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 = (), timestamp_column = None, )
>>> 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 (List[datetime] | None) – 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. If changepoints is not supplied, then n_changepoints potential changepoints are selected uniformly from the first changepoint_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 (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 (str | bool) – Same as for yearly_seasonality.

  • daily_seasonality (str | bool) – Same as for yearly_seasonality.

  • holidays (DataFrame | None) – 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 column prior_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. If mcmc.samples>0, this will be integrated over all model parameters, which will include uncertainty in seasonality.

  • uncertainty_samples (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 (str | None) – 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.

  • timestamp_column (str | None) – Name of a column to be used as timestamp. If not given, index is used. Column is expected to be regressor containing datetime values.

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.

params_to_tune()

Get default grid for tuning hyperparameters.

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

This class stores its __init__ parameters as attributes.

context_size

Context size of the model.

fit(ts: TSDataset) PerSegmentModelMixin[source]#

Fit model.

Parameters:

ts (TSDataset) – Dataset with features

Returns:

Model after fit

Return type:

PerSegmentModelMixin

forecast(ts: TSDataset, prediction_interval: bool = False, quantiles: Sequence[float] = (0.025, 0.975), return_components: bool = False) TSDataset[source]#

Make predictions.

Parameters:
  • ts (TSDataset) – Dataset with features

  • prediction_interval (bool) – If True returns prediction interval for forecast

  • quantiles (Sequence[float]) – Levels of prediction distribution. By default 2.5% and 97.5% are taken to form a 95% prediction interval

  • return_components (bool) – If True additionally returns forecast components

Returns:

Dataset with predictions

Return type:

TSDataset

get_model() Dict[str, Any][source]#

Get internal models that are used inside etna class.

Internal model is a model that is used inside etna to forecast segments, e.g. catboost.CatBoostRegressor or sklearn.linear_model.Ridge.

Returns:

dictionary where key is segment and value is internal model

Return type:

Dict[str, Any]

classmethod load(path: Path) Self[source]#

Load an object.

Warning

This method uses dill module which is not secure. It is possible to construct malicious data which will execute arbitrary code during loading. Never load data that could have come from an untrusted source, or that could have been tampered with.

Parameters:

path (Path) – Path to load object from.

Returns:

Loaded object.

Return type:

Self

params_to_tune() Dict[str, BaseDistribution][source]#

Get default grid for tuning hyperparameters.

This grid tunes parameters: seasonality_mode, seasonality_prior_scale, changepoint_prior_scale, changepoint_range, holidays_prior_scale. Other parameters are expected to be set by the user.

Returns:

Grid to tune.

Return type:

Dict[str, BaseDistribution]

predict(ts: TSDataset, prediction_interval: bool = False, quantiles: Sequence[float] = (0.025, 0.975), return_components: bool = False) TSDataset[source]#

Make predictions with using true values as autoregression context if possible (teacher forcing).

Parameters:
  • ts (TSDataset) – Dataset with features

  • prediction_interval (bool) – If True returns prediction interval for forecast

  • quantiles (Sequence[float]) – Levels of prediction distribution. By default 2.5% and 97.5% are taken to form a 95% prediction interval

  • return_components (bool) – If True additionally returns prediction components

Returns:

Dataset with predictions

Return type:

TSDataset

save(path: Path)[source]#

Save the object.

Parameters:

path (Path) – Path to save object to.

set_params(**params: dict) Self[source]#

Return new object instance with modified parameters.

Method also allows to change parameters of nested objects within the current object. For example, it is possible to change parameters of a model in a Pipeline.

Nested parameters are expected to be in a <component_1>.<...>.<parameter> form, where components are separated by a dot.

Parameters:

**params (dict) – Estimator parameters

Returns:

New instance with changed parameters

Return type:

Self

Examples

>>> from etna.pipeline import Pipeline
>>> from etna.models import NaiveModel
>>> from etna.transforms import AddConstTransform
>>> model = NaiveModel(lag=1)
>>> transforms = [AddConstTransform(in_column="target", value=1)]
>>> pipeline = Pipeline(model, transforms=transforms, horizon=3)
>>> pipeline.set_params(**{"model.lag": 3, "transforms.0.value": 2})
Pipeline(model = NaiveModel(lag = 3, ), transforms = [AddConstTransform(in_column = 'target', value = 2, inplace = True, out_column = None, )], horizon = 3, )
to_dict()[source]#

Collect all information about etna object in dict.

property context_size: int[source]#

Context size of the model. Determines how many history points do we ask to pass to the model.

Zero for this model.