Skip to main content

Change-point detection with cpdetect

PyPI version GitHub Release Date Downloads

cpdetect is a python package designed for change point-detection using statistical methods. This is a first version and considers only one change-point model which is normal mean model. This assumes normally distributed time series values and changes only in the mean (mean shift). The package offers three detection methods which are Binary Segmentation (BS), Backward Detection (BWD) and Screening and Ranking algorithm (SaRa).

Install

To install the package use

pip install cpdetect

Example usage

Let's import some useful libraries first.

import scipy.stats as sp
import numpy as np
from matplotlib import pyplot as plt

Now we can create an example time series with three change-points.

# mean shifts between 0 and 3, sigma = 2
Y1 = sp.norm.rvs(0, 2, 200)
Y2 = sp.norm.rvs(3, 2, 200)
Y3 = sp.norm.rvs(0, 2, 200)
Y4 = sp.norm.rvs(3, 2, 200)
Y = np.hstack((Y1, Y2, Y3, Y4))
plt.plot(Y)

To find the change-points location we can use BinSeg which contains binary segmentation implementation.

from cpdetect import BinSeg

bs = BinSeg()                 # creating object

bs.fit(Y, stat='Z', sigma=2)  # fitting to data

plt.plot(bs.stat_values)      # statistic plot

bs.predict(0.01)              # change-point detection

If we don't know what the standard deviation (sigma) is, we can use T statistic.

bs.fit(Y, stat='T')        # fitting to data

plt.plot(bs.stat_values)   # statistic plot

bs.predict(0.01)           # change-point detection

If we don't know the distribution of time series values, we can't use normal mean models. Then we can use bootstrap which finds the statistic distribution by itself.

bs.predict(0.01, bootstrap_samples=1000)

Libraries used

  • numpy
  • pandas
  • scipy

Release files for cpdetect 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cpdetect 0.0.2
File Size Uploaded
cpdetect-0.0.2.tar.gz 24.5 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for cpdetect 0.0.2
File Interpreter ABI Platform
cpdetect-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 48.9 MB

Release files / cpdetect-0.0.2.tar.gz

Download URL cpdetect-0.0.2.tar.gz
Size 24.5 MB
Tags Source
SHA-256 checksum
How to use checksums
2b65a6b87a9fbed014a50831b505277b601c714c7bf71a918402fc35c4cccdb5
BLAKE2b-256 checksum
How to use checksums
53739678a0d093bed48cb582eb53778c5da8a906db4ed5cc29a78e14e2fa89fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.8

Release files / cpdetect-0.0.2-py3-none-any.whl

Download URL cpdetect-0.0.2-py3-none-any.whl
Size 24.5 MB
Tags Python 3
SHA-256 checksum
How to use checksums
ca3a02e939d166ec71cbb232266d4efeb1e9e65c2c99f6730fe40d5b7af315b7
BLAKE2b-256 checksum
How to use checksums
cd0c42b3318932e0e5e57f42cf2b93f3c3c14efdadba0374faf1e7a94317cc7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.8

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page