Precision and recall (precision_recall
)#
Description#
The precision and recall of an estimated segmentation is computed by the function precision_recall
as follows.
A true change point is declared "detected" (or positive) if there is at least one computed change point at less than "margin" points from it.
Formally, assume a set of change point indexes \(t_1,t_2,\dots\) and their estimates \(\hat{t}_1, \hat{t}_2,\dots\)
In the context of change point detection, precision and recall are defined as follows:
where, for a given margin \(M\), true positives \(\text{TP}\) are true change points for which there is an estimated one at less than \(M\) samples, i.e.
Usage#
Start with the usual imports and create two change point sets to compare.
from ruptures.metrics import precision_recall
bkps1, bkps2 = [100, 200, 500], [105, 115, 350, 400, 500]
p, r = precision_recall(bkps1, bkps2)
print((p, r))
The margin parameter \(M\) can be changed through the keyword margin
(default is 10 samples).
p, r = precision_recall(bkps1, bkps2, margin=10)
print((p, r))
p, r = precision_recall(bkps1, bkps2, margin=20)
print((p, r))