MeanDetectionOffset
MeanDetectionOffset
- MeanDetectionOffset(min_offset=0, max_offset=0, time_unit='s')[source]
Mean detection offset, how far the earliest alarm is from each event.
A true event at time
Tcounts as hit if at least one alarm falls in the window[T + min_offset, T + max_offset]. For each hit event, the detection offset is the time of the earliest alarm in its window, minusT. The score is the mean detection offset over hit events only.The offset is signed in the same way as the window: it is negative for an alarm before the event, and positive for a late hit, which can only happen if
max_offsetis above 0. An earlier alarm gives a smaller score, so lower is better.The offsets are signed, negative is before the event and positive is after it. With offsets in the units of
X.index, for an event atT:min_offset=0, max_offset=0: only an alarm exactly atT.min_offset=-3, max_offset=0: advance only, an alarm from 3 beforeTup toT. Late alarms do not count.min_offset=0, max_offset=2: late only, an alarm fromTup to 2 afterT. Early alarms do not count.min_offset=-3, max_offset=2: before and after, an alarm from 3 beforeTup to 2 afterT.min_offset=-10, max_offset=-2: at least 2 beforeT, and not earlier than 10 beforeT. An alarm atTdoes not count.
Missed events do not enter the mean. Read this score together with
EventTPR, which reports how many events were hit at all.Positions in
y_trueandy_predareilocreferences intoX, and are mapped throughX.indexbefore matching, soXis required. IfXhas a time index, the offsets are time offsets, for instancepd.Timedelta("-3s"), and the score is returned as a number oftime_unit. Otherwise all values are in the units ofX.index.Only point events are scored, so interval
ilocs(segments) iny_trueory_predraise aValueError.If there are no true events, or no event is hit, the score is not defined, and
nanis returned.- Parameters:
- min_offsetint, float, or time offset, default=0
Start of the hit window, relative to the event time
T. Negative values let alarms before the event count. A time offset, for instancepd.Timedelta("-3s"), ifXhas a time index, otherwise a number in the units ofX.index. AValueErroris raised if it is NaN, or aftermax_offset.- max_offsetint, float, or time offset, default=0
End of the hit window, relative to the event time
T. Positive values let alarms after the event count, the default of 0 means that alarms after the event do not count. Same unit asmin_offset. NaN raises aValueError.- time_unitstr, default=āsā
Unit of the returned score, if
Xhas a time index. Any unit accepted bypd.Timedelta, for instance"s","ms","min", or"h". Ignored ifXdoes not have a time index.
Examples
>>> import pandas as pd >>> from sktime.performance_metrics.detection import MeanDetectionOffset >>> index = pd.date_range("2020-01-01", periods=20, freq="s") >>> X = pd.DataFrame({"foo": range(20)}, index=index) >>> y_true = pd.DataFrame({"ilocs": [5, 15]}) >>> y_pred = pd.DataFrame({"ilocs": [2, 14]}) >>> metric = MeanDetectionOffset(min_offset=pd.Timedelta("-3s")) >>> metric(y_true, y_pred, X) -2.0

