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);Nonethresholds 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.
n_changepoints) or unsupervisedmax_points) and S is
n_candidatesprophet and cmdstanpyParameters#
Name |
Type |
Default |
Description |
|---|---|---|---|
|
int / None |
|
Number of change points to return; |
|
callable / None |
|
Callable that determines |
|
int |
|
Number of evenly spaced potential change points. |
|
float |
|
Scale of the Laplace prior on the rate changes. |
|
float |
|
Minimum score ( |
|
bool |
|
Fit Prophet’s yearly, weekly and daily seasonalities. |
|
str |
|
|
|
float |
|
Minimum distance between two change points (fraction of the length when below 1, samples otherwise). |
|
int / None |
|
Series longer than this are reduced to block means before the fit. |
|
int |
|
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:
BaseSegmenterChange 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 placesn_candidatespotential 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 then_changepointsstrongest when this number is given (semi-supervised), otherwise those whose score exceedsdelta_threshold, a relative form of TCPDBench’s rule [2]. Two returned change points are at leasttoleranceapart (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 thantolerancecan give two change points for one shift, which may leave a smaller shift out of then_changepointsreturned.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.Noneselects them bydelta_threshold.n_changepoint_func (
Callable[[ndarray],int] |None) – Callable returningn_changepointsfrom the series; overridesn_changepointswhen 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 whenn_changepointsis 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.Nonefits the full series.axis (
int) – Time axis.
References
- set_fit_request(*, axis='$UNCHANGED$')#
Configure whether metadata should be requested to be passed to the
fitmethod.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(seesklearn.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 tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.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.
- set_predict_request(*, axis='$UNCHANGED$')#
Configure whether metadata should be requested to be passed to the
predictmethod.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(seesklearn.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 topredictif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it topredict.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.
- 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.
signalhas shape(n_timepoints, n_channels). Series longer thanmax_pointsare 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),deltaof shape(n_models, n_candidates): one row per channel for"ensembling", one row for"l2"and univariate input.