Name | claspy JSON |
Version |
0.2.4
JSON |
| download |
home_page | https://github.com/ermshaua/claspy |
Summary | None |
upload_time | 2024-10-30 15:24:20 |
maintainer | None |
docs_url | None |
author | Arik Ermshaus |
requires_python | <3.12,>=3.7 |
license | BSD 3-Clause License Copyright (c) 2023, Arik Ermshaus Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
keywords |
machine-learning
time-series
unsupervised-learning
segmentation
change-points
|
VCS |
|
bugtrack_url |
|
requirements |
numpy
numba
pandas
scikit-learn
scipy
tomli
toml
setuptools
statsmodels
matplotlib
daproli
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# ClaSPy: A Python package for time series segmentation
[![PyPI version](https://badge.fury.io/py/claspy.svg)](https://pypi.org/project/claspy/) [![Downloads](https://pepy.tech/badge/claspy)](https://pepy.tech/project/claspy)
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 <a href="https://github.com/ermshaua/time-series-segmentation-benchmark" target="_blank">"Time Series Segmentation Benchmark"</a> (TSSB) to demonstrate its utility.
```python3
>>> from claspy.segmentation import BinaryClaSPSegmentation
>>> from claspy.data_loader import load_tssb_dataset
```
As an example, we choose the <a href="http://timeseriesclassification.com/description.php?Dataset=Cricket" target="_blank">Cricket</a> 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.
```python3
>>> 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.
```python3
clasp.plot(gt_cps=true_cps, heading="Segmentation of different umpire cricket signals", ts_name="ACC", file_path="segmentation_example.png")
```
<img src="https://raw.githubusercontent.com/ermshaua/claspy/main/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 <a href="https://github.com/ermshaua/claspy/blob/main/claspy/segmentation.py">parameters</a> for more information.
## Usage: multivariate time series
Now, let's import multivariate TS data from the <a href="https://github.com/patrickzib/human_activity_segmentation_challenge" target="_blank">"Human Activity Segmentation Challenge"</a> to show how ClaSP handles it.
```python3
>>> 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.
```python3
>>> 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.
```python3
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")
```
<img src="https://raw.githubusercontent.com/ermshaua/claspy/main/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:
- <a href="https://github.com/ermshaua/claspy/blob/main/claspy/notebooks/tssb_evaluation.ipynb">ClaSP evaluation on the "Time Series Segmentation Benchmark" (TSSB)</a>
- <a href="https://github.com/ermshaua/claspy/blob/main/claspy/notebooks/has_evaluation.ipynb">ClaSP results for the "Human Activity Segmentation Challenge"</a>
- <a href="https://github.com/ermshaua/claspy/blob/main/claspy/notebooks/clasp_configuration.ipynb">Hyper-parameter Tuning and Configuration of ClaSP</a>
- <a href="https://github.com/ermshaua/claspy/blob/main/claspy/notebooks/window_size_selection.ipynb">Window Size Selection for Unsupervised Time Series Analytics</a>
## 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 <a href="https://doi.org/10.1007/s10618-023-00923-x" target="_blank">citation</a>:
```
@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.
Raw data
{
"_id": null,
"home_page": "https://github.com/ermshaua/claspy",
"name": "claspy",
"maintainer": null,
"docs_url": null,
"requires_python": "<3.12,>=3.7",
"maintainer_email": null,
"keywords": "machine-learning, time-series, unsupervised-learning, segmentation, change-points",
"author": "Arik Ermshaus",
"author_email": "Arik Ermshaus <ermshaua@informatik.hu-berlin.de>",
"download_url": "https://files.pythonhosted.org/packages/5c/aa/fbfb64e8e442b10286f89298ba0b54dd91d0853432b3e0c6c0c6fc16565b/claspy-0.2.4.tar.gz",
"platform": null,
"description": "# ClaSPy: A Python package for time series segmentation\n[![PyPI version](https://badge.fury.io/py/claspy.svg)](https://pypi.org/project/claspy/) [![Downloads](https://pepy.tech/badge/claspy)](https://pepy.tech/project/claspy)\n\nTime 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.\n\n## Installation\nYou can install ClaSPy with PyPi: \n`python -m pip install claspy` \n\n## Usage: univariate time series\n\nLet's first import the ClaSP algorithm and univariate TS data from the <a href=\"https://github.com/ermshaua/time-series-segmentation-benchmark\" target=\"_blank\">\"Time Series Segmentation Benchmark\"</a> (TSSB) to demonstrate its utility.\n\n```python3\n>>> from claspy.segmentation import BinaryClaSPSegmentation\n>>> from claspy.data_loader import load_tssb_dataset\n```\n\nAs an example, we choose the <a href=\"http://timeseriesclassification.com/description.php?Dataset=Cricket\" target=\"_blank\">Cricket</a> 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.\n\n```python3\n>>> dataset, window_size, true_cps, time_series = load_tssb_dataset(names=(\"CricketX\",)).iloc[0,:]\n>>> clasp = BinaryClaSPSegmentation()\n>>> clasp.fit_predict(time_series)\n[ 712 1281 1933 2581]\n```\n\nClaSP 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.\n\n```python3\nclasp.plot(gt_cps=true_cps, heading=\"Segmentation of different umpire cricket signals\", ts_name=\"ACC\", file_path=\"segmentation_example.png\")\n```\n\n<img src=\"https://raw.githubusercontent.com/ermshaua/claspy/main/segmentation_example.png\" />\n\nClaSP 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 <a href=\"https://github.com/ermshaua/claspy/blob/main/claspy/segmentation.py\">parameters</a> for more information.\n\n## Usage: multivariate time series\n\nNow, let's import multivariate TS data from the <a href=\"https://github.com/patrickzib/human_activity_segmentation_challenge\" target=\"_blank\">\"Human Activity Segmentation Challenge\"</a> to show how ClaSP handles it.\n\n```python3\n>>> from claspy.data_loader import load_has_dataset\n```\nIn 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.\n\n```python3\n>>> dataset, window_size, true_cps, labels, time_series = load_has_dataset().iloc[107, :]\n>>> clasp = BinaryClaSPSegmentation()\n>>> clasp.fit_predict(time_series)\n[ 781 8212 9287 14468]\n```\n\nWe visualize the segmentation and compare it to the ground truth annotation.\n\n```python3\nclasp.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\")\n```\n\n<img src=\"https://raw.githubusercontent.com/ermshaua/claspy/main/multivariate_segmentation_example.png\" />\n\nAlso 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.\n\n## Examples\n\nCheckout the following Jupyter notebooks that show applications of the ClaSPy package:\n\n- <a href=\"https://github.com/ermshaua/claspy/blob/main/claspy/notebooks/tssb_evaluation.ipynb\">ClaSP evaluation on the \"Time Series Segmentation Benchmark\" (TSSB)</a>\n- <a href=\"https://github.com/ermshaua/claspy/blob/main/claspy/notebooks/has_evaluation.ipynb\">ClaSP results for the \"Human Activity Segmentation Challenge\"</a>\n- <a href=\"https://github.com/ermshaua/claspy/blob/main/claspy/notebooks/clasp_configuration.ipynb\">Hyper-parameter Tuning and Configuration of ClaSP</a>\n- <a href=\"https://github.com/ermshaua/claspy/blob/main/claspy/notebooks/window_size_selection.ipynb\">Window Size Selection for Unsupervised Time Series Analytics</a>\n\n## Citation\n\nThe ClaSPy package is actively maintained, updated and intended for application. If you use ClaSP in your scientific publication, we would appreciate the following <a href=\"https://doi.org/10.1007/s10618-023-00923-x\" target=\"_blank\">citation</a>:\n\n```\n@article{clasp2023,\n title={ClaSP: parameter-free time series segmentation},\n author={Arik Ermshaus and Patrick Sch{\\\"a}fer and Ulf Leser},\n journal={Data Mining and Knowledge Discovery},\n year={2023},\n}\n```\n\n## Todos\n\nHere are some of the things we would like to add to ClaSPy in the future:\n\n- Future research related to ClaSP\n- Example and application Jupyter notebooks\n- More documentation and tests \n\nIf you want to contribute, report bugs, or need help applying ClaSP for your application, feel free to reach out.\n",
"bugtrack_url": null,
"license": "BSD 3-Clause License Copyright (c) 2023, Arik Ermshaus Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ",
"summary": null,
"version": "0.2.4",
"project_urls": {
"Homepage": "https://github.com/ermshaua/claspy",
"repository": "https://github.com/ermshaua/claspy"
},
"split_keywords": [
"machine-learning",
" time-series",
" unsupervised-learning",
" segmentation",
" change-points"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "e47903dcf6fa40352fcded94e0b0ac6daa7d5af5b47f5227c64dc951043c24bc",
"md5": "cdc63fceaca1b955c3ef7fa4b3d6ae3e",
"sha256": "65d10d02b4c7aa823c1fe1887376489818bd230dddd8c23da645d3c7467d3508"
},
"downloads": -1,
"filename": "claspy-0.2.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "cdc63fceaca1b955c3ef7fa4b3d6ae3e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<3.12,>=3.7",
"size": 36279,
"upload_time": "2024-10-30T15:24:18",
"upload_time_iso_8601": "2024-10-30T15:24:18.762342Z",
"url": "https://files.pythonhosted.org/packages/e4/79/03dcf6fa40352fcded94e0b0ac6daa7d5af5b47f5227c64dc951043c24bc/claspy-0.2.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "5caafbfb64e8e442b10286f89298ba0b54dd91d0853432b3e0c6c0c6fc16565b",
"md5": "94eeedf2e0c87a9cc35a0d49c60e109d",
"sha256": "03284c9d7bc37e78d01103ed1a407062404f76042d3f35871689add2795379ab"
},
"downloads": -1,
"filename": "claspy-0.2.4.tar.gz",
"has_sig": false,
"md5_digest": "94eeedf2e0c87a9cc35a0d49c60e109d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<3.12,>=3.7",
"size": 33312,
"upload_time": "2024-10-30T15:24:20",
"upload_time_iso_8601": "2024-10-30T15:24:20.037921Z",
"url": "https://files.pythonhosted.org/packages/5c/aa/fbfb64e8e442b10286f89298ba0b54dd91d0853432b3e0c6c0c6fc16565b/claspy-0.2.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-30 15:24:20",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ermshaua",
"github_project": "claspy",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "numpy",
"specs": [
[
">=",
"1.21.0"
],
[
"<",
"1.25"
]
]
},
{
"name": "numba",
"specs": [
[
">=",
"0.53"
]
]
},
{
"name": "pandas",
"specs": [
[
"<",
"1.6.0"
],
[
">=",
"1.1.0"
]
]
},
{
"name": "scikit-learn",
"specs": [
[
"<",
"1.3.0"
],
[
">=",
"0.24.0"
]
]
},
{
"name": "scipy",
"specs": [
[
"<",
"2.0.0"
],
[
">=",
"1.2.0"
]
]
},
{
"name": "tomli",
"specs": [
[
">=",
"2.0.1"
]
]
},
{
"name": "toml",
"specs": [
[
">=",
"0.10.2"
]
]
},
{
"name": "setuptools",
"specs": [
[
">=",
"65.6.3"
]
]
},
{
"name": "statsmodels",
"specs": [
[
">=",
"0.13.5"
]
]
},
{
"name": "matplotlib",
"specs": [
[
">=",
"3.3"
]
]
},
{
"name": "daproli",
"specs": [
[
">=",
"0.22"
]
]
}
],
"lcname": "claspy"
}