cpt is a DuckDB extension for offline change point detection. It finds the points where the mean, the variance, a count rate or the median of a series shifts, with the methods statisticians use, inside DuckDB and next to your data.
Open source under MIT, written by Örjan Lundberg. Installs from the DuckDB community repository.
Exact PELT, binary segmentation for long series with few changes, dynamic programming for a known number of change points, and CROPS to see every answer across a range of penalties.
Changes in the mean, in the mean and variance, in the rate of counts, or in the median, which stays robust when the data has outliers.
BIC by default, MBIC and AIC as R’s changepoint package defines them, or any number you choose.
Results agree with Python’s ruptures on random series and with R’s changepoint on its reference datasets. With a minimum segment length, PELT here stays exact.
PELT with the l2 cost takes 0.84 s on 1,000,000 points on a laptop. Binary segmentation stays fast when a long series changes only a few times.
Written in C against DuckDB’s stable C API, so the same build loads in DuckDB 1.5.6 and later. The community repository serves it for DuckDB 2.0.
Each function takes one ordered series per row and returns where each segment ends. In the examples, series holds one list(value ORDER BY ts) per sensor, in the column xs.
BIC penalty by default, with at least 5 points in a segment.
Start, end, mean, variance and length of every segment found.
The optimal split into exactly four segments.
CROPS lists each distinct segmentation PELT gives in a penalty range.
The README covers every function, cost and penalty, with more examples. Questions and ideas are welcome as issues.