changepoint_precision#

changepoint_precision(changepoints_true: ArrayLike, changepoints_pred: ArrayLike, *, tolerance: int = 5) float[source][source]#

Compute detection precision for changepoints with a tolerance window.

The fraction of predicted changepoints that match a true changepoint within tolerance samples (greedy matching). Higher is better.

Returns 1.0 when there are no predicted changepoints (no false alarms).

Parameters:
changepoints_truearray-like of shape (n_changepoints_true,)

True changepoint indices, as returned by predict_changepoints().

changepoints_predarray-like of shape (n_changepoints_pred,)

Predicted changepoint indices, as returned by predict_changepoints().

toleranceint, default=5

Maximum sample distance for a match to count as correct.

Returns:
float

Precision in [0, 1].

Examples

>>> changepoint_precision([10, 20], [12, 20], tolerance=5)
1.0