Prophet#

Prophet – trend change point detection via Facebook Prophet.

Description#

This detector returns the change points of Facebook Prophet’s piecewise-linear trend. Prophet lets the trend’s rate change at a set of potential change points, with an L1-regularised (sparse, Laplace) prior on the rate-change magnitudes delta so that most potential points go unused. The detector places n_candidates potential change points evenly over the series and scores each one by its fitted |delta| relative to the median |delta| over the candidates. It returns the n_changepoints strongest when this number is given, otherwise those whose score exceeds delta_threshold (a relative form of TCPDBench’s rule). Two returned change points are at least tolerance apart (non-maximum suppression). A piecewise-linear trend cannot jump, so Prophet fits a level shift as a steep ramp: a run of rate changes of one sign on the candidates just before the shift, then a run of the opposite sign just after it. A ramp wider than tolerance can give two change points for one shift, which may leave a smaller shift out of the n_changepoints returned.

Key parameters:

  • n_changepoints – number of change points to return (semi-supervised); None thresholds the rate changes instead.

  • n_candidates – number of evenly spaced potential change points; their spacing bounds the localisation accuracy.

  • changepoint_prior_scale – scale of the Laplace prior: larger values give sharper trend changes, closer to the true change points. The default (500) was calibrated for change point detection on TSB-SEG, far above Prophet’s forecasting default (0.05).

  • max_points – longer series are reduced to block means before the fit.

Type: change point detection
Supervision: semi-supervised (n_changepoints) or unsupervised
Scope: univariate (multivariate via ensembling or L2 norm)
Complexity: \(O(d\,n)\) for the L2 reduction (default strategy), then \(O(\tilde{n}\,S)\) per L-BFGS iteration of Prophet’s fit, where \(\tilde{n} = \min(n, 2000)\) (max_points) and S is n_candidates
Requires: prophet and cmdstanpy

Parameters#

Name

Type

Default

Description

n_changepoints

int / None

None

Number of change points to return; None selects them by delta_threshold.

n_changepoint_func

callable / None

None

Callable that determines n_changepoints from the series.

n_candidates

int

200

Number of evenly spaced potential change points.

changepoint_prior_scale

float

500.0

Scale of the Laplace prior on the rate changes.

delta_threshold

float

3.0

Minimum score (|delta| over its median) of a change point when n_changepoints is None.

seasonality

bool

False

Fit Prophet’s yearly, weekly and daily seasonalities.

multivariate_strategy

str

"l2"

"ensembling" (one model per channel, scores averaged over the channels) or "l2" (one model on the L2 norm).

tolerance

float

0.02

Minimum distance between two change points (fraction of the length when below 1, samples otherwise).

max_points

int / None

2000

Series longer than this are reduced to block means before the fit.

axis

int

0

Time axis.

Usage#

from tsseg.algorithms import ProphetDetector

detector = ProphetDetector(n_changepoints=10)
change_points = detector.fit_predict(X)

Implementation: Wrapper around facebook/prophet. MIT.

Reference: Taylor & Letham (2018), Forecasting at Scale, The American Statistician.

API reference#

Prophet-based change-point detector exposed as a tsseg segmenter.

class ProphetDetector(*, n_changepoints=None, n_changepoint_func=None, n_candidates=200, changepoint_prior_scale=500.0, delta_threshold=3.0, seasonality=False, multivariate_strategy='l2', tolerance=0.02, max_points=2000, axis=0)[source]#

Bases: BaseSegmenter

Change points of Prophet’s piecewise-linear trend.

Prophet [1] models the trend as a piecewise-linear function whose rate may change at a set of potential change points, with a sparse (Laplace) prior on the rate changes delta. The detector places n_candidates potential change points evenly over the series and scores each one by its fitted |delta| divided by the median |delta| over the candidates (averaged over the channels with "ensembling"). It returns the n_changepoints strongest when this number is given (semi-supervised), otherwise those whose score exceeds delta_threshold, a relative form of TCPDBench’s rule [2]. Two returned change points are at least tolerance apart (non-maximum suppression). A piecewise-linear trend cannot jump, so Prophet fits a level shift as a steep ramp: a run of rate changes of one sign on the candidates just before the shift, then a run of the opposite sign just after it. A ramp wider than tolerance can give two change points for one shift, which may leave a smaller shift out of the n_changepoints returned.

The defaults were calibrated for change point detection on 24 series of TSB-SEG (3 per dataset): a prior scale far above Prophet’s forecasting default (0.05) places the rate changes at the level shifts instead of spreading them over a smooth trend.

Parameters:
  • n_changepoints (int | None) – Number of change points to return. None selects them by delta_threshold.

  • n_changepoint_func (Callable[[ndarray], int] | None) – Callable returning n_changepoints from the series; overrides n_changepoints when given.

  • n_candidates (int) – Number of potential change points, evenly spaced; their spacing bounds the localisation accuracy.

  • changepoint_prior_scale (float) – Scale of Prophet’s Laplace prior on the rate changes; larger values allow sharper trend changes (Prophet’s own default is 0.05).

  • delta_threshold (float) – Minimum score of a change point when n_changepoints is None: its |delta| relative to the median |delta| over the candidates.

  • seasonality (bool) – Fit Prophet’s yearly, weekly and daily seasonalities. The time index is synthetic, so they are off by default.

  • multivariate_strategy (str) – "ensembling" fits one model per channel and averages the scores of each candidate over the channels; "l2" fits one model on the L2 norm of the channels.

  • tolerance (int | float) – Minimum distance between two returned change points, in samples, or as a fraction of the series length when below 1.

  • max_points (int | None) – Series longer than this are reduced to the means of consecutive blocks before the fit, which keeps Prophet’s cost bounded; the candidates stay evenly spaced over the full series. None fits the full series.

  • axis (int) – Time axis.

References

set_fit_request(*, axis='$UNCHANGED$')#

Configure whether metadata should be requested to be passed to the fit method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:

axis (Union[bool, None, str]) – Metadata routing for axis parameter in fit.

Returns:

self – The updated object.

Return type:

ProphetDetector

set_predict_request(*, axis='$UNCHANGED$')#

Configure whether metadata should be requested to be passed to the predict method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:

axis (Union[bool, None, str]) – Metadata routing for axis parameter in predict.

Returns:

self – The updated object.

Return type:

ProphetDetector

rate_change_profile(signal, n_candidates, changepoint_prior_scale, seasonality, multivariate_strategy, max_points)[source]#

Candidate positions and Prophet’s rate changes at each of them.

signal has shape (n_timepoints, n_channels). Series longer than max_points are reduced to block means before the fit (Prophet’s cost grows with the length times the number of candidates); the candidates are returned as indices of the full series. Returns (candidates, delta), delta of shape (n_models, n_candidates): one row per channel for "ensembling", one row for "l2" and univariate input.

Return type:

tuple[ndarray, ndarray]