Kats Changepoints
Use this skill after time-series data preparation when the task is changepoint or significant process-change detection with Kats.
Kats supports multiple detection families. Some are explicit changepoint detectors; others are trend/anomaly/statistical-change detectors. Keep that distinction in outputs.
Minimum Install
pip install --upgrade pip
pip install kats
Kats also documents MINIMAL_KATS=1 pip install kats, but warns that minimal installation disables many functions and logs warnings. PyPI lists kats 0.2.0 as the latest release, published March 15, 2022.
Data Contract
- Use
kats.consts.TimeSeriesData.
- Initialize from a pandas
DataFrame, Series, DatetimeIndex, or explicit time and value.
- DataFrame input defaults to a time column named
time; use time_col_name when needed.
value can be a pandas Series for univariate or DataFrame for multivariate.
- Require sorted time, numeric finite values, documented frequency/gaps, train/current split for online-like detectors, and entity id if looping over panels.
- For multiple independent series, fit detectors per entity unless using a documented multivariate/vectorized path.
Read references/kats-data-workflow.md before adapting panels, online detection, multivariate inputs, or production windows.
Core Patterns
Single level-shift changepoint with CUSUM:
from kats.consts import TimeSeriesData
from kats.detectors.cusum_detection import CUSUMDetector
ts = TimeSeriesData(df, time_col_name="time")
detector = CUSUMDetector(ts)
change_points = detector.detector(change_directions=["increase", "decrease"])
detector.plot(change_points)
Online Bayesian changepoints:
from kats.detectors.bocpd import BOCPDetector, BOCPDModelType
detector = BOCPDetector(ts)
change_points = detector.detector(
model=BOCPDModelType.NORMAL_KNOWN_MODEL,
lag=10,
threshold=0.5,
)
detector.plot(change_points)
Rolling CUSUM model for multiple level shifts:
from kats.detectors.cusum_model import CUSUMDetectorModel
model = CUSUMDetectorModel(
scan_window=43200,
historical_window=604800,
threshold=0.01,
change_directions=["increase"],
)
response = model.fit_predict(ts)
change_points_unix = model.cps
Detector Choice
CUSUMDetector: explicit level-shift changepoint detector; assumes one increase and/or one decrease changepoint and Gaussian mean-change testing.
BOCPDetector: Bayesian Online Changepoint Detection; use for online-style detection where lag controls delay/certainty.
RobustStatDetector: robust univariate statistical changepoint detector from official source; uses smoothed differences, z-scores, and p-value cutoff.
CUSUMDetectorModel: DetectorModel wrapper that runs CUSUM repeatedly over historical_window and scan_window to detect multiple level-shift points.
MKDetector: Mann-Kendall trend detector; use for persistent monotonic trend alerts, not generic distributional changepoints.
StatSigDetectorModel / MultiStatSigDetectorModel: rolling test-vs-control statistical-change detectors; use when comparing current windows to historical windows.
ProphetDetectorModel: documented as Prophet-based anomaly detection, not a changepoint detector.
Read references/kats-api-map.md before choosing parameters or reporting detector capabilities.
Fit, Detection, and Outputs
- Classic detectors use
Detector(data).detector(...) and return changepoint objects, usually with start_time, end_time, and confidence.
- Detector models use
fit, predict, or fit_predict and return AnomalyResponse or store changepoints in model attributes such as CUSUMDetectorModel.cps.
- Plot with detector-specific
.plot(change_points) where documented. CUSUM multivariate plotting is explicitly not supported in the API docs.
- For BOCPD, use
get_change_prob() and get_run_length_matrix() after detection when probability diagnostics are needed.
Evaluation
- With labeled changepoints, use
kats.detectors.changepoint_evaluator.get_cp_index, f_measure, and true_positives.
f_measure expects 0-based changepoint locations and a margin tolerance.
- The Turing benchmark evaluator is documented for changepoint benchmark evaluation, but custom datasets must match the documented columns.
- Without labels, report window/threshold sensitivity, detection delay for online workflows, false alert review, and domain plausibility.
Anti-Leakage Rules
- Split train/history/current/test periods before interpolation, smoothing, seasonality removal, threshold tuning, priors, or detector selection.
- For online detectors, pass only past data as
historical_data and current/future windows as data; do not let future points influence earlier alerts.
- Tune
threshold, lag, changepoint_prior, scan_window, historical_window, step_window, p_value_cutoff, smoothing_window_size, window_size, n_control, and n_test on validation periods only.
- If removing seasonality or interpolating gaps, fit the policy inside each train/history window.
- Evaluate with temporal cuts, labeled retrospective periods, or rolling/expanding backtests; never random split.
Common Errors
- Treating all Kats detectors as changepoint detectors; some are anomaly or trend detectors.
- Using
CUSUMDetector for many changepoints in one pass; use CUSUMDetectorModel or windowed workflows for multiple level shifts.
- Passing multivariate data to a univariate-only detector such as
RobustStatDetector.
- Forgetting that
BOCPDetector reports after a lag, so detection time and true change time can differ.
- Setting windows in seconds for
CUSUMDetectorModel without matching the data frequency.
- Tuning thresholds on the final test window.
- Using minimal Kats installation and expecting all detection dependencies to work.
References
- Read
references/kats-data-workflow.md for TimeSeriesData shapes, panels, and online/history splits.
- Read
references/kats-api-map.md for detector capabilities, parameters, outputs, plotting, and limitations.
- Read
references/official-sources.md for official sources consulted.
- Use
scripts/validate_kats_changepoints.py to sanity-check CSV input, labels, and window sizes.
Ready Checklist
- Data is sorted, numeric, finite, and converted to
TimeSeriesData.
- Detector choice matches the documented change type and univariate/multivariate support.
- Offline vs online semantics, window sizes,
lag, and threshold policy are explicit.
- Evaluation uses labeled changepoints, temporal validation, or rolling/expanding windows.
- No preprocessing, priors, thresholds, or window settings leak validation/test future data.
1---2name: changepoint-kats3description: Use Kats for changepoint, level-shift, online Bayesian changepoint, robust statistical changepoint, rolling CUSUM, trend, and statistical-change detection after validating prepared time-series data, including TimeSeriesData inputs, univariate/multivariate constraints, thresholds, windows, priors, evaluation, plotting, and leakage-safe offline or online workflows.4---56# Kats Changepoints78Use this skill after time-series data preparation when the task is changepoint or significant process-change detection with Kats.910Kats supports multiple detection families. Some are explicit changepoint detectors; others are trend/anomaly/statistical-change detectors. Keep that distinction in outputs.1112## Minimum Install1314```bash15pip install --upgrade pip16pip install kats17```1819Kats also documents `MINIMAL_KATS=1 pip install kats`, but warns that minimal installation disables many functions and logs warnings. PyPI lists `kats 0.2.0` as the latest release, published March 15, 2022.2021## Data Contract2223- Use `kats.consts.TimeSeriesData`.24- Initialize from a pandas `DataFrame`, `Series`, `DatetimeIndex`, or explicit `time` and `value`.25- DataFrame input defaults to a time column named `time`; use `time_col_name` when needed.26- `value` can be a pandas `Series` for univariate or `DataFrame` for multivariate.27- Require sorted time, numeric finite values, documented frequency/gaps, train/current split for online-like detectors, and entity id if looping over panels.28- For multiple independent series, fit detectors per entity unless using a documented multivariate/vectorized path.2930Read `references/kats-data-workflow.md` before adapting panels, online detection, multivariate inputs, or production windows.3132## Core Patterns3334Single level-shift changepoint with CUSUM:3536```python37from kats.consts import TimeSeriesData38from kats.detectors.cusum_detection import CUSUMDetector3940ts = TimeSeriesData(df, time_col_name="time")41detector = CUSUMDetector(ts)42change_points = detector.detector(change_directions=["increase", "decrease"])43detector.plot(change_points)44```4546Online Bayesian changepoints:4748```python49from kats.detectors.bocpd import BOCPDetector, BOCPDModelType5051detector = BOCPDetector(ts)52change_points = detector.detector(53 model=BOCPDModelType.NORMAL_KNOWN_MODEL,54 lag=10,55 threshold=0.5,56)57detector.plot(change_points)58```5960Rolling CUSUM model for multiple level shifts:6162```python63from kats.detectors.cusum_model import CUSUMDetectorModel6465model = CUSUMDetectorModel(66 scan_window=43200,67 historical_window=604800,68 threshold=0.01,69 change_directions=["increase"],70)71response = model.fit_predict(ts)72change_points_unix = model.cps73```7475## Detector Choice7677- `CUSUMDetector`: explicit level-shift changepoint detector; assumes one increase and/or one decrease changepoint and Gaussian mean-change testing.78- `BOCPDetector`: Bayesian Online Changepoint Detection; use for online-style detection where `lag` controls delay/certainty.79- `RobustStatDetector`: robust univariate statistical changepoint detector from official source; uses smoothed differences, z-scores, and p-value cutoff.80- `CUSUMDetectorModel`: `DetectorModel` wrapper that runs CUSUM repeatedly over `historical_window` and `scan_window` to detect multiple level-shift points.81- `MKDetector`: Mann-Kendall trend detector; use for persistent monotonic trend alerts, not generic distributional changepoints.82- `StatSigDetectorModel` / `MultiStatSigDetectorModel`: rolling test-vs-control statistical-change detectors; use when comparing current windows to historical windows.83- `ProphetDetectorModel`: documented as Prophet-based anomaly detection, not a changepoint detector.8485Read `references/kats-api-map.md` before choosing parameters or reporting detector capabilities.8687## Fit, Detection, and Outputs8889- Classic detectors use `Detector(data).detector(...)` and return changepoint objects, usually with `start_time`, `end_time`, and `confidence`.90- Detector models use `fit`, `predict`, or `fit_predict` and return `AnomalyResponse` or store changepoints in model attributes such as `CUSUMDetectorModel.cps`.91- Plot with detector-specific `.plot(change_points)` where documented. CUSUM multivariate plotting is explicitly not supported in the API docs.92- For BOCPD, use `get_change_prob()` and `get_run_length_matrix()` after detection when probability diagnostics are needed.9394## Evaluation9596- With labeled changepoints, use `kats.detectors.changepoint_evaluator.get_cp_index`, `f_measure`, and `true_positives`.97- `f_measure` expects 0-based changepoint locations and a `margin` tolerance.98- The Turing benchmark evaluator is documented for changepoint benchmark evaluation, but custom datasets must match the documented columns.99- Without labels, report window/threshold sensitivity, detection delay for online workflows, false alert review, and domain plausibility.100101## Anti-Leakage Rules102103- Split train/history/current/test periods before interpolation, smoothing, seasonality removal, threshold tuning, priors, or detector selection.104- For online detectors, pass only past data as `historical_data` and current/future windows as `data`; do not let future points influence earlier alerts.105- Tune `threshold`, `lag`, `changepoint_prior`, `scan_window`, `historical_window`, `step_window`, `p_value_cutoff`, `smoothing_window_size`, `window_size`, `n_control`, and `n_test` on validation periods only.106- If removing seasonality or interpolating gaps, fit the policy inside each train/history window.107- Evaluate with temporal cuts, labeled retrospective periods, or rolling/expanding backtests; never random split.108109## Common Errors110111- Treating all Kats detectors as changepoint detectors; some are anomaly or trend detectors.112- Using `CUSUMDetector` for many changepoints in one pass; use `CUSUMDetectorModel` or windowed workflows for multiple level shifts.113- Passing multivariate data to a univariate-only detector such as `RobustStatDetector`.114- Forgetting that `BOCPDetector` reports after a `lag`, so detection time and true change time can differ.115- Setting windows in seconds for `CUSUMDetectorModel` without matching the data frequency.116- Tuning thresholds on the final test window.117- Using minimal Kats installation and expecting all detection dependencies to work.118119## References120121- Read `references/kats-data-workflow.md` for TimeSeriesData shapes, panels, and online/history splits.122- Read `references/kats-api-map.md` for detector capabilities, parameters, outputs, plotting, and limitations.123- Read `references/official-sources.md` for official sources consulted.124- Use `scripts/validate_kats_changepoints.py` to sanity-check CSV input, labels, and window sizes.125126## Ready Checklist127128- Data is sorted, numeric, finite, and converted to `TimeSeriesData`.129- Detector choice matches the documented change type and univariate/multivariate support.130- Offline vs online semantics, window sizes, `lag`, and threshold policy are explicit.131- Evaluation uses labeled changepoints, temporal validation, or rolling/expanding windows.132- No preprocessing, priors, thresholds, or window settings leak validation/test future data.