ClaSS#
ClaSS (Classification Score Stream) – online change point detection with a self-supervised classifier.
Description#
ClaSS is the streaming counterpart of ClaSP. It keeps the last
sliding_window_size points of a univariate stream and maintains, point by
point, the k nearest neighbours of every subsequence of width window_size
in that window. Every jump points, it scores each split of the window
after the last reported change point with a k-NN classifier (the ClaSP
profile, cross-validated with a macro F1 score). The best split is reported
as a change point when a rank-sum test on the predicted labels is
significant (p-value below 1e-50 by default). The subsequence width is
learned with SuSS on the first n_warmup points.
ClaSS is the first online detector of tsseg: see
Online detectors for the update API and the events it returns.
Parameters#
Name |
Type |
Default |
Description |
|---|---|---|---|
|
int |
|
Number of most recent points kept (d in the paper). |
|
int / None |
|
Points on which |
|
str / int |
|
Subsequence width, or |
|
int |
|
Number of nearest neighbours. |
|
str |
|
Subsequence distance (z-normalised Euclidean = Pearson correlation). |
|
int |
|
A split is searched every |
|
str |
|
|
|
str / float |
|
p-value (default 1e-50) or score threshold (default 0.75). |
|
int |
|
Exclusion radius of the profile, in multiples of |
|
int |
|
Time axis of the input. |
sliding_window_size, SuSS, the z-normalised distance, k_neighbours,
the macro F1 score and the 1e-50 significance level are the paper’s
(Section 4.2); jump and excl_radius come from claspy and the authors’
code.
Usage#
import numpy as np
from tsseg.algorithms import ClaSSDetector
rng = np.random.default_rng(0)
t = np.arange(3000)
X = np.where(t < 1500, np.sin(t / 5), np.sign(np.sin(t / 12)))
X = X + 0.1 * rng.standard_normal(t.size)
det = ClaSSDetector(sliding_window_size=2000)
for start in range(0, X.size, 100): # a stream, 100 points at a time
for event in det.update(X[start : start + 100]):
print(event["position"], event["detection_time"])
ClaSSDetector().fit_predict(X) # batch use: replay of the stream
A stream fed with update emits nothing before its warm-up is complete
(10,000 points by default); change points found in the warm-up points are
emitted when it completes. predict treats its input as a finite stream:
on a series shorter than the warm-up, window_size is learned on the
whole series, which is then segmented, as in the authors’ evaluation.
Implementation notes#
Vendored from claspy 0.2.8 (
claspy/streaming, BSD-3-Clause), on top of the ClaSP code that tsseg already vendors, with the split rule of the authors’ code: the change point is the profile argmax pluswindow_size, it is rejected within5 * window_sizeof the window edge, and the next segment starts at the reported change point. claspy applies the offset to the reported position only, so it placed a change that had just entered the window early (29 to 111 points in the tests) and started the next segmentwindow_sizepoints before it.Inherited from claspy: the significance test uses all the cross-validated labels of the window (the paper resamples 1,000 of them with replacement, Section 3.3) and splits them at the profile argmax; claspy’s
score="accuracy"has no effect, so it is not exposed.Scores of the events are
NaN: claspy does not log them.On the 75 TSSB series, the mean Covering is 0.848 (claspy: 0.838); the authors’ code scores 0.807 (their published per-series results). The reproduction test is
tests/reproduction/test_class_tssb.py.
Reference#
Ermshaus, A., Schäfer, P., and Leser, U. (2024). Raising the ClaSS of Streaming Time Series Segmentation. Proceedings of the VLDB Endowment, 17(8), 1953–1966. https://doi.org/10.14778/3659437.3659450