KCPD#
KCPD – Kernel Change Point Detection.
Warning
Deprecated. KCPDDetector is not a method of its own: it runs the solvers of
PELT (with pen) and DynP (with n_cps) on a kernel
cost, and will be removed in a future release. Use
PeltDetector(model="rbf", penalty=pen, jump=1) or
DynpDetector(model="rbf", n_cps=k, jump=1) (model="l2" for the
linear kernel). For decimation=k, pass X[::k] and multiply the
change points by k; for pen_scale="bic", use a penalty of
pen * log(n) * d.
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:
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".
Parameters#
Name |
Type |
Default |
Description |
|---|---|---|---|
|
int / None |
|
Number of change points. |
|
float / None |
|
Penalty for the penalised optimisation. |
|
str |
|
Kernel to use ( |
|
int |
|
Minimum segment length. |
|
int |
|
Sub-sampling factor for candidates. |
|
dict / None |
|
Extra arguments for the kernel cost. |
|
int |
|
Time axis. |
Usage#
from tsseg.algorithms import KCPDDetector
detector = KCPDDetector(kernel="rbf", n_cps=3)
change_points = detector.fit_predict(X)
# Unknown K – use a penalty
detector = KCPDDetector(kernel="rbf", pen=10)
change_points = detector.fit_predict(X)
Implementation: vendored from ruptures v1.1.8, whose KernelCPD is a C
implementation of PELT and DynP for kernel costs. tsseg runs its vendored
Python Pelt / Dynp instead, or their numba backend (backend), which
for the rbf and cosine kernels transcribes that C code. BSD 2-Clause.
Reference: Celisse, Marot, Pierre-Jean & Rigaill (2018), Computational Statistics and Data Analysis; Arlot, Celisse & Harchaoui (2019), JMLR.
API reference#
Kernel-based change point detector built on the vendored ruptures implementation.
- class KCPDDetector(*, n_cps=None, pen=10, kernel='rbf', pen_scale=None, min_size=2, jump=1, decimation=1, cost_params=None, backend='auto', axis=0)[source]#
Bases:
BaseSegmenterKernel change point detector using dynamic programming or PELT.
Deprecated:
KCPDDetectoris not a method of its own. It runs the solvers ofPeltDetector(withpen) andDynpDetector(withn_cps) on a kernel cost, and will be removed in a future release. UsePeltDetector(model=kernel, penalty=pen, jump=1)orDynpDetector(model=kernel, n_cps=n_cps, jump=1), withmodel="l2"for the linear kernel. Fordecimation=k, passX[::k]and multiply the change points byk; forpen_scale="bic", use a penalty ofpen * log(n) * d.- Parameters:
n_cps (
int|None) – Number of change points: the dynamic programming solver is used. When given,penis ignored (with aUserWarning,penbeing 10 by default).0returns no change point.pen (
float|None) – Penalty per change point, used with the PELT solver whenn_cpsisNone.kernel (
str) – Kernel of the cost.pen_scale (
str|None) –None:penis used as is."bic": the penalty ispen * log(n) * d, n and d the length and number of channels of the series after decimation.min_size (
int) – Minimum segment length, in decimated samples.jump (
int) – Sub-sampling factor for candidate breakpoints, in decimated samples.decimation (
int) – Keep one sample indecimationbefore segmenting; the change points are mapped back to the time base ofX. Must be at least 1.cost_params (
dict|None) – Extra keyword arguments forwarded to the kernel cost (for instance{"gamma": 0.1}for"rbf").backend (
str) – Backend of the kernel costs: numba when it is installed under"auto", then without the n x n Gram matrix. Same change points either way.axis (
int) – Axis ofXthat represents time.
- Raises:
ValueError – If both
n_cpsandpenareNone, or ifdecimationis smaller than 1.
- 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.