FalseAlarmRate
FalseAlarmRate
- FalseAlarmRate(min_offset=0, max_offset=0, time_unit='hour')[source]
False alarm rate, number of alarms that hit no event, per unit of time.
A true event at time
Tcounts as hit by an alarm that falls in the window[T + min_offset, T + max_offset]. An alarm that falls in no event window is a false alarm. Further alarms inside a window that is already hit are not false alarms.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.
The score is the number of false alarms, divided by the scored duration. The scored duration is the span of
X.index, last value minus first value, soXshould hold only the part of the stream that is scored.This metric counts unmatched alarms only. With
min_offset=0andmax_offset=0, the window is the event time itself, so an alarm is unmatched unless it lands exactly on an event. The default is therefore close to the number of alarms divided by the length ofX, but an alarm that lands exactly on an event is not a false alarm.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 duration is counted intime_unit, by default hours. Otherwise all values are in the units ofX.index, andtime_unitis ignored.With no true events the score is still defined, as every alarm is a false alarm. With no alarms the score is 0, as long as
Xhas a span. IfXhas no span, that is fewer than two time points, the rate is not defined, andnanis returned, even if there are no alarms.Only point events are scored, so interval
ilocs(segments) iny_trueory_predraise aValueError.- 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, with the default of 0, alarms after the event are false alarms. Same unit asmin_offset. NaN raises aValueError.- time_unitstr, default=”hour”
Unit in which the duration is counted, if
Xhas a time index, so the score is false alarms pertime_unit. Any unit accepted bypd.Timedelta, for instance"hour","min", or"s". Ignored ifXdoes not have a time index.
Examples
>>> import pandas as pd >>> from sktime.performance_metrics.detection import FalseAlarmRate >>> index = pd.date_range("2020-01-01", periods=7, freq="20min") >>> X = pd.DataFrame({"foo": range(7)}, index=index) >>> y_true = pd.DataFrame({"ilocs": [5]}) >>> y_pred = pd.DataFrame({"ilocs": [1, 4]}) >>> metric = FalseAlarmRate(min_offset=pd.Timedelta("-20min")) >>> metric(y_true, y_pred, X) 0.5

