Result Types#
OfflineChangePointResult#
Returned by all offline detectors. Contains detected breakpoints, optional scores and segment statistics, and rich diagnostics.
Properties#
Property |
Type |
Description |
|---|---|---|
|
|
Breakpoint indices (strictly increasing, final element = n) |
|
|
Change point indices (breakpoints excluding the terminal n) |
|
|
Per-change-point scores (length = len(change_points), if available) |
|
|
Per-segment statistics (length = len(breakpoints)) |
|
|
Rich diagnostics metadata |
Methods#
to_json() -> str#
Serialize the result to a JSON string following the versioned contract.
Current writer version: schema marker
1Unknown fields are preserved during round-trip
Optional build provenance is surfaced under
diagnostics.buildwhen available
from_json(payload: str) -> OfflineChangePointResult (static)#
Deserialize a result from a JSON string.
Accepts schema markers in the supported window (currently
1..=2)Raises:
ValueErroron unsupported schema version or structural validation failure
plot(values=None, *, ax=None, title=None, breakpoint_color="crimson", breakpoint_style="--", line_width=1.5, show_legend=True) -> Any#
Plot the signal with detected breakpoints overlaid.
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
Signal values. Required if |
|
|
|
Axes to plot on. Creates new figure if |
|
|
|
Plot title |
|
|
|
Color for breakpoint lines |
|
|
|
Line style for breakpoints |
|
|
|
Line width |
|
|
|
Whether to show legend |
Returns: matplotlib Figure
Raises:
ImportErrorif matplotlib is not installed
Note
plot(ax=...) is supported only for univariate data (diagnostics.d == 1).
Example#
result = cpd.Pelt(model="l2").fit(x).predict(n_bkps=2)
# Inspect results
print(result.breakpoints) # [50, 100, 150]
print(result.change_points) # [50, 100]
# Serialize round-trip
payload = result.to_json()
restored = cpd.OfflineChangePointResult.from_json(payload)
assert restored.breakpoints == result.breakpoints
# Plot
fig = result.plot(x, title="Detected breakpoints")
OnlineStepResult#
Emitted by online detectors for each processed observation.
Properties#
Property |
Type |
Description |
|---|---|---|
|
|
Time index (0-based observation count) |
|
|
Posterior probability of a change at this step |
|
|
Whether the alert policy fired |
|
|
Reason the alert fired (e.g. |
|
|
Mode of the run-length posterior |
|
|
Mean of the run-length posterior |
|
|
Processing latency in microseconds (if measured) |
Example#
bocpd = cpd.Bocpd(model="gaussian_nig", hazard=1/200)
step = bocpd.update(3.5)
print(step.t) # 0
print(step.p_change) # 0.005 (low for first observation)
print(step.alert) # False