A package containing multiple change-point detection methods for normal mean model (mean shift detection).
Project description
Change-point detection with cpdetect
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
numpypandasscipy
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cpdetect-0.0.2.tar.gz.
File metadata
- Download URL: cpdetect-0.0.2.tar.gz
- Upload date:
- Size: 24.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b65a6b87a9fbed014a50831b505277b601c714c7bf71a918402fc35c4cccdb5
|
|
| MD5 |
62608541c2bdc9b43d34367814040338
|
|
| BLAKE2b-256 |
53739678a0d093bed48cb582eb53778c5da8a906db4ed5cc29a78e14e2fa89fc
|
File details
Details for the file cpdetect-0.0.2-py3-none-any.whl.
File metadata
- Download URL: cpdetect-0.0.2-py3-none-any.whl
- Upload date:
- Size: 24.5 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca3a02e939d166ec71cbb232266d4efeb1e9e65c2c99f6730fe40d5b7af315b7
|
|
| MD5 |
e8eb8db6067a389809e7f0a96e4de61a
|
|
| BLAKE2b-256 |
cd0c42b3318932e0e5e57f42cf2b93f3c3c14efdadba0374faf1e7a94317cc7b
|