Pelt
polars_ts.changepoint.pelt
PELT (Pruned Exact Linear Time) changepoint detection.
Delegates to the Rust implementation when available (10-50x faster), falling back to pure Python otherwise.
_cost_mean(data, start, end)
Cost of segment [start, end) under a change-in-mean model.
_cost_var(data, start, end)
Cost of segment [start, end) under a change-in-variance model.
_cost_meanvar(data, start, end)
Cost of segment under a change-in-mean-and-variance model.
_pelt_python(df, target_col, id_col, time_col, cost, penalty, min_size)
Pure-Python PELT implementation (fallback).
_pelt_rust(df, target_col, id_col, time_col, cost, penalty, min_size)
Rust-accelerated PELT implementation.
pelt(df, target_col='y', id_col='unique_id', time_col='ds', cost='mean', penalty=None, min_size=2)
Detect multiple changepoints using the PELT algorithm.
Parameters
df
Input DataFrame.
target_col
Column to analyze.
id_col
Column identifying each time series.
time_col
Column with timestamps.
cost
Cost function: "mean", "var", or "meanvar".
penalty
Penalty per changepoint. Defaults to 2 * log(n) (BIC-like).
min_size
Minimum segment length between changepoints.
Returns
pl.DataFrame
DataFrame with columns [id_col, "changepoint_idx", time_col]
listing detected changepoint locations.