Skip to content

Bocpd

polars_ts.changepoint.bocpd

Bayesian Online Changepoint Detection (BOCPD).

bocpd(df, target_col='y', id_col='unique_id', time_col='ds', hazard_rate=200.0, mu_prior=0.0, kappa_prior=1.0, alpha_prior=1.0, beta_prior=1.0, threshold=0.5)

Detect changepoints using Bayesian Online Changepoint Detection.

Uses a normal-inverse-gamma conjugate model with constant hazard.

Parameters

df Input DataFrame. target_col Column to analyze. id_col Column identifying each time series. time_col Column with timestamps. hazard_rate Expected run length (higher = fewer changepoints). mu_prior Prior mean for the normal model. kappa_prior Prior precision scaling. alpha_prior Prior shape for inverse-gamma. beta_prior Prior rate for inverse-gamma. threshold Probability threshold above which a changepoint is flagged.

Returns

pl.DataFrame DataFrame with columns [id_col, time_col, "run_length", "changepoint_prob"] and a boolean "is_changepoint" column.

_log_student_t(x, mu, scale, df)

Log-probability of x under a Student-t distribution.