30
votes
$\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$
5
  • $\begingroup$ I'm also looking for change-point analysis in Python. Did you find anything useful (e.g. using RPy?). $\endgroup$
    – Jack Kelly
    Commented Oct 17, 2013 at 11:24
  • 1
    $\begingroup$ Use the fused lasso in SPAMS spams-devel.gforge.inria.fr (has Python bindings). $\endgroup$ Commented Feb 9, 2016 at 22:22
  • $\begingroup$ anyone found any good changepoint analysis library by now (implementing various algorithms say binary segmentation, segment neighbourhood)? $\endgroup$
    – Mahesha999
    Commented Nov 2, 2016 at 13:43
  • 1
    $\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$ Commented Oct 1, 2018 at 22:30
  • $\begingroup$ The most popular by download: 1. ruptures 2. changefinder 3. changepy 4. baysian-changepoint-detection Source: microprediction.com/blog/popular-timeseries-packages $\endgroup$ Commented Jan 12, 2021 at 1:33

6 Answers 6

10
votes
$\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$
2
  • 3
    $\begingroup$ A Python implementation of Bayesian Change Point Detection can also be found at this Github repo. $\endgroup$
    – kushan_s
    Commented Jul 23, 2014 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
    Commented May 2, 2016 at 6:49
7
votes
$\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
  • 2
    $\begingroup$ is this still the case? Do I still need to end up using R-Python bridge? $\endgroup$
    – Mahesha999
    Commented Oct 25, 2016 at 13:53
  • $\begingroup$ anyone found any good changepoint analysis library by now (implementing various algorithms say binary segmentation, segment neighbourhood)? $\endgroup$
    – Mahesha999
    Commented Nov 2, 2016 at 13:43
5
votes
$\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$
4
votes
$\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$
2
votes
$\begingroup$

Depending on your requirement for online/offline change point detection, python has the below packages:

1) The ruptures package, a Python library for performing offline change point detection.

2) Calling the R changepoint package into Python using the rpy2 package, an R-to-Python interface.

3) The changefinder package, a Python library for online change point detection.

4) Bayesian Change Point Detection - both online and offline approaches.

$\endgroup$
1
vote
$\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$

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