Skip to main content

A package containing multiple change-point detection methods for normal mean model (mean shift detection).

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cpdetect-0.0.2.tar.gz (24.5 MB view details)

Uploaded Source

Built Distribution

cpdetect-0.0.2-py3-none-any.whl (24.5 MB view details)

Uploaded Python 3

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

Hashes for cpdetect-0.0.2.tar.gz
Algorithm Hash digest
SHA256 2b65a6b87a9fbed014a50831b505277b601c714c7bf71a918402fc35c4cccdb5
MD5 62608541c2bdc9b43d34367814040338
BLAKE2b-256 53739678a0d093bed48cb582eb53778c5da8a906db4ed5cc29a78e14e2fa89fc

See more details on using hashes here.

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

Hashes for cpdetect-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ca3a02e939d166ec71cbb232266d4efeb1e9e65c2c99f6730fe40d5b7af315b7
MD5 e8eb8db6067a389809e7f0a96e4de61a
BLAKE2b-256 cd0c42b3318932e0e5e57f42cf2b93f3c3c14efdadba0374faf1e7a94317cc7b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page