A changepoint is where the statistical properties of a series abruptly shift — a new mean, variance, or trend slope. PELT (Pruned Exact Linear Time) finds optimal changepoints efficiently. BOCPD (Bayesian Online Changepoint Detection) detects them in real-time.
A series whose mean moves from 0 to 1.5 at t = 60. The single best split is found at exactly 60, removing 42% of the squared error. On a series where nothing happens, the method still returns a “best” split (at t = 13) — but it removes only 1.8%. Whether a change is real depends on a penalty, not on the method finding one.
- A changepoint method will always find changes if you let it: the penalty, or the number of changepoints allowed, decides how many, so tune it on data with known breaks.
- A detected shift in the mean can also be a change in variance or a single outlier, depending on what the method assumes.
- An online detector can only flag a break some steps after it happened, once enough evidence has arrived.
rng = np.random.default_rng(9)
def best_split(y): # the single split that most reduces squared error
total = ((y - y.mean()) ** 2).sum()
gains = [total - ((y[:k] - y[:k].mean()) ** 2).sum() - ((y[k:] - y[k:].mean()) ** 2).sum() for k in range(5, len(y) - 5)]
k = int(np.argmax(gains)); return k + 5, gains[k] / total
shift = np.r_[rng.normal(0, 1, 60), rng.normal(1.5, 1, 40)] # the mean moves at t = 60
flat = rng.normal(0, 1, 100) # nothing happens
found, found_flat = best_split(shift), best_split(flat)Assumes import numpy as np and import pandas as pd. Each snippet simulates or makes up its own series, as the comments say.
The same idea with a library
# Python — changepoint detection with ruptures import ruptures as rpt algo = rpt.Pelt(model="rbf").fit(signal) breakpoints = algo.predict(pen=10) rpt.display(signal, breakpoints)
- E. S. Page, “Continuous Inspection Schemes”, Biometrika 41(1/2), 1954 — CUSUM
- R. Killick, P. Fearnhead & I. A. Eckley, “Optimal Detection of Changepoints with a Linear Computational Cost”, Journal of the American Statistical Association 107(500), 2012
- C. Truong, L. Oudre & N. Vayatis, “Selective Review of Offline Change Point Detection Methods”, Signal Processing 167, 2020
Last reviewed October 2026 · How this site checks its content · Report a mistake
- MLOps & Production MLDrift Detection in ProductionDetecting when the world changes under your model
- The ToolkitData Drift & Distribution ShiftIs your model still valid? PSI, KS test, and detecting when the world has changed
- Timeseries EngineeringProphetDecomposable forecasting at scale
- Timeseries EngineeringStationarityThe assumption that makes forecasting possible