ClaSP#

ClaSP (Classification Score Profile) – classification-based change point detection.

Description#

ClaSP 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.

ClaSP runs in two modes:

  • Unsupervised (n_segments="learn", the default): the number of segments is learned, and each change point must pass the validation test.

  • Guided: provide n_segments or n_change_points. The count is returned as it is, fewer only when the segments are too short to split further; the change points are then not validated (claspy validates them in both modes).

The state detector CLaP starts from the change points of ClaSP and shares its core routines.

Type: change point detection
Supervision: unsupervised or semi-supervised
Scope: univariate and multivariate
Complexity: \(O(K\,d\,n^{2})\), where K is the number of change points

Parameters#

Name

Type

Default

Description

n_segments

str / int

"learn"

Number of segments ("learn" = auto-detect, each change point validated; an integer = guided mode, no validation).

n_change_points

int / None

None

Number of change points (guided mode, no validation; 0 = none).

n_estimators

int

10

Number of ClaSPs in the ensemble.

window_size

str / int

"suss"

Window size or auto method ("suss", "fft", "acf").

k_neighbours

int

3

Number of nearest neighbours for ClaSP.

excl_radius

int

5

Exclusion radius (multiples of window size).

distance

str

"znormed_euclidean_distance"

Distance function for k-NN.

score

str

"roc_auc"

Scoring function for the profile ("roc_auc" or "f1").

early_stopping

bool

True

Stop early when no significant split is found.

validation

str

"significance_test"

Validation method for change point significance (learned number of segments only).

threshold

str / float

"default"

Threshold for the validation test.

n_jobs

int

-1

Number of parallel jobs.

Usage#

from tsseg.algorithms import ClaspDetector

# Unsupervised: the number of change points is learned
cps = ClaspDetector().fit_predict(X)  # change point indices

# Guided: three change points
cps = ClaspDetector(n_change_points=3).fit_predict(X)

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.

API reference#

This module provides a wrapper for the ClaSP algorithm to integrate it with the tsseg library’s API.

class ClaspDetector(*, n_segments='learn', n_change_points=None, n_estimators=10, window_size='suss', k_neighbours=3, excl_radius=5, distance='znormed_euclidean_distance', score='roc_auc', early_stopping=True, validation='significance_test', threshold='default', n_jobs=-1, axis=0)[source]#

Bases: BaseSegmenter

A wrapper for the ClaSP (Classification Score Profile) algorithm for time series segmentation, using binary segmentation, compatible with aeon.

Parameters:
  • n_segments (str or int, default="learn") – The number of segments to split the time series into. If “learn”, the number is inferred automatically: each change point must pass the validation. An integer is a given number (guided mode), returned without validation. 1 returns no change point.

  • n_change_points (int, optional) – The number of change points (guided mode). Takes precedence over n_segments when set; 0 returns no change point.

  • n_estimators (int, default=10) – The number of ClaSPs in the ensemble.

  • window_size (str or int, default="suss") – The window size or the method to determine it (‘suss’, ‘fft’, ‘acf’).

  • k_neighbours (int, default=3) – The number of nearest neighbors to use in the ClaSP algorithm.

  • excl_radius (int, default=5) – The exclusion radius, in multiples of the window size.

  • distance (str, default="znormed_euclidean_distance") – The distance used to find the k nearest neighbours: "znormed_euclidean_distance", "euclidean_distance" or "cinvariant_euclidean_distance" (complexity invariant).

  • score (str, default="roc_auc") – The classification score of the profile: "roc_auc" or "f1".

  • early_stopping (bool, default=True) – Stop adding ClaSPs to the ensemble once a validated change point is found or a new ClaSP does not improve the best score. In the guided mode, where nothing is validated, the ensemble stops after its first ClaSP, fitted on the whole segment.

  • validation (str, default="significance_test") – How a candidate change point is accepted when the number of segments is learned: "significance_test" (statistical test on the score profile) or "score_threshold" (minimum score). Not used in the guided mode.

  • threshold (str or float, default="default") – The threshold of the validation: a p-value for "significance_test", a minimum score for "score_threshold". "default" means 1e-15 (univariate) or 1e-30 (multivariate) for the test, and 0.75 for the score.

  • n_jobs (int, default=-1) – The number of numba threads. Values below 1 mean all the threads numba may use; larger values are capped at that number.

  • axis (int) – The time axis of X: 0 if time points are rows.

change_points_#

The indices of the detected change points, sorted in ascending order. Available only after calling the fit or fit_predict method.

Type:

np.ndarray of int

Notes

In the guided mode (n_change_points, or an integer n_segments), the count is returned as it is: the candidate change points are not validated, so n_change_points=k gives k change points, fewer only when the segments are too short to split further (each part must span at least excl_radius windows). claspy validates them in this mode too, so it may return fewer, or none.

The ensemble draws its temporal constraints with a fixed seed (2357, as in claspy).

ClaSP segments the series given to fit: predict(X) returns those change points when X has the same values, and otherwise segments X with a new fit, with a warning, leaving the fitted attributes unchanged.

set_fit_request(*, axis='$UNCHANGED$')#

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 (Union[bool, None, str]) – Metadata routing for axis parameter in fit.

Returns:

self – The updated object.

Return type:

ClaspDetector

set_predict_request(*, axis='$UNCHANGED$')#

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 (Union[bool, None, str]) – Metadata routing for axis parameter in predict.

Returns:

self – The updated object.

Return type:

ClaspDetector