tsseg.algorithms.clap package
ClaSP and CLaP — classification-based time series segmentation.
Description
This package contains two related algorithms that share core routines:
ClaSP (Classification Score Profile) is a parameter-free method for change point detection. It hierarchically splits a time series by training a binary classifier (k-NN by default) for each possible split point and selecting the point that best separates the two halves. The number of change points and the window size are both learned automatically from the data. ClaSP is fast, domain-agnostic, and requires no distributional assumptions.
CLaP (Classification Label Profile) extends ClaSP from change point detection to state detection. Instead of a k-NN classifier, CLaP uses a time series classifier (e.g. ROCKET) and cross-validates segment-labelled subsequences. Segments with high confusion are iteratively merged, producing a set of state labels that can be reused across non-contiguous time regions.
Both algorithms support three usage modes:
Fully unsupervised — the number of segments is learned automatically.
Guided semi-supervised — provide
n_segmentsorn_change_points.Exact semi-supervised — provide pre-computed
change_points.
ClaSP parameters
Name |
Type |
Default |
Description |
|---|---|---|---|
|
str / int |
|
Number of segments ( |
|
int / None |
|
Exact number of change points (semi-supervised mode). |
|
int |
|
Number of ClaSPs in the ensemble. |
|
str / int |
|
Window size or auto method ( |
|
int |
|
Number of nearest neighbours for ClaSP. |
|
int |
|
Exclusion radius (multiples of window size). |
|
str |
|
Distance function for k-NN. |
|
str |
|
Scoring function for the profile. |
|
bool |
|
Stop early when no significant split is found. |
|
str |
|
Validation method for change point significance. |
|
str / float |
|
Threshold for the validation test. |
|
int |
|
Number of parallel jobs. |
CLaP parameters
Name |
Type |
Default |
Description |
|---|---|---|---|
|
str / int |
|
Window size or auto-detection method. |
|
str |
|
Time series classifier ( |
|
str |
|
Scoring function for segment merging. |
|
int |
|
Cross-validation folds. |
|
int |
|
Parallel jobs ( |
|
int |
|
Samples for classifier training. |
|
int / None |
|
Number of change points (overrides |
|
list / None |
|
Pre-computed change points for exact mode. |
|
int / None |
|
Number of segments. |
Usage
from tsseg.algorithms import ClaspDetector, ClapDetector
# --- ClaSP (change point detection, fully unsupervised) ---
clasp = ClaspDetector()
cps = clasp.fit_predict(X) # dense labels
# --- CLaP (state detection, guided) ---
clap = ClapDetector(n_segments=4, classifier="rocket")
states = clap.fit_predict(X) # sparse state labels
Implementation: Adapted from original ClaSP code by Arik Ermshaus. BSD 3-Clause.
Reference: Ermshaus, Schäfer & Leser (2023), ClaSP: parameter-free time series segmentation, DMKD; Ermshaus, Schäfer & Leser (2024), CLaP — State Detection from Time Series.