22
$\begingroup$

I'm looking for a Python module that performs a change-point analysis on a time-series. There are a number of different algorithms and I'd like to explore the efficacy of some of them without having to hand-roll each of the algorithms.

Ideally I'd like some modules like the bcp (Bayesian Change Point) or strucchange packages in R. I expected to find some in Scipy but I haven't been able to turn up anything.

I'm surprised that there aren't any facilities in:

Are there any modules with change point detection algorithms in Python?

$\endgroup$
  • $\begingroup$ I'm also looking for change-point analysis in Python. Did you find anything useful (e.g. using RPy?). $\endgroup$ – Jack Kelly Oct 17 '13 at 11:24
  • $\begingroup$ Use the fused lasso in SPAMS spams-devel.gforge.inria.fr (has Python bindings). $\endgroup$ – Vladislavs Dovgalecs Feb 9 '16 at 22:22
  • $\begingroup$ anyone found any good changepoint analysis library by now (implementing various algorithms say binary segmentation, segment neighbourhood)? $\endgroup$ – Mahesha999 Nov 2 '16 at 13:43
  • $\begingroup$ For online time series data, how does a Change-Point Detection implementation, say changefinder can scale? This seems to be an inherent problem to me. $\endgroup$ – HoofarLotusX Oct 1 '18 at 22:30
6
$\begingroup$

There are still some gaps in the Python library for using advanced statistics packages. Have you tried using the RPy module? When using RPy you can load R modules.

brief tutorial on RPy: http://www.sciprogblog.com/2012/08/using-r-from-within-python.html strucchange

$\endgroup$
  • 2
    $\begingroup$ is this still the case? Do I still need to end up using R-Python bridge? $\endgroup$ – Mahesha999 Oct 25 '16 at 13:53
  • $\begingroup$ anyone found any good changepoint analysis library by now (implementing various algorithms say binary segmentation, segment neighbourhood)? $\endgroup$ – Mahesha999 Nov 2 '16 at 13:43
6
$\begingroup$

You can try out the changefinder library on PyPI. The description says that it's an online Change Detection Library based on the ChangeFinder algorithm

There are also some Python implementations of Michele Basseville's Statistical Change Point Detection techniques available in tutorial format on this Github repo.

$\endgroup$
  • 3
    $\begingroup$ A Python implementation of Bayesian Change Point Detection can also be found at this Github repo. $\endgroup$ – kushan_s Jul 23 '14 at 6:06
  • 1
    $\begingroup$ looks like the first link in the answer (amanahuja) is incomplete? the other one you posted in the comment is useful! $\endgroup$ – okkhoy May 2 '16 at 6:49
4
$\begingroup$

This implementation of the Python package rpy2 worked for me:

import numpy as np
from rpy2.robjects.packages import importr
import rpy2.robjects as robjects

r = robjects.r #allows access to r object with r.

bcp = importr('bcp') #import bayesian change point package in python

values = bcp.bcp( r.c( r.rnorm(50) , r.rnorm(50,5,1), r.rnorm(50) ) ) #use bcp function on vector

posterior_means = np.array(values[5]).flatten()
posterior_probability = np.array(values[7]).flatten()

Then, you can plot the posterior means and posterior probability against the original vector. See the bcp function example in R for more detailed information about this example.

Also, hard indexing values with a number (i.e. values[5]) is not ideal, but I was having a hard time using the rx and rx2 extractor. So if anyone can enlighten me on a less hacky method of extraction, I'd love to know!

$\endgroup$
1
$\begingroup$

I just came across a change point detection library in Python named "ruptures" : https://arxiv.org/abs/1801.00826

Maybe this can be of use.

$\endgroup$
0
$\begingroup$

Have you tried ChangeFinder library, you can install it on linux by:

pip install changefinder

also Bayesian_changepoint_detection GitHub code can be found here: GitHub Code

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.