tsseg.algorithms.binseg package
Binary Segmentation (BinSeg) — fast sequential change point detection.
Description
Binary segmentation is a greedy, top-down procedure: it first detects a single change point in the full signal, then splits the series at that point and repeats the operation on each sub-signal until a stopping criterion is met.
The benefits include low complexity — \(O(C\,n\log n)\) where n is the number of samples and C the cost of evaluating the cost function on one sub-signal — and the ability to work whether the number of regimes is known beforehand or not.
Parameters
Name |
Type |
Default |
Description |
|---|---|---|---|
|
int / None |
|
Number of change points. When |
|
str |
|
Ruptures cost model ( |
|
int |
|
Minimum segment length. |
|
int |
|
Sub-sampling factor for candidate breakpoints. |
|
float / None |
|
Penalty value (BIC-style). Mutually exclusive with |
|
float / None |
|
Reconstruction-error tolerance. Mutually exclusive with |
|
BaseCost / None |
|
Pre-instantiated ruptures cost object. |
|
dict / None |
|
Additional keyword arguments forwarded to the cost factory. |
|
int |
|
Axis representing time. |
Usage
from tsseg.algorithms import BinSegDetector
detector = BinSegDetector(model="l2", n_cps=3)
labels = detector.fit_predict(X)
# Unknown number of change points — use a penalty
detector = BinSegDetector(model="l2", penalty=10)
labels = detector.fit_predict(X)
Implementation: Vendored from ruptures v1.1.8. BSD 2-Clause.
Reference: Bai (1997), Econometric Theory; Fryzlewicz (2014), The Annals of Statistics.
Submodules
tsseg.algorithms.binseg.detector module
BinSeg detector aligned with the tsseg BaseSegmenter API.
- class tsseg.algorithms.binseg.detector.BinSegDetector(*, n_cps=None, model='l2', min_size=2, jump=5, penalty=10, epsilon=None, custom_cost=None, cost_params=None, axis=0)[source]
Bases:
BaseSegmenterBinary Segmentation change-point detector using ruptures’ implementation.
This wrapper fits the single-change
Binsegsolver on the provided data and repeatedly splits the series to obtain multiple change points.- Parameters:
n_cps (
int|None) – Number of change points to return. WhenNone, ruptures stops according to its internal criteria (penorepsilon).model (
str) – Cost model passed to ruptures. Examples include “l2”, “l1”, “rbf”.min_size (
int) – Minimum segment length enforced during the binary search.jump (
int) – Sub-sampling factor for candidate breakpoints.penalty (
float|None) – Penalty threshold supplied topredict. Mutually exclusive withn_cpsandepsilon. Provide at least one ofn_cps,penaltyorepsilon.epsilon (
float|None) – Reconstruction error tolerance. Mutually exclusive withn_cpsandpenalty.custom_cost (
BaseCost|None) – Pre-instantiated ruptures cost object.cost_params (
dict|None) – Additional keyword arguments forwarded tocost_factorywhen building the cost frommodel.axis (
int) – Axis representing time in the input array.
- set_fit_request(*, axis: bool | None | str = '$UNCHANGED$') BinSegDetector
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: bool | None | str = '$UNCHANGED$') BinSegDetector
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.