OnlineF1Score#

class OnlineF1Score(*, max_delay)[source]#

F1 under a detection deadline, with delay and false-alarm diagnostics.

For a true change c_i, the first event with detection time tau in [c_i, min(c_i + max_delay, c_{i+1})) is a true positive. The last change has no next-change bound. Every other event is a false positive, including alarms before the first change, after a deadline, or following an already matched event in the same interval. Unmatched changes are false negatives. Events sharing a detection time retain their log order.

Parameters:

max_delay (int) – Positive detection deadline in points. The upper bound is excluded: max_delay=1 only accepts an alarm emitted at the true change. Choose this deadline for the application; there is no default.

Notes

Matching uses detection time alone. The estimated position determines localization error, and the event’s score is ignored (including NaN). All timestamps are zero-based indices, as in BaseOnlineSegmenter. Delay is measured from the true change, not the estimated position.

If both truth and events are empty, F1, precision and recall are 1. If just one is empty, all three are 0, as for F1Score. Delay and localization summaries are NaN whenever there is no true positive.

Examples

>>> from tsseg.algorithms.base_online import make_events
>>> events = make_events([9, 19, 29], [12, 23, 36])
>>> result = OnlineF1Score(max_delay=5)(
...     [10, 20, 30], events, n_timepoints=100
... )
>>> result["score"]
0.6666666666666666
>>> result["mean_delay"], result["false_alarms_per_10000"]
(2.5, 100.0)
__init__(*, max_delay)[source]#

Initializes the metric with optional parameters.

Methods

__init__(*, max_delay)

Initializes the metric with optional parameters.

compute(y_true, y_pred, *, n_timepoints)

Score true change points against a complete online event log.