ruptures is a Python library for off-line change point detection. This package provides methods for the analysis and segmentation of non-stationary signals. It is actively maintained with regular minor releases, and the current stable version is 1.1.10.
pip install rupturesVerified import paths — ran on the pinned version, not inferred.
This example generates a piecewise constant signal with noise, then applies the Pelt algorithm with an L2 cost function to detect change points. Finally, it visualizes the original signal, true change points, and detected change points.
Upgrade to ruptures v1.1.8 or later to ensure correct behavior, especially for `min_size=1`.
For reproducible results, upgrade to ruptures v1.1.6 or newer and ensure a random seed is set when generating data or initializing algorithms if randomness is involved.
Users experiencing memory-related issues with `KernelCPD` should update to ruptures v1.1.2 or later.
Upgrade to ruptures v1.1.4 or later to prevent unexpected side effects from in-place modifications when using `costar`.
Install the library using pip: `pip install ruptures`
Set `n_bkps` to an integer greater than 0, or use `n_bkps=None` for algorithms like Pelt that automatically select the number of change points. ```python import ruptures as rpt import numpy as np signal = np.random.rand(100) algo = rpt.Pelt(model="l2", n_bkps=None) # Correct # Or: algo = rpt.Binseg(model="l2", n_bkps=1) # Correct, if a specific positive number is desired ```
Pass the input data array (e.g., a NumPy array) as the `signal` argument to the `fit` method. ```python import ruptures as rpt import numpy as np signal = np.random.rand(100, 1) algo = rpt.Pelt(model="l2") algo.fit(signal) # Correct ```
Replace the `algo` parameter with `model` in the algorithm's constructor. ```python import ruptures as rpt # Incorrect: algo = rpt.Pelt(algo="l2") algo = rpt.Pelt(model="l2") # Correct ```