No project description provided
Project description
ClaSPy: A Python package for time series segmentation
Time series segmentation (TSS) tries to partition a time series (TS) into semantically meaningful segments. It's an important unsupervised learning task applied to large, real-world sensor signals for human inspection, change point detection or as preprocessing for classification and anomaly detection. This python library is the official implementation of the accurate and domain-agnostic TSS algorithm ClaSP.
Installation
You can install ClaSPy with PyPi:
python -m pip install claspy
Usage: univariate time series
Let's first import the ClaSP algorithm and univariate TS data from the "Time Series Segmentation Benchmark" (TSSB) to demonstrate its utility.
>>> from claspy.segmentation import BinaryClaSPSegmentation
>>> from claspy.data_loader import load_tssb_dataset
As an example, we choose the Cricket data set that contains motions of different umpire signals captured as wrist acceleration. ClaSP should automatically detect semantic changes between signals and deduce their segmentation. It is parameter-free, so we just need to pass the time series as a numpy array.
>>> dataset, window_size, true_cps, time_series = load_tssb_dataset(names=("CricketX",)).iloc[0,:]
>>> clasp = BinaryClaSPSegmentation()
>>> clasp.fit_predict(time_series)
[ 712 1281 1933 2581]
ClaSP is fully interpretable to human inspection. It creates a score profile (between 0 and 1) that estimates the probability of a "change point" in a TS, where one segment transitions into another. We visualize the segmentation and compare it to the pre-defined human annotation.
clasp.plot(gt_cps=true_cps, heading="Segmentation of different umpire cricket signals", ts_name="ACC", file_path="segmentation_example.png")
ClaSP accurately detects the number and location of changes in the motion sequence (compare green vs red lines) that infer its segmentation (the different-coloured subsequences). It is carefully designed to do this fully autonomously. However, if you have domain-specific knowledge, you can utilize it to guide and improve the segmentation. See its parameters for more information.
Usage: multivariate time series
Now, let's import multivariate TS data from the "Human Activity Segmentation Challenge" to show how ClaSP handles it.
>>> from claspy.data_loader import load_has_dataset
In this example, we use a motion routine from a student getting on, riding, and getting of a train. The multivariate TS consists of acceleration and magnetometer readings from a smartphone. We pass the time series as a 2-dimensional numpy array to ClaSP.
>>> dataset, window_size, true_cps, labels, time_series = load_has_dataset().iloc[107, :]
>>> clasp = BinaryClaSPSegmentation()
>>> clasp.fit_predict(time_series)
[ 781 8212 9287 14468]
We visualize the segmentation and compare it to the ground truth annotation.
clasp.plot(gt_cps=true_cps, heading=f"Segmentation of activity routine: {', '.join(labels)}", ts_name="ACC", font_size=18, file_path="multivariate_segmentation_example.png")
Also in the multivariate case, ClaSP correctly determines the number und location of activities in the routine. It is built to extract information from all TS channels to guide the segmentation. To ensure high performance, only provide necessary TS dimensions to ClaSP.
Examples
Checkout the following Jupyter notebooks that show applications of the ClaSPy package:
- ClaSP evaluation on the "Time Series Segmentation Benchmark" (TSSB)
- ClaSP results for the "Human Activity Segmentation Challenge"
- Hyper-parameter Tuning and Configuration of ClaSP
- Window Size Selection for Unsupervised Time Series Analytics
Citation
The ClaSPy package is actively maintained, updated and intended for application. If you use ClaSP in your scientific publication, we would appreciate the following citation:
@article{clasp2023,
title={ClaSP: parameter-free time series segmentation},
author={Arik Ermshaus and Patrick Sch{\"a}fer and Ulf Leser},
journal={Data Mining and Knowledge Discovery},
year={2023},
}
Todos
Here are some of the things we would like to add to ClaSPy in the future:
- Future research related to ClaSP
- Example and application Jupyter notebooks
- More documentation and tests
If you want to contribute, report bugs, or need help applying ClaSP for your application, feel free to reach out.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file claspy-0.2.4.tar.gz
.
File metadata
- Download URL: claspy-0.2.4.tar.gz
- Upload date:
- Size: 33.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03284c9d7bc37e78d01103ed1a407062404f76042d3f35871689add2795379ab |
|
MD5 | 94eeedf2e0c87a9cc35a0d49c60e109d |
|
BLAKE2b-256 | 5caafbfb64e8e442b10286f89298ba0b54dd91d0853432b3e0c6c0c6fc16565b |
File details
Details for the file claspy-0.2.4-py3-none-any.whl
.
File metadata
- Download URL: claspy-0.2.4-py3-none-any.whl
- Upload date:
- Size: 36.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65d10d02b4c7aa823c1fe1887376489818bd230dddd8c23da645d3c7467d3508 |
|
MD5 | cdc63fceaca1b955c3ef7fa4b3d6ae3e |
|
BLAKE2b-256 | e47903dcf6fa40352fcded94e0b0ac6daa7d5af5b47f5227c64dc951043c24bc |