claspy


Nameclaspy JSON
Version 0.2.5 PyPI version JSON
download
home_pagehttps://github.com/ermshaua/claspy
SummaryNone
upload_time2024-11-22 15:43:43
maintainerNone
docs_urlNone
authorArik Ermshaus
requires_python<3.13,>=3.7
licenseBSD 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 No requirements were recorded.
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.13,>=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/1e/a1/71e276c66c39807c3221708bed1ae4286ad81fe527cb40049ca9b1ea5b8d/claspy-0.2.5.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.5",
    "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": "88d7abb64facf01ac051663ef32b574e69d3f776069cf380e6242c0ab0e2733e",
                "md5": "b2e448d1a27d3ab60b0bfbd707446873",
                "sha256": "0252329c40ea3f321beccb4423b5eaf5ad35576870c1ea2ace47ce051c216e63"
            },
            "downloads": -1,
            "filename": "claspy-0.2.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b2e448d1a27d3ab60b0bfbd707446873",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<3.13,>=3.7",
            "size": 36282,
            "upload_time": "2024-11-22T15:43:41",
            "upload_time_iso_8601": "2024-11-22T15:43:41.709071Z",
            "url": "https://files.pythonhosted.org/packages/88/d7/abb64facf01ac051663ef32b574e69d3f776069cf380e6242c0ab0e2733e/claspy-0.2.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1ea171e276c66c39807c3221708bed1ae4286ad81fe527cb40049ca9b1ea5b8d",
                "md5": "10a2f1b48f96496d54077e836424fc9f",
                "sha256": "db0f42ea33d850da4949318e7588eeee73841aea540f154a00dce29ef634374f"
            },
            "downloads": -1,
            "filename": "claspy-0.2.5.tar.gz",
            "has_sig": false,
            "md5_digest": "10a2f1b48f96496d54077e836424fc9f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<3.13,>=3.7",
            "size": 33345,
            "upload_time": "2024-11-22T15:43:43",
            "upload_time_iso_8601": "2024-11-22T15:43:43.468827Z",
            "url": "https://files.pythonhosted.org/packages/1e/a1/71e276c66c39807c3221708bed1ae4286ad81fe527cb40049ca9b1ea5b8d/claspy-0.2.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-22 15:43:43",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ermshaua",
    "github_project": "claspy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "claspy"
}
        
Elapsed time: 0.37179s