Ruptures

1.1.10 · active · verified Sat Apr 11

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.

Warnings

Install

Imports

Quickstart

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.

import ruptures as rpt
import numpy as np
import matplotlib.pyplot as plt

# Generate a signal with change points
n_samples, n_dims, sigma = 500, 3, 2
n_bkps = 3  # number of breakpoints
signal, bkps = rpt.pw_constant(n_samples, n_dims, n_bkps, noise_std=sigma, seed=42)

# Change point detection with Pelt algorithm and L2 cost
algo = rpt.Pelt(model="l2", jump=1, min_size=1).fit(signal)
result = algo.predict(pen=10)

# Display results
fig, ax_array = rpt.display(signal, bkps, result)
plt.show()

view raw JSON →