tsseg.algorithms.bottomup package

Bottom-Up segmentation — agglomerative merging of segments.

Description

Contrary to binary segmentation (top-down), bottom-up segmentation starts with a fine initial partition along a regular grid and successively merges the two most similar contiguous segments until a stopping criterion is met. The procedure is generous: it begins with many change points and removes the least significant ones.

Complexity is \(O(n\log n)\) where n is the number of samples, and the algorithm supports any cost function available in the vendored ruptures library.

Type: change point detection
Supervision: unsupervised or semi-supervised
Scope: univariate and multivariate
Complexity: \(O(n\log n)\)

Parameters

Name

Type

Default

Description

n_cps

int / None

None

Number of change points. When None, uses penalty or epsilon.

model

str

"l2"

Ruptures cost model ("l2", "l1", "rbf", etc.).

min_size

int

2

Minimum segment length.

jump

int

5

Grid step for candidate change points.

penalty

float / None

10

Penalty value. Mutually exclusive with n_cps / epsilon.

epsilon

float / None

None

Reconstruction budget. Mutually exclusive with n_cps / penalty.

cost_params

dict / None

None

Extra parameters passed to the cost function.

axis

int

0

Time axis.

Usage

from tsseg.algorithms import BottomUpDetector

detector = BottomUpDetector(model="l2", n_cps=3)
labels = detector.fit_predict(X)

# Penalty-based stopping
detector = BottomUpDetector(model="l2", penalty=10)
labels = detector.fit_predict(X)

Implementation: Vendored from ruptures v1.1.8. BSD 2-Clause.

Reference: Keogh, Chu, Hart & Pazzani (2001), ICDM; Fryzlewicz (2007), JASA.

Submodules

tsseg.algorithms.bottomup.detector module

Bottom-up detector built on the vendored ruptures implementation.

class tsseg.algorithms.bottomup.detector.BottomUpDetector(*, n_cps=None, model='l2', min_size=2, jump=5, penalty=10, epsilon=None, cost_params=None, axis=0)[source]

Bases: BaseSegmenter

Bottom-up change point detector.

set_fit_request(*, axis: bool | None | str = '$UNCHANGED$') BottomUpDetector

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 (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for axis parameter in fit.

Returns:

self – The updated object.

Return type:

object

set_predict_request(*, axis: bool | None | str = '$UNCHANGED$') BottomUpDetector

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 (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for axis parameter in predict.

Returns:

self – The updated object.

Return type:

object

Module contents

Bottom-up change point detector.