tsseg.algorithms.kcpd package

KCPD — Kernel Change Point Detection.

Description

KCPD operates in a Reproducing Kernel Hilbert Space (RKHS) and detects mean-shifts in the mapped signal. The time series is implicitly mapped by a kernel function \(k(\cdot,\cdot)\) and the algorithm minimises:

\[V(t_1,\dots,t_K) = \sum_{k=0}^{K}\sum_{t=t_k}^{t_{k+1}-1} \|\phi(y_t) - \bar\mu_{t_k..t_{k+1}}\|_{\mathcal{H}}^2\]

When the number of changes K is known, the exact minimum is found by dynamic programming; otherwise a penalised formulation (PELT) is used.

Available kernels: "linear" (L2 cost), "rbf" (Gaussian), "cosine".

Type: change point detection
Supervision: unsupervised or semi-supervised
Scope: univariate and multivariate

Parameters

Name

Type

Default

Description

n_cps

int / None

None

Number of change points. None = use pen.

pen

float / None

10

Penalty for the penalised optimisation.

kernel

str

"rbf"

Kernel to use ("linear", "rbf", "cosine").

min_size

int

2

Minimum segment length.

jump

int

1

Sub-sampling factor for candidates.

cost_params

dict / None

None

Extra arguments for the kernel cost.

axis

int

0

Time axis.

Usage

from tsseg.algorithms import KCPDDetector

detector = KCPDDetector(kernel="rbf", n_cps=3)
labels = detector.fit_predict(X)

# Unknown K — use a penalty
detector = KCPDDetector(kernel="rbf", pen=10)
labels = detector.fit_predict(X)

Implementation: Vendored from ruptures v1.1.8 (C implementation). BSD 2-Clause.

Reference: Celisse, Marot, Pierre-Jean & Rigaill (2018), Computational Statistics and Data Analysis; Arlot, Celisse & Harchaoui (2019), JMLR.

Submodules

tsseg.algorithms.kcpd.detector module

Kernel-based change point detector built on the vendored ruptures implementation.

class tsseg.algorithms.kcpd.detector.KCPDDetector(*, n_cps=None, pen=10, kernel='rbf', min_size=2, jump=1, cost_params=None, axis=0)[source]

Bases: BaseSegmenter

Kernel change point detector using dynamic programming or PELT.

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

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$') KCPDDetector

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

Kernel change point detector.