Alibi Detect Changepoints
Use this skill after time-series data preparation when a changepoint is defined as a distribution shift between stable reference history and later observations.
Important limitation: official Alibi Detect docs describe outlier, adversarial, and drift detection, not native offline changepoint segmentation. Use drift alarms as changepoint candidates and say so explicitly.
Minimum Install
pip install alibi-detect
Extras documented by the README include alibi-detect[tensorflow], [torch], [keops], and [prophet]. PyPI lists alibi-detect 0.13.0 as latest, released December 11, 2025, requiring Python >=3.9.
Data Contract
- Convert prepared time series to ordered arrays:
x_ref is stable reference history; stream/test rows arrive after it.
- Use
numpy.ndarray or list inputs. A typical tabular time-series frame becomes df[value_cols].to_numpy(dtype=float).
- For online detectors, call
predict(x_t) on one observation at a time, without a batch dimension.
- Keep timestamps outside Alibi Detect for plotting and evaluation; predictions return observation counts in
data["time"].
- Univariate and multivariate numeric features are supported depending on detector.
FETDriftOnline requires binary Bernoulli streams.
- For panels, fit one detector per entity unless the columns are a single multivariate process.
Read references/alibi-detect-data-workflow.md before adapting panels, context windows, preprocessing functions, or labels.
Core Pattern
import numpy as np
from alibi_detect.cd import MMDDriftOnline
x_ref = train_df[value_cols].to_numpy(dtype=np.float32)
stream = test_df[value_cols].to_numpy(dtype=np.float32)
cd = MMDDriftOnline(
x_ref=x_ref,
ert=500,
window_size=50,
backend="pytorch",
data_type="time-series",
)
alarms = []
for i, x_t in enumerate(stream):
pred = cd.predict(x_t, return_test_stat=True)
if pred["data"]["is_drift"] == 1:
alarms.append((test_df.index[i], pred["data"]))
pred["data"] includes is_drift, time, ert, and, when requested, test_stat plus threshold.
Detector Choice
MMDDriftOnline: multivariate kernel drift; use for general numeric distribution changes.
LSDDDriftOnline: multivariate least-squares density difference; use for density-difference drift alarms.
CVMDriftOnline: continuous univariate-per-feature test, with multivariate correction; use for continuous feature streams.
FETDriftOnline: binary Bernoulli streams; use for accuracy/error-rate or indicator streams.
- Rolling offline candidates:
MMDDrift, LSDDDrift, KSDrift, CVMDrift, FETDrift, ChiSquareDrift, TabularDrift, ClassifierDrift, LearnedKernelDrift, ContextMMDDrift, SpotTheDiffDrift, ClassifierUncertaintyDrift, RegressorUncertaintyDrift.
- Time-series outlier proxies such as
OutlierProphet, SpectralResidual, and OutlierSeq2Seq can flag anomalous intervals, but they are not documented changepoint segmenters.
Read references/alibi-detect-api-map.md before selecting detector parameters or claiming capabilities.
Fit, State, Prediction
- There is no
.fit() for online drift detectors in the core pattern; construction configures reference data and thresholds.
- Set
ert as the expected runtime before false detection under no drift.
- Set
window_size or window_sizes to balance delay and sensitivity.
- Use
preprocess_fn only if fitted on training/reference data. Set x_ref_preprocessed=True only when the stored reference was already transformed.
- Save/load online state with
save_state(...) and load_state(...); reset with reset_state().
Evaluation and Plotting
- Evaluate alarm timestamps against labeled changepoints with a tolerance or max-delay window.
- Report precision, recall, F1, mean/median detection delay, first-alarm delay, false alarms per time, and realized no-drift runtime versus configured
ert.
- For rolling offline tests, map each alarm to the end timestamp of the tested window unless a project-specific convention says otherwise.
- Alibi Detect does not document built-in changepoint plots. Plot source series,
test_stat, threshold, and vertical alarm lines with matplotlib.
Anti-Leakage Rules
- Split reference/train, validation, and test by time before scaling, dimensionality reduction, encoders, thresholds, or detector choice.
- Build
x_ref only from pre-change or training history available at deployment time.
- Do not tune
ert, window_size(s), p_val, kernels, preprocessing, or n_bootstraps on final test labels.
- If using rolling offline tests, each test window must only compare past reference/history to current/future window allowed at that decision time.
- Do not let
update_x_ref absorb validation/test future data unless that is the explicit production policy.
- For learned preprocessing, train encoders/classifiers on training data only.
Common Errors
- Presenting Alibi Detect as a native changepoint segmentation library.
- Passing a batch to online
predict; online detectors expect one instance at a time.
- Forgetting that
CVMDriftOnline and FETDriftOnline need full windows before useful statistics exist.
- Using
FETDriftOnline on non-binary data.
- Setting
n_bootstraps far below the requested ert, making thresholds noisy.
- Losing timestamps after converting to arrays and then misreporting alarm times.
- Globally scaling or embedding all data before the time split.
References
- Read
references/alibi-detect-data-workflow.md for array shapes, windows, panels, labels, and leakage.
- Read
references/alibi-detect-api-map.md for detector families, parameters, outputs, and limitations.
- Read
references/official-sources.md for official sources consulted.
- Use
scripts/validate_alibi_detect_changepoints.py to sanity-check CSV inputs and online detector settings.
Ready Checklist
- Task is framed as drift/change alarm detection, not offline optimal segmentation.
x_ref is stable, chronological, and leakage-free.
- Detector, backend, ERT, window sizes, preprocessing, and binary/continuous assumptions match the data.
- Alarm timestamps are mapped back to the original time index.
- Evaluation uses temporal labels/tolerance windows and reports detection delay plus false alarms.
1---2name: changepoint-alibi-detect3description: Use Seldon Alibi Detect for changepoint-like distribution-change monitoring after validating prepared time-series arrays, including online MMD/LSDD/CVM/FET drift detectors, rolling offline drift tests, reference windows, ERT, window sizes, preprocessing/backends, state handling, evaluation delay, plotting, and anti-leakage safeguards.4---56# Alibi Detect Changepoints78Use this skill after time-series data preparation when a changepoint is defined as a distribution shift between stable reference history and later observations.910Important limitation: official Alibi Detect docs describe outlier, adversarial, and drift detection, not native offline changepoint segmentation. Use drift alarms as changepoint candidates and say so explicitly.1112## Minimum Install1314```bash15pip install alibi-detect16```1718Extras documented by the README include `alibi-detect[tensorflow]`, `[torch]`, `[keops]`, and `[prophet]`. PyPI lists `alibi-detect 0.13.0` as latest, released December 11, 2025, requiring Python `>=3.9`.1920## Data Contract2122- Convert prepared time series to ordered arrays: `x_ref` is stable reference history; stream/test rows arrive after it.23- Use `numpy.ndarray` or list inputs. A typical tabular time-series frame becomes `df[value_cols].to_numpy(dtype=float)`.24- For online detectors, call `predict(x_t)` on one observation at a time, without a batch dimension.25- Keep timestamps outside Alibi Detect for plotting and evaluation; predictions return observation counts in `data["time"]`.26- Univariate and multivariate numeric features are supported depending on detector. `FETDriftOnline` requires binary Bernoulli streams.27- For panels, fit one detector per entity unless the columns are a single multivariate process.2829Read `references/alibi-detect-data-workflow.md` before adapting panels, context windows, preprocessing functions, or labels.3031## Core Pattern3233```python34import numpy as np35from alibi_detect.cd import MMDDriftOnline3637x_ref = train_df[value_cols].to_numpy(dtype=np.float32)38stream = test_df[value_cols].to_numpy(dtype=np.float32)3940cd = MMDDriftOnline(41 x_ref=x_ref,42 ert=500,43 window_size=50,44 backend="pytorch",45 data_type="time-series",46)4748alarms = []49for i, x_t in enumerate(stream):50 pred = cd.predict(x_t, return_test_stat=True)51 if pred["data"]["is_drift"] == 1:52 alarms.append((test_df.index[i], pred["data"]))53```5455`pred["data"]` includes `is_drift`, `time`, `ert`, and, when requested, `test_stat` plus `threshold`.5657## Detector Choice5859- `MMDDriftOnline`: multivariate kernel drift; use for general numeric distribution changes.60- `LSDDDriftOnline`: multivariate least-squares density difference; use for density-difference drift alarms.61- `CVMDriftOnline`: continuous univariate-per-feature test, with multivariate correction; use for continuous feature streams.62- `FETDriftOnline`: binary Bernoulli streams; use for accuracy/error-rate or indicator streams.63- Rolling offline candidates: `MMDDrift`, `LSDDDrift`, `KSDrift`, `CVMDrift`, `FETDrift`, `ChiSquareDrift`, `TabularDrift`, `ClassifierDrift`, `LearnedKernelDrift`, `ContextMMDDrift`, `SpotTheDiffDrift`, `ClassifierUncertaintyDrift`, `RegressorUncertaintyDrift`.64- Time-series outlier proxies such as `OutlierProphet`, `SpectralResidual`, and `OutlierSeq2Seq` can flag anomalous intervals, but they are not documented changepoint segmenters.6566Read `references/alibi-detect-api-map.md` before selecting detector parameters or claiming capabilities.6768## Fit, State, Prediction6970- There is no `.fit()` for online drift detectors in the core pattern; construction configures reference data and thresholds.71- Set `ert` as the expected runtime before false detection under no drift.72- Set `window_size` or `window_sizes` to balance delay and sensitivity.73- Use `preprocess_fn` only if fitted on training/reference data. Set `x_ref_preprocessed=True` only when the stored reference was already transformed.74- Save/load online state with `save_state(...)` and `load_state(...)`; reset with `reset_state()`.7576## Evaluation and Plotting7778- Evaluate alarm timestamps against labeled changepoints with a tolerance or max-delay window.79- Report precision, recall, F1, mean/median detection delay, first-alarm delay, false alarms per time, and realized no-drift runtime versus configured `ert`.80- For rolling offline tests, map each alarm to the end timestamp of the tested window unless a project-specific convention says otherwise.81- Alibi Detect does not document built-in changepoint plots. Plot source series, `test_stat`, `threshold`, and vertical alarm lines with matplotlib.8283## Anti-Leakage Rules8485- Split reference/train, validation, and test by time before scaling, dimensionality reduction, encoders, thresholds, or detector choice.86- Build `x_ref` only from pre-change or training history available at deployment time.87- Do not tune `ert`, `window_size(s)`, `p_val`, kernels, preprocessing, or `n_bootstraps` on final test labels.88- If using rolling offline tests, each test window must only compare past reference/history to current/future window allowed at that decision time.89- Do not let `update_x_ref` absorb validation/test future data unless that is the explicit production policy.90- For learned preprocessing, train encoders/classifiers on training data only.9192## Common Errors9394- Presenting Alibi Detect as a native changepoint segmentation library.95- Passing a batch to online `predict`; online detectors expect one instance at a time.96- Forgetting that `CVMDriftOnline` and `FETDriftOnline` need full windows before useful statistics exist.97- Using `FETDriftOnline` on non-binary data.98- Setting `n_bootstraps` far below the requested `ert`, making thresholds noisy.99- Losing timestamps after converting to arrays and then misreporting alarm times.100- Globally scaling or embedding all data before the time split.101102## References103104- Read `references/alibi-detect-data-workflow.md` for array shapes, windows, panels, labels, and leakage.105- Read `references/alibi-detect-api-map.md` for detector families, parameters, outputs, and limitations.106- Read `references/official-sources.md` for official sources consulted.107- Use `scripts/validate_alibi_detect_changepoints.py` to sanity-check CSV inputs and online detector settings.108109## Ready Checklist110111- Task is framed as drift/change alarm detection, not offline optimal segmentation.112- `x_ref` is stable, chronological, and leakage-free.113- Detector, backend, ERT, window sizes, preprocessing, and binary/continuous assumptions match the data.114- Alarm timestamps are mapped back to the original time index.115- Evaluation uses temporal labels/tolerance windows and reports detection delay plus false alarms.