CLaP#
CLaP (Classification Label Profile) – classification-based state detection.
Description#
CLaP extends ClaSP from change point detection to state detection. It first segments the series with ClaSP, then cross-validates a time series classifier (e.g. ROCKET) on 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.
CLaP runs in three modes:
Unsupervised: the number of segments is learned by ClaSP.
Guided: provide
n_segmentsorn_change_points.Exact: provide pre-computed
change_points; ClaSP is not run.
Parameters#
Name |
Type |
Default |
Description |
|---|---|---|---|
|
str / int |
|
Window size or auto-detection method. |
|
str |
|
aeon time series classifier: |
|
str |
|
Score that decides whether two confused labels are merged:
|
|
int |
|
Cross-validation folds. |
|
int |
|
Parallel jobs ( |
|
int |
|
Samples for classifier training. |
|
int / None |
|
Number of change points (overrides |
|
array-like / None |
|
Known change points (exact mode; ClaSP is not run). |
|
int / None |
|
Number of segments (guided mode). |
|
str |
|
Distance of ClaSP’s k-NN: |
|
int |
|
Seed of CLaP’s classifiers; ClaSP keeps the fixed seed of claspy (2357). |
Usage#
from tsseg.algorithms import ClapDetector
# Guided: four segments, one state label per time point
clap = ClapDetector(n_segments=4, classifier="rocket")
states = clap.fit_predict(X)
Implementation: Adapted from original ClaSP code by Arik Ermshaus. BSD 3-Clause.
Reference: Ermshaus, Schäfer & Leser (2024), CLaP – State Detection from Time Series.
API reference#
- class CLaP(window_size='suss', classifier='rocket', merge_score='cgain', n_splits=5, n_jobs=1, sample_size=1000, random_state=2357)[source]#
Bases:
object
This module provides a wrapper for the CLaP algorithm to integrate it with the tsseg library’s API.
- class ClapDetector(*, window_size='suss', classifier='rocket', merge_score='cgain', n_splits=5, n_jobs=1, sample_size=1000, random_state=42, n_change_points=None, change_points=None, n_segments=None, distance='znormed_euclidean_distance', axis=0)[source]#
Bases:
BaseSegmenterA wrapper for the CLaP (Classification Label Profile) algorithm for time series state detection, compatible with aeon.
- Parameters:
window_size (str or int, default="suss") – The window size or the method to determine it (‘suss’, ‘fft’, ‘acf’).
classifier (str, default="rocket") – The aeon time series classifier that is cross-validated on the segments:
"rocket"(RocketClassifier),"mrhydra"(MultiRocketHydraClassifier),"weasel"(WEASEL_V2),"quant"(QUANTClassifier),"rdst"(RDSTClassifier),"proximityforest"(ProximityForest),"freshprince"(FreshPRINCEClassifier) or"inception"(IndividualInceptionClassifier, which needs the aeon deep learning extras,pip install aeon[dl]).merge_score (str, default="cgain") – The score that decides whether two confused segment labels are merged:
"cgain"(classification gain),"f1_score"(macro F1),"log_loss","ami"(adjusted mutual information),"hamming_loss"or"roc_auc".n_splits (int, default=5) – Number of splits for cross-validation.
n_jobs (int, default=1) – The number of jobs to run in parallel. -1 means using all processors.
sample_size (int, default=1000) – The number of samples to use for training the classifier.
random_state (int, default=42) – Seed of the classifiers of CLaP. ClaSP, which finds the change points when
change_pointsis not given, does not use it: its ensemble draws with a fixed seed (2357, as in claspy).axis (
int) – The axis of the time series data.n_change_points (int, optional) – The number of change points to find (guided mode). Takes precedence over
n_segments;0yields a single segment, hence one state.change_points (array-like of int, optional) – Known change points (exact mode). When given, ClaSP is not run and
n_change_pointsandn_segmentsare ignored.n_segments (int, optional) – The number of segments to find (guided mode), passed to ClaSP.
distance (str, default="znormed_euclidean_distance") – The distance ClaSP uses to find the k nearest neighbours of each window:
"znormed_euclidean_distance","euclidean_distance"or"cinvariant_euclidean_distance"(complexity invariant). The z-normalised default compares the shapes of the windows, so it misses a change of level alone (a mean shift in noise); the other two see it.
Notes
CLaP labels the segments between change points. Three usage patterns are supported:
Exact – pass the known change points as
change_points; they are used as they are.Guided – pass
n_change_points(orn_segments). The count is forwarded toBinaryClaSPSegmentation, without its validation:n_change_points=kgiveskchange points, fewer only when the segments are too short to split further (each part must span at least five windows). claspy validates them in this mode too, so it may return fewer, or none.Fully unsupervised – the default behaviour: ClaSP estimates the change points and their number, each change point passing its significance test.
CLaP may then give two segments the same state label, so the number of states can be lower than the number of segments.
yis never used:fit()ignores it.CLaP labels the series given to
fit:predict(X)returns those labels whenXhas the same values, and otherwise labelsXwith a new fit, with a warning, leaving the fitted attributes unchanged.- states_#
An array of state labels for each time point. Available only after calling the fit or fit_predict method.
- Type:
np.ndarray
- change_points_#
The change points used for fitting the model.
- Type:
np.ndarray
- 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.