tsadmetrics 0.1.11__py3-none-any.whl → 0.1.13__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tsadmetrics/binary_metrics.py +371 -219
- tsadmetrics/non_binary_metrics.py +51 -24
- tsadmetrics/utils.py +13 -7
- {tsadmetrics-0.1.11.dist-info → tsadmetrics-0.1.13.dist-info}/METADATA +1 -1
- {tsadmetrics-0.1.11.dist-info → tsadmetrics-0.1.13.dist-info}/RECORD +7 -7
- {tsadmetrics-0.1.11.dist-info → tsadmetrics-0.1.13.dist-info}/WHEEL +0 -0
- {tsadmetrics-0.1.11.dist-info → tsadmetrics-0.1.13.dist-info}/top_level.txt +0 -0
tsadmetrics/binary_metrics.py
CHANGED
@@ -11,14 +11,17 @@ def point_wise_recall(y_true: np.array, y_pred: np.array):
|
|
11
11
|
Calculate point-wise recall for anomaly detection in time series.
|
12
12
|
Esta métrica consiste en el recall clásico, sin tener en cuenta el contexto
|
13
13
|
temporal.
|
14
|
+
|
14
15
|
Implementation of https://link.springer.com/article/10.1007/s10618-023-00988-8
|
15
16
|
|
16
17
|
Parameters:
|
17
|
-
|
18
|
-
|
18
|
+
y_true (np.array):
|
19
|
+
The ground truth binary labels for the time series data.
|
20
|
+
y_pred (np.array):
|
21
|
+
The predicted binary labels for the time series data.
|
19
22
|
|
20
23
|
Returns:
|
21
|
-
|
24
|
+
float: The point-wise recall score, which is the ratio of true positives to the sum of true positives and false negatives.
|
22
25
|
"""
|
23
26
|
m = Pointwise_metrics(len(y_true),y_true,y_pred)
|
24
27
|
m.set_confusion()
|
@@ -32,14 +35,17 @@ def point_wise_precision(y_true: np.array, y_pred: np.array):
|
|
32
35
|
Calculate point-wise precision for anomaly detection in time series.
|
33
36
|
Esta métrica consiste en la precisión clásica, sin tener en cuenta el contexto
|
34
37
|
temporal.
|
38
|
+
|
35
39
|
Implementation of https://link.springer.com/article/10.1007/s10618-023-00988-8
|
36
40
|
|
37
41
|
Parameters:
|
38
|
-
|
39
|
-
|
42
|
+
y_true (np.array):
|
43
|
+
The ground truth binary labels for the time series data.
|
44
|
+
y_pred (np.array):
|
45
|
+
The predicted binary labels for the time series data.
|
40
46
|
|
41
47
|
Returns:
|
42
|
-
|
48
|
+
float: The point-wise precision score, which is the ratio of true positives to the sum of true positives and false positives.
|
43
49
|
"""
|
44
50
|
m = Pointwise_metrics(len(y_true),y_true,y_pred)
|
45
51
|
m.set_confusion()
|
@@ -53,16 +59,20 @@ def point_wise_f_score(y_true: np.array, y_pred: np.array, beta=1):
|
|
53
59
|
Calculate point-wise F-score for anomaly detection in time series.
|
54
60
|
Esta métrica consiste en la F-score clásica, sin tener en cuenta el contexto
|
55
61
|
temporal.
|
62
|
+
|
56
63
|
Implementation of https://link.springer.com/article/10.1007/s10618-023-00988-8
|
57
64
|
|
58
65
|
Parameters:
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
66
|
+
y_true (np.array):
|
67
|
+
The ground truth binary labels for the time series data.
|
68
|
+
y_pred (np.array):
|
69
|
+
The predicted binary labels for the time series data.
|
70
|
+
beta (float):
|
71
|
+
The beta value, which determines the weight of precision in the combined score.
|
72
|
+
Default is 1, which gives equal weight to precision and recall.
|
63
73
|
|
64
74
|
Returns:
|
65
|
-
|
75
|
+
float: The point-wise F-score, which is the harmonic mean of precision and recall, adjusted by the beta value.
|
66
76
|
"""
|
67
77
|
precision = point_wise_precision(y_true, y_pred)
|
68
78
|
recall = point_wise_recall(y_true, y_pred)
|
@@ -84,11 +94,13 @@ def point_adjusted_recall(y_true: np.array, y_pred: np.array):
|
|
84
94
|
Implementation of https://link.springer.com/article/10.1007/s10618-023-00988-8
|
85
95
|
|
86
96
|
Parameters:
|
87
|
-
|
88
|
-
|
97
|
+
y_true (np.array):
|
98
|
+
The ground truth binary labels for the time series data.
|
99
|
+
y_pred (np.array):
|
100
|
+
The predicted binary labels for the time series data.
|
89
101
|
|
90
102
|
Returns:
|
91
|
-
|
103
|
+
float: The point-adjusted recall score, which is the ratio of true positives to the sum of true positives and false negatives.
|
92
104
|
"""
|
93
105
|
if np.sum(y_pred) == 0:
|
94
106
|
return 0
|
@@ -106,14 +118,17 @@ def point_adjusted_precision(y_true: np.array, y_pred: np.array):
|
|
106
118
|
if at least one point within that segment is predicted as anomalous, all points in the segment
|
107
119
|
are marked as correctly detected. The adjusted predictions are then compared to the ground-truth
|
108
120
|
labels using the standard point-wise precision formulation.
|
121
|
+
|
109
122
|
Implementation of https://link.springer.com/article/10.1007/s10618-023-00988-8
|
110
123
|
|
111
124
|
Parameters:
|
112
|
-
|
113
|
-
|
125
|
+
y_true (np.array):
|
126
|
+
The ground truth binary labels for the time series data.
|
127
|
+
y_pred (np.array):
|
128
|
+
The predicted binary labels for the time series data.
|
114
129
|
|
115
130
|
Returns:
|
116
|
-
|
131
|
+
float: The point-adjusted precision score, which is the ratio of true positives to the sum of true positives and false positives.
|
117
132
|
"""
|
118
133
|
if np.sum(y_pred) == 0:
|
119
134
|
return 0
|
@@ -134,13 +149,16 @@ def point_adjusted_f_score(y_true: np.array, y_pred: np.array, beta=1):
|
|
134
149
|
Implementation of https://link.springer.com/article/10.1007/s10618-023-00988-8
|
135
150
|
|
136
151
|
Parameters:
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
152
|
+
y_true (np.array):
|
153
|
+
The ground truth binary labels for the time series data.
|
154
|
+
y_pred (np.array):
|
155
|
+
The predicted binary labels for the time series data.
|
156
|
+
beta (float):
|
157
|
+
The beta value, which determines the weight of precision in the combined score.
|
158
|
+
Default is 1, which gives equal weight to precision and recall.
|
141
159
|
|
142
160
|
Returns:
|
143
|
-
|
161
|
+
float: The point-adjusted F-score, which is the harmonic mean of precision and recall, adjusted by the beta value.
|
144
162
|
"""
|
145
163
|
precision = point_adjusted_precision(y_true, y_pred)
|
146
164
|
recall = point_adjusted_recall(y_true, y_pred)
|
@@ -160,15 +178,20 @@ def delay_th_point_adjusted_recall(y_true: np.array, y_pred: np.array, k: int):
|
|
160
178
|
if at least one point within the first k time steps of the segment is predicted as anomalous,
|
161
179
|
all points in the segment are marked as correctly detected. The adjusted predictions are then
|
162
180
|
used to compute the standard point-wise recall formulation.
|
181
|
+
|
163
182
|
Implementation of https://link.springer.com/article/10.1007/s10618-023-00988-8
|
164
183
|
|
165
184
|
Parameters:
|
166
|
-
|
167
|
-
|
168
|
-
|
185
|
+
y_true (np.array):
|
186
|
+
The ground truth binary labels for the time series data.
|
187
|
+
y_pred (np.array):
|
188
|
+
The predicted binary labels for the time series data.
|
189
|
+
k (int):
|
190
|
+
Maximum number of time steps from the start of an anomaly segment within which a
|
191
|
+
prediction must occur for the segment to be considered detected.
|
169
192
|
|
170
193
|
Returns:
|
171
|
-
|
194
|
+
float: The delay thresholded point-adjusted recall score, which is the ratio of true positives to the sum of true positives and false negatives.
|
172
195
|
"""
|
173
196
|
if np.sum(y_pred) == 0:
|
174
197
|
return 0
|
@@ -186,15 +209,20 @@ def delay_th_point_adjusted_precision(y_true: np.array, y_pred: np.array, k: int
|
|
186
209
|
if at least one point within the first k time steps of the segment is predicted as anomalous,
|
187
210
|
all points in the segment are marked as correctly detected. The adjusted predictions are then
|
188
211
|
used to compute the standard point-wise precision fromulation.
|
212
|
+
|
189
213
|
Implementation of https://link.springer.com/article/10.1007/s10618-023-00988-8
|
190
214
|
|
191
215
|
Parameters:
|
192
|
-
|
193
|
-
|
194
|
-
|
216
|
+
y_true (np.array):
|
217
|
+
The ground truth binary labels for the time series data.
|
218
|
+
y_pred (np.array):
|
219
|
+
The predicted binary labels for the time series data.
|
220
|
+
k (int):
|
221
|
+
Maximum number of time steps from the start of an anomaly segment
|
222
|
+
within which a prediction must occur for the segment to be considered detected.
|
195
223
|
|
196
224
|
Returns:
|
197
|
-
|
225
|
+
float: The delay thresholded point-adjusted precision score, which is the ratio of true positives to the sum of true positives and false positives.
|
198
226
|
"""
|
199
227
|
if np.sum(y_pred) == 0:
|
200
228
|
return 0
|
@@ -216,14 +244,18 @@ def delay_th_point_adjusted_f_score(y_true: np.array, y_pred: np.array, k: int,
|
|
216
244
|
Implementation of https://link.springer.com/article/10.1007/s10618-023-00988-8
|
217
245
|
|
218
246
|
Parameters:
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
247
|
+
y_true (np.array):
|
248
|
+
The ground truth binary labels for the time series data.
|
249
|
+
y_pred (np.array):
|
250
|
+
The predicted binary labels for the time series data.
|
251
|
+
k (int):
|
252
|
+
Maximum number of time steps from the start of an anomaly segment within which a prediction must occur for the segment to be considered detected.
|
253
|
+
beta (float):
|
254
|
+
The beta value, which determines the weight of precision in the combined score.
|
255
|
+
Default is 1, which gives equal weight to precision and recall.
|
224
256
|
|
225
257
|
Returns:
|
226
|
-
|
258
|
+
float: The delay thresholded point-adjusted F-score, which is the harmonic mean of precision and recall, adjusted by the beta value.
|
227
259
|
"""
|
228
260
|
precision = delay_th_point_adjusted_precision(y_true, y_pred, k)
|
229
261
|
recall = delay_th_point_adjusted_recall(y_true, y_pred, k)
|
@@ -243,17 +275,20 @@ def point_adjusted_at_k_recall(y_true: np.array, y_pred: np.array, k: float):
|
|
243
275
|
the segment are marked as correctly detected. Otherwise, the entire segment is treated as
|
244
276
|
missed, even if some points were correctly predicted. The adjusted predictions are then used
|
245
277
|
to compute the standard point-wise recall.
|
278
|
+
|
246
279
|
Implementation of https://link.springer.com/article/10.1007/s10618-023-00988-8
|
247
280
|
|
248
281
|
Parameters:
|
249
|
-
|
250
|
-
|
251
|
-
|
282
|
+
y_true (np.array):
|
283
|
+
The ground truth binary labels for the time series data.
|
284
|
+
y_pred (np.array):
|
285
|
+
The predicted binary labels for the time series data.
|
286
|
+
k (float):
|
287
|
+
The minimum percentage of the anomaly that must be detected to consider the anomaly as detected.
|
252
288
|
|
253
289
|
Returns:
|
254
|
-
|
290
|
+
float: The point-adjusted recall score, which is the ratio of true positives to the sum of true positives and false negatives.
|
255
291
|
"""
|
256
|
-
#TP, _, FP, FN = get_tp_tn_fp_fn_point_adjusted_at_k(y_true, y_pred, k)
|
257
292
|
m = PointAdjustKPercent(len(y_true),y_true,y_pred,k=k)
|
258
293
|
TP,FN = m.tp,m.fn
|
259
294
|
if TP == 0:
|
@@ -272,12 +307,15 @@ def point_adjusted_at_k_precision(y_true: np.array, y_pred: np.array, k: float):
|
|
272
307
|
Implementation of https://link.springer.com/article/10.1007/s10618-023-00988-8
|
273
308
|
|
274
309
|
Parameters:
|
275
|
-
|
276
|
-
|
277
|
-
|
310
|
+
y_true (np.array):
|
311
|
+
The ground truth binary labels for the time series data.
|
312
|
+
y_pred (np.array):
|
313
|
+
The predicted binary labels for the time series data.
|
314
|
+
k (float):
|
315
|
+
The minimum percentage of the anomaly that must be detected to consider the anomaly as detected.
|
278
316
|
|
279
317
|
Returns:
|
280
|
-
|
318
|
+
float: The point-adjusted precision score, which is the ratio of true positives to the sum of true positives and false positives.
|
281
319
|
"""
|
282
320
|
m = PointAdjustKPercent(len(y_true),y_true,y_pred,k=k)
|
283
321
|
TP,FP = m.tp,m.fp
|
@@ -294,17 +332,22 @@ def point_adjusted_at_k_f_score(y_true: np.array, y_pred: np.array, k: float, be
|
|
294
332
|
the segment are marked as correctly detected. Otherwise, the entire segment is treated as
|
295
333
|
missed, even if some points were correctly predicted. The adjusted predictions are then used
|
296
334
|
to compute the standard F-Score precision.
|
335
|
+
|
297
336
|
Implementation of https://link.springer.com/article/10.1007/s10618-023-00988-8
|
298
337
|
|
299
338
|
Parameters:
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
339
|
+
y_true (np.array):
|
340
|
+
The ground truth binary labels for the time series data.
|
341
|
+
y_pred (np.array):
|
342
|
+
The predicted binary labels for the time series data.
|
343
|
+
k (float):
|
344
|
+
The minimum percentage of the anomaly that must be detected to consider the anomaly as detected.
|
345
|
+
beta (float):
|
346
|
+
The beta value, which determines the weight of precision in the combined score.
|
347
|
+
Default is 1, which gives equal weight to precision and recall.
|
305
348
|
|
306
349
|
Returns:
|
307
|
-
|
350
|
+
float: The point-adjusted F-score, which is the harmonic mean of precision and recall, adjusted by the beta value.
|
308
351
|
"""
|
309
352
|
precision = point_adjusted_at_k_precision(y_true, y_pred, k)
|
310
353
|
recall = point_adjusted_at_k_recall(y_true, y_pred, k)
|
@@ -326,15 +369,19 @@ def latency_sparsity_aw_recall(y_true: np.array, y_pred: np.array, ni: int):
|
|
326
369
|
scattered false positives, predictions are subsampled using a sparsity factor n, so that
|
327
370
|
only one prediction is considered every n time steps. The adjusted predictions are then used
|
328
371
|
to compute the standard point-wise recall.
|
372
|
+
|
329
373
|
Implementation of https://dl.acm.org/doi/10.1145/3447548.3467174
|
330
374
|
|
331
375
|
Parameters:
|
332
|
-
|
333
|
-
|
334
|
-
|
376
|
+
y_true (np.array):
|
377
|
+
The ground truth binary labels for the time series data.
|
378
|
+
y_pred (np.array):
|
379
|
+
The predicted binary labels for the time series data.
|
380
|
+
ni (int):
|
381
|
+
The batch size used in the implementation to handle latency and sparsity.
|
335
382
|
|
336
383
|
Returns:
|
337
|
-
|
384
|
+
float: The latency and sparsity aware recall score, which is the ratio of true positives to the sum of true positives and false negatives.
|
338
385
|
"""
|
339
386
|
if np.sum(y_pred) == 0:
|
340
387
|
return 0
|
@@ -358,12 +405,15 @@ def latency_sparsity_aw_precision(y_true: np.array, y_pred: np.array, ni: int):
|
|
358
405
|
Implementation of https://dl.acm.org/doi/10.1145/3447548.3467174
|
359
406
|
|
360
407
|
Parameters:
|
361
|
-
|
362
|
-
|
363
|
-
|
408
|
+
y_true (np.array):
|
409
|
+
The ground truth binary labels for the time series data.
|
410
|
+
y_pred (np.array):
|
411
|
+
The predicted binary labels for the time series data.
|
412
|
+
ni (int):
|
413
|
+
The batch size used in the implementation to handle latency and sparsity.
|
364
414
|
|
365
415
|
Returns:
|
366
|
-
|
416
|
+
float: The latency and sparsity aware precision score, which is the ratio of true positives to the sum of true positives and false positives.
|
367
417
|
"""
|
368
418
|
if np.sum(y_pred) == 0:
|
369
419
|
return 0
|
@@ -388,14 +438,18 @@ def latency_sparsity_aw_f_score(y_true: np.array, y_pred: np.array, ni: int, bet
|
|
388
438
|
Implementation of https://dl.acm.org/doi/10.1145/3447548.3467174
|
389
439
|
|
390
440
|
Parameters:
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
441
|
+
y_true (np.array):
|
442
|
+
The ground truth binary labels for the time series data.
|
443
|
+
y_pred (np.array):
|
444
|
+
The predicted binary labels for the time series data.
|
445
|
+
ni (int):
|
446
|
+
The batch size used in the implementation to handle latency and sparsity.
|
447
|
+
beta (float):
|
448
|
+
The beta value, which determines the weight of precision in the combined score.
|
449
|
+
Default is 1, which gives equal weight to precision and recall.
|
396
450
|
|
397
451
|
Returns:
|
398
|
-
|
452
|
+
float: The latency and sparsity aware F-score, which is the harmonic mean of precision and recall, adjusted by the beta value.
|
399
453
|
"""
|
400
454
|
if np.sum(y_pred) == 0:
|
401
455
|
return 0
|
@@ -421,11 +475,13 @@ def segment_wise_recall(y_true: np.array, y_pred: np.array):
|
|
421
475
|
Implementation of https://arxiv.org/pdf/1802.04431
|
422
476
|
|
423
477
|
Parameters:
|
424
|
-
|
425
|
-
|
478
|
+
y_true (np.array):
|
479
|
+
The ground truth binary labels for the time series data.
|
480
|
+
y_pred (np.array):
|
481
|
+
The predicted binary labels for the time series data.
|
426
482
|
|
427
483
|
Returns:
|
428
|
-
|
484
|
+
float: The segment-wise recall score, which is the ratio of true positives to the sum of true positives and false negatives.
|
429
485
|
"""
|
430
486
|
m = Segmentwise_metrics(len(y_true),y_true,y_pred)
|
431
487
|
TP,FN = m.tp,m.fn
|
@@ -443,14 +499,17 @@ def segment_wise_precision(y_true: np.array, y_pred: np.array):
|
|
443
499
|
is detected, and a false positive is recorded for each predicted anomalous segment that does not
|
444
500
|
overlap with any ground-truth anomaly. The final precision is computed using these adjusted
|
445
501
|
segment-level counts.
|
502
|
+
|
446
503
|
Implementation of https://arxiv.org/pdf/1802.04431
|
447
504
|
|
448
505
|
Parameters:
|
449
|
-
|
450
|
-
|
506
|
+
y_true (np.array):
|
507
|
+
The ground truth binary labels for the time series data.
|
508
|
+
y_pred (np.array):
|
509
|
+
The predicted binary labels for the time series data.
|
451
510
|
|
452
511
|
Returns:
|
453
|
-
|
512
|
+
float: The segment-wise precision score, which is the ratio of true positives to the sum of true positives and false positives.
|
454
513
|
"""
|
455
514
|
m = Segmentwise_metrics(len(y_true),y_true,y_pred)
|
456
515
|
TP,FP = m.tp,m.fp
|
@@ -468,16 +527,20 @@ def segment_wise_f_score(y_true: np.array, y_pred: np.array, beta=1):
|
|
468
527
|
is detected, and a false positive is recorded for each predicted anomalous segment that does not
|
469
528
|
overlap with any ground-truth anomaly. The final F-score is computed using these adjusted
|
470
529
|
segment-level counts.
|
530
|
+
|
471
531
|
Implementation of https://arxiv.org/pdf/1802.04431
|
472
532
|
|
473
533
|
Parameters:
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
534
|
+
y_true (np.array):
|
535
|
+
The ground truth binary labels for the time series data.
|
536
|
+
y_pred (np.array):
|
537
|
+
The predicted binary labels for the time series data.
|
538
|
+
beta (float):
|
539
|
+
The beta value, which determines the weight of precision in the combined score.
|
540
|
+
Default is 1, which gives equal weight to precision and recall.
|
478
541
|
|
479
542
|
Returns:
|
480
|
-
|
543
|
+
float: The segment-wise F-score, which is the harmonic mean of precision and recall, adjusted by the beta value.
|
481
544
|
|
482
545
|
"""
|
483
546
|
m = Segmentwise_metrics(len(y_true),y_true,y_pred)
|
@@ -503,13 +566,16 @@ def composite_f_score(y_true: np.array, y_pred: np.array, beta=1):
|
|
503
566
|
Implementation of https://ieeexplore.ieee.org/document/9525836
|
504
567
|
|
505
568
|
Parameters:
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
569
|
+
y_true (np.array):
|
570
|
+
The ground truth binary labels for the time series data.
|
571
|
+
y_pred (np.array):
|
572
|
+
The predicted binary labels for the time series data.
|
573
|
+
beta (float):
|
574
|
+
The beta value, which determines the weight of precision in the combined score.
|
575
|
+
Default is 1, which gives equal weight to precision and recall.
|
510
576
|
|
511
577
|
Returns:
|
512
|
-
|
578
|
+
float: The composite F-score, which is the harmonic mean of precision and recall, adjusted by the beta value.
|
513
579
|
|
514
580
|
"""
|
515
581
|
m = Composite_f(len(y_true),y_true,y_pred)
|
@@ -536,12 +602,15 @@ def time_tolerant_recall(y_true: np.array, y_pred: np.array, t: int) -> float:
|
|
536
602
|
Implementation of https://arxiv.org/pdf/1802.04431
|
537
603
|
|
538
604
|
Parameters:
|
539
|
-
|
540
|
-
|
541
|
-
|
605
|
+
y_true (np.array):
|
606
|
+
The ground truth binary labels for the time series data.
|
607
|
+
y_pred (np.array):
|
608
|
+
The predicted binary labels for the time series data.
|
609
|
+
t (int):
|
610
|
+
The time tolerance parameter
|
542
611
|
|
543
612
|
Returns:
|
544
|
-
|
613
|
+
float: The time tolerant recall score, which is the ratio of true positives to the sum of true positives and false negatives.
|
545
614
|
"""
|
546
615
|
if np.sum(y_pred) == 0:
|
547
616
|
return 0
|
@@ -561,12 +630,15 @@ def time_tolerant_precision(y_true: np.array, y_pred: np.array, t: int) -> float
|
|
561
630
|
Implementation of https://arxiv.org/pdf/1802.04431
|
562
631
|
|
563
632
|
Parameters:
|
564
|
-
|
565
|
-
|
566
|
-
|
633
|
+
y_true (np.array):
|
634
|
+
The ground truth binary labels for the time series data.
|
635
|
+
y_pred (np.array):
|
636
|
+
The predicted binary labels for the time series data.
|
637
|
+
t (int):
|
638
|
+
The time tolerance parameter
|
567
639
|
|
568
640
|
Returns:
|
569
|
-
|
641
|
+
float: The time tolerant precision score, which is the ratio of true positives to the sum of true positives and false positives.
|
570
642
|
"""
|
571
643
|
if np.sum(y_pred) == 0:
|
572
644
|
return 0
|
@@ -586,14 +658,18 @@ def time_tolerant_f_score(y_true: np.array, y_pred: np.array, t: int, beta=1):
|
|
586
658
|
Implementation of https://arxiv.org/pdf/1802.04431
|
587
659
|
|
588
660
|
Parameters:
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
661
|
+
y_true (np.array):
|
662
|
+
The ground truth binary labels for the time series data.
|
663
|
+
y_pred (np.array):
|
664
|
+
The predicted binary labels for the time series data.
|
665
|
+
t (int):
|
666
|
+
The time tolerance parameter
|
667
|
+
beta (float):
|
668
|
+
The beta value, which determines the weight of precision in the combined score.
|
669
|
+
Default is 1, which gives equal weight to precision and recall.
|
594
670
|
|
595
671
|
Returns:
|
596
|
-
|
672
|
+
float: The time tolerant F-score, which is the harmonic mean of precision and recall, adjusted by the beta value.
|
597
673
|
|
598
674
|
"""
|
599
675
|
precision = time_tolerant_precision(y_true,y_pred,t)
|
@@ -618,14 +694,19 @@ def range_based_recall(y_true: np.array, y_pred: np.array, alpha: float, bias='f
|
|
618
694
|
https://proceedings.neurips.cc/paper_files/paper/2018/file/8f468c873a32bb0619eaeb2050ba45d1-Paper.pdf
|
619
695
|
|
620
696
|
Parameters:
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
697
|
+
y_true (np.array):
|
698
|
+
The ground truth binary labels for the time series data.
|
699
|
+
y_pred (np.array):
|
700
|
+
The predicted binary labels for the time series data.
|
701
|
+
alpha (float):
|
702
|
+
Relative importance of existence reward. 0 ≤ alpha ≤ 1.
|
703
|
+
bias (str):
|
704
|
+
Positional bias. This should be "flat", "front", "middle", or "back".
|
705
|
+
cardinality_mode (str, optional):
|
706
|
+
Cardinality type. This should be "one", "reciprocal" or "udf_gamma".
|
626
707
|
|
627
708
|
Returns:
|
628
|
-
|
709
|
+
float: The range-based recall score.
|
629
710
|
"""
|
630
711
|
if np.sum(y_pred) == 0:
|
631
712
|
return 0
|
@@ -647,14 +728,19 @@ def range_based_precision(y_true: np.array, y_pred: np.array, alpha: float, bias
|
|
647
728
|
https://proceedings.neurips.cc/paper_files/paper/2018/file/8f468c873a32bb0619eaeb2050ba45d1-Paper.pdf
|
648
729
|
|
649
730
|
Parameters:
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
731
|
+
y_true (np.array):
|
732
|
+
The ground truth binary labels for the time series data.
|
733
|
+
y_pred (np.array):
|
734
|
+
The predicted binary labels for the time series data.
|
735
|
+
alpha (float):
|
736
|
+
Relative importance of existence reward. 0 ≤ alpha ≤ 1.
|
737
|
+
bias (str):
|
738
|
+
Positional bias. This should be "flat", "front", "middle", or "back".
|
739
|
+
cardinality_mode (str, optional):
|
740
|
+
Cardinality type. This should be "one", "reciprocal" or "udf_gamma".
|
655
741
|
|
656
742
|
Returns:
|
657
|
-
|
743
|
+
float: The range-based precision score.
|
658
744
|
"""
|
659
745
|
if np.sum(y_pred) == 0:
|
660
746
|
return 0
|
@@ -680,17 +766,24 @@ def range_based_f_score(y_true: np.array, y_pred: np.array, p_alpha: float, r_al
|
|
680
766
|
|
681
767
|
|
682
768
|
Parameters:
|
683
|
-
y_true (np.array):
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
769
|
+
y_true (np.array):
|
770
|
+
The ground truth binary labels for the time series data.
|
771
|
+
y_pred (np.array):
|
772
|
+
The predicted binary labels for the time series data.
|
773
|
+
alpha (float):
|
774
|
+
Relative importance of existence reward. 0 ≤ alpha ≤ 1.
|
775
|
+
p_bias (str):
|
776
|
+
Positional bias for precision. This should be "flat", "front", "middle", or "back".
|
777
|
+
r_bias (str):
|
778
|
+
Positional bias for recall. This should be "flat", "front", "middle", or "back".
|
779
|
+
cardinality_mode (str, optional):
|
780
|
+
Cardinality type. This should be "one", "reciprocal" or "udf_gamma".
|
781
|
+
beta (float):
|
782
|
+
The beta value, which determines the weight of precision in the combined score.
|
783
|
+
Default is 1, which gives equal weight to precision and recall.
|
691
784
|
|
692
785
|
Returns:
|
693
|
-
|
786
|
+
float: The range-based F-score, which is the harmonic mean of precision and recall, adjusted by the beta value.
|
694
787
|
"""
|
695
788
|
if np.sum(y_pred) == 0:
|
696
789
|
return 0
|
@@ -712,22 +805,28 @@ def ts_aware_recall(y_true: np.array, y_pred: np.array, alpha: float, delta: flo
|
|
712
805
|
focusing solely on overlap fraction and end‑tolerance decay.
|
713
806
|
|
714
807
|
Parameters:
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
808
|
+
y_true (np.array):
|
809
|
+
The ground truth binary labels for the time series data.
|
810
|
+
y_pred (np.array):
|
811
|
+
The predicted binary labels for the time series data.
|
812
|
+
alpha (float):
|
813
|
+
Relative importance of the existence reward versus overlap reward (0 ≤ α ≤ 1).
|
814
|
+
delta (float):
|
815
|
+
Tolerance window length at the end of each true anomaly segment.
|
816
|
+
- If past_range is True, δ must be a float in (0, 1], representing the fraction of the segment’s
|
817
|
+
length to extend. E.g., δ = 0.5 extends a segment of length 10 by 5 time steps.
|
818
|
+
- If past_range is False, δ must be a non-negative integer, representing an absolute number of
|
819
|
+
time steps to extend each segment.
|
820
|
+
theta (float):
|
821
|
+
Minimum fraction (0 ≤ θ ≤ 1) of the true anomaly range that must be overlapped by
|
822
|
+
predictions for the segment to count as detected.
|
823
|
+
past_range (bool):
|
824
|
+
Determines how δ is interpreted.
|
825
|
+
- True: δ is treated as a fractional extension of each segment’s length.
|
826
|
+
- False: δ is treated as an absolute number of time steps.
|
728
827
|
|
729
828
|
Returns:
|
730
|
-
|
829
|
+
float: The time series aware recall score.
|
731
830
|
"""
|
732
831
|
m = TaF(len(y_true),y_true,y_pred,alpha=alpha,theta=theta,delta=delta,past_range=past_range)
|
733
832
|
return m.recall()
|
@@ -747,22 +846,28 @@ def ts_aware_precision(y_true: np.array, y_pred: np.array,alpha: float, delta: f
|
|
747
846
|
focusing solely on overlap fraction and end‑tolerance decay.
|
748
847
|
|
749
848
|
Parameters:
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
849
|
+
y_true (np.array):
|
850
|
+
The ground truth binary labels for the time series data.
|
851
|
+
y_pred (np.array):
|
852
|
+
The predicted binary labels for the time series data.
|
853
|
+
alpha (float):
|
854
|
+
Relative importance of the existence reward versus overlap reward (0 ≤ α ≤ 1).
|
855
|
+
delta (float):
|
856
|
+
Tolerance window length at the end of each true anomaly segment.
|
857
|
+
- If past_range is True, δ must be a float in (0, 1], representing the fraction of the segment’s
|
858
|
+
length to extend. E.g., δ = 0.5 extends a segment of length 10 by 5 time steps.
|
859
|
+
- If past_range is False, δ must be a non-negative integer, representing an absolute number of
|
860
|
+
time steps to extend each segment.
|
861
|
+
theta (float):
|
862
|
+
Minimum fraction (0 ≤ θ ≤ 1) of the true anomaly range that must be overlapped by
|
863
|
+
predictions for the segment to count as detected.
|
864
|
+
past_range (bool):
|
865
|
+
Determines how δ is interpreted.
|
866
|
+
- True: δ is treated as a fractional extension of each segment’s length.
|
867
|
+
- False: δ is treated as an absolute number of time steps.
|
763
868
|
|
764
869
|
Returns:
|
765
|
-
|
870
|
+
float: The time series aware precision score.
|
766
871
|
"""
|
767
872
|
m = TaF(len(y_true),y_true,y_pred,alpha=alpha,theta=theta,delta=delta,past_range=past_range)
|
768
873
|
return m.precision()
|
@@ -783,22 +888,28 @@ def ts_aware_f_score(y_true: np.array, y_pred: np.array, beta: float, alpha: flo
|
|
783
888
|
focusing solely on overlap fraction and end‑tolerance decay.
|
784
889
|
|
785
890
|
Parameters:
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
891
|
+
y_true (np.array):
|
892
|
+
The ground truth binary labels for the time series data.
|
893
|
+
y_pred (np.array):
|
894
|
+
The predicted binary labels for the time series data.
|
895
|
+
alpha (float):
|
896
|
+
Relative importance of the existence reward versus overlap reward (0 ≤ α ≤ 1).
|
897
|
+
delta (float):
|
898
|
+
Tolerance window length at the end of each true anomaly segment.
|
899
|
+
- If past_range is True, δ must be a float in (0, 1], representing the fraction of the segment’s
|
900
|
+
length to extend. E.g., δ = 0.5 extends a segment of length 10 by 5 time steps.
|
901
|
+
- If past_range is False, δ must be a non-negative integer, representing an absolute number of
|
902
|
+
time steps to extend each segment.
|
903
|
+
theta (float):
|
904
|
+
Minimum fraction (0 ≤ θ ≤ 1) of the true anomaly range that must be overlapped by
|
905
|
+
predictions for the segment to count as detected.
|
906
|
+
past_range (bool):
|
907
|
+
Determines how δ is interpreted.
|
908
|
+
- True: δ is treated as a fractional extension of each segment’s length.
|
909
|
+
- False: δ is treated as an absolute number of time steps.
|
799
910
|
|
800
911
|
Returns:
|
801
|
-
|
912
|
+
float: The time series aware F-score, which is the harmonic mean of precision and recall, adjusted by the beta value.
|
802
913
|
"""
|
803
914
|
|
804
915
|
m = TaF(len(y_true),y_true,y_pred,alpha=alpha,theta=theta,delta=delta,past_range=past_range)
|
@@ -824,13 +935,16 @@ def enhanced_ts_aware_recall(y_true: np.array, y_pred: np.array, theta: float):
|
|
824
935
|
true segment’s length, providing a compromise between point-wise and segment-wise approaches.
|
825
936
|
|
826
937
|
Parameters:
|
827
|
-
|
828
|
-
|
829
|
-
|
938
|
+
y_true (np.array):
|
939
|
+
The ground truth binary labels for the time series data.
|
940
|
+
y_pred (np.array):
|
941
|
+
The predicted binary labels for the time series data.
|
942
|
+
theta (float):
|
943
|
+
Minimum fraction (0 ≤ θ ≤ 1) of a true segment that must be overlapped
|
830
944
|
by predictions to count as detected.
|
831
945
|
|
832
946
|
Returns:
|
833
|
-
|
947
|
+
float: The time series aware recall score.
|
834
948
|
"""
|
835
949
|
if np.sum(y_pred) == 0:
|
836
950
|
return 0
|
@@ -851,13 +965,16 @@ def enhanced_ts_aware_precision(y_true: np.array, y_pred: np.array, theta: float
|
|
851
965
|
true segment’s length, providing a compromise between point-wise and segment-wise approaches.
|
852
966
|
|
853
967
|
Parameters:
|
854
|
-
|
855
|
-
|
856
|
-
|
968
|
+
y_true (np.array):
|
969
|
+
The ground truth binary labels for the time series data.
|
970
|
+
y_pred (np.array):
|
971
|
+
The predicted binary labels for the time series data.
|
972
|
+
theta (float):
|
973
|
+
Minimum fraction (0 ≤ θ ≤ 1) of a true segment that must be overlapped
|
857
974
|
by predictions to count as detected.
|
858
975
|
|
859
976
|
Returns:
|
860
|
-
|
977
|
+
float: The time series aware precision score.
|
861
978
|
"""
|
862
979
|
if np.sum(y_pred) == 0:
|
863
980
|
return 0
|
@@ -879,13 +996,16 @@ def enhanced_ts_aware_f_score(y_true: np.array, y_pred: np.array, theta_p: float
|
|
879
996
|
true segment’s length, providing a compromise between point-wise and segment-wise approaches.
|
880
997
|
|
881
998
|
Parameters:
|
882
|
-
|
883
|
-
|
884
|
-
|
999
|
+
y_true (np.array):
|
1000
|
+
The ground truth binary labels for the time series data.
|
1001
|
+
y_pred (np.array):
|
1002
|
+
The predicted binary labels for the time series data.
|
1003
|
+
theta (float):
|
1004
|
+
Minimum fraction (0 ≤ θ ≤ 1) of a true segment that must be overlapped
|
885
1005
|
by predictions to count as detected.
|
886
1006
|
|
887
1007
|
Returns:
|
888
|
-
|
1008
|
+
float: The time series aware F-score, which is the harmonic mean of precision and recall, adjusted by the beta value.
|
889
1009
|
"""
|
890
1010
|
if np.sum(y_pred) == 0:
|
891
1011
|
return 0
|
@@ -903,11 +1023,13 @@ def affiliation_based_recall(y_true: np.array, y_pred: np.array):
|
|
903
1023
|
predicted anomaly point.
|
904
1024
|
|
905
1025
|
Parameters:
|
906
|
-
|
907
|
-
|
1026
|
+
y_true (np.array):
|
1027
|
+
The ground truth binary labels for the time series data.
|
1028
|
+
y_pred (np.array):
|
1029
|
+
The predicted binary labels for the time series data.
|
908
1030
|
|
909
1031
|
Returns:
|
910
|
-
|
1032
|
+
float: The affiliation based recall score.
|
911
1033
|
"""
|
912
1034
|
if np.sum(y_pred) == 0:
|
913
1035
|
return 0
|
@@ -925,12 +1047,14 @@ def affiliation_based_precision(y_true: np.array, y_pred: np.array):
|
|
925
1047
|
ground truth anomaly point.
|
926
1048
|
|
927
1049
|
Parameters:
|
928
|
-
|
929
|
-
|
1050
|
+
y_true (np.array):
|
1051
|
+
The ground truth binary labels for the time series data.
|
1052
|
+
y_pred (np.array):
|
1053
|
+
The predicted binary labels for the time series data.
|
930
1054
|
|
931
1055
|
|
932
1056
|
Returns:
|
933
|
-
|
1057
|
+
float: The affiliation based precision score.
|
934
1058
|
"""
|
935
1059
|
if np.sum(y_pred) == 0:
|
936
1060
|
return 0
|
@@ -950,13 +1074,16 @@ def affiliation_based_f_score(y_true: np.array, y_pred: np.array, beta=1):
|
|
950
1074
|
anomalies and vice versa.
|
951
1075
|
|
952
1076
|
Parameters:
|
953
|
-
|
954
|
-
|
955
|
-
|
1077
|
+
y_true (np.array):
|
1078
|
+
The ground truth binary labels for the time series data.
|
1079
|
+
y_pred (np.array):
|
1080
|
+
The predicted binary labels for the time series data.
|
1081
|
+
beta (float):
|
1082
|
+
The beta value, which determines the weight of precision in the combined score.
|
956
1083
|
|
957
1084
|
|
958
1085
|
Returns:
|
959
|
-
|
1086
|
+
float: The affiliation based F-score.
|
960
1087
|
"""
|
961
1088
|
if np.sum(y_pred) == 0:
|
962
1089
|
return 0
|
@@ -974,12 +1101,14 @@ def nab_score(y_true: np.array, y_pred: np.array):
|
|
974
1101
|
positive prediction contributes negatively.
|
975
1102
|
|
976
1103
|
Parameters:
|
977
|
-
|
978
|
-
|
1104
|
+
y_true (np.array):
|
1105
|
+
The ground truth binary labels for the time series data.
|
1106
|
+
y_pred (np.array):
|
1107
|
+
The predicted binary labels for the time series data.
|
979
1108
|
|
980
1109
|
|
981
1110
|
Returns:
|
982
|
-
|
1111
|
+
float: The nab score.
|
983
1112
|
"""
|
984
1113
|
|
985
1114
|
m = NAB_score(len(y_true),y_true,y_pred)
|
@@ -995,15 +1124,18 @@ def temporal_distance(y_true: np.array, y_pred: np.array, distance: int = 0):
|
|
995
1124
|
|
996
1125
|
|
997
1126
|
Parameters:
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1127
|
+
y_true (np.array):
|
1128
|
+
The ground truth binary labels for the time series data.
|
1129
|
+
y_pred (np.array):
|
1130
|
+
The predicted binary labels for the time series data.
|
1131
|
+
distance (int):
|
1132
|
+
The distance type parameter for the temporal distance calculation.
|
1133
|
+
0: Euclidean distance
|
1134
|
+
1: Squared Euclidean distance
|
1003
1135
|
|
1004
1136
|
|
1005
1137
|
Returns:
|
1006
|
-
|
1138
|
+
float: The temporal distance.
|
1007
1139
|
"""
|
1008
1140
|
|
1009
1141
|
m = Temporal_Distance(len(y_true),y_true,y_pred,distance=distance)
|
@@ -1021,12 +1153,14 @@ def average_detection_count(y_true: np.array, y_pred: np.array):
|
|
1021
1153
|
https://ceur-ws.org/Vol-1226/paper31.pdf
|
1022
1154
|
|
1023
1155
|
Parameters:
|
1024
|
-
|
1025
|
-
|
1156
|
+
y_true (np.array):
|
1157
|
+
The ground truth binary labels for the time series data.
|
1158
|
+
y_pred (np.array):
|
1159
|
+
The predicted binary labels for the time series data.
|
1026
1160
|
|
1027
1161
|
|
1028
1162
|
Returns:
|
1029
|
-
|
1163
|
+
float: The average detection count score.
|
1030
1164
|
"""
|
1031
1165
|
|
1032
1166
|
b = Binary_detection(len(y_true),y_true,y_pred)
|
@@ -1052,15 +1186,18 @@ def absolute_detection_distance(y_true: np.array, y_pred: np.array):
|
|
1052
1186
|
those distances and divides by the total number of such matching predicted points, yielding the
|
1053
1187
|
mean distance to segment centers for correctly detected points.
|
1054
1188
|
|
1055
|
-
Parameters:
|
1056
|
-
y_true (np.array): The ground truth binary labels for the time series data.
|
1057
|
-
y_pred (np.array): The predicted binary labels for the time series data.
|
1058
|
-
|
1059
1189
|
For more information, see the original paper:
|
1060
1190
|
https://ceur-ws.org/Vol-1226/paper31.pdf
|
1061
1191
|
|
1192
|
+
Parameters:
|
1193
|
+
y_true (np.array):
|
1194
|
+
The ground truth binary labels for the time series data.
|
1195
|
+
y_pred (np.array):
|
1196
|
+
The predicted binary labels for the time series data.
|
1197
|
+
|
1198
|
+
|
1062
1199
|
Returns:
|
1063
|
-
|
1200
|
+
float: The absolute detection distance.
|
1064
1201
|
"""
|
1065
1202
|
|
1066
1203
|
b = Binary_detection(len(y_true),y_true,y_pred)
|
@@ -1096,13 +1233,16 @@ def total_detected_in_range(y_true: np.array, y_pred: np.array, k: int):
|
|
1096
1233
|
https://acta.sapientia.ro/content/docs/evaluation-metrics-for-anomaly-detection.pdf
|
1097
1234
|
|
1098
1235
|
Parameters:
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1236
|
+
y_true (np.array):
|
1237
|
+
The ground truth binary labels for the time series data.
|
1238
|
+
y_pred (np.array):
|
1239
|
+
The predicted binary labels for the time series data.
|
1240
|
+
k (int):
|
1241
|
+
Half-window size for tolerance around each true anomaly point. A prediction within k
|
1242
|
+
time steps of a true point counts toward detection.
|
1103
1243
|
|
1104
1244
|
Returns:
|
1105
|
-
|
1245
|
+
float: The total detected in range score.
|
1106
1246
|
"""
|
1107
1247
|
if np.sum(y_pred) == 0:
|
1108
1248
|
return 0
|
@@ -1131,13 +1271,16 @@ def detection_accuracy_in_range(y_true: np.array, y_pred: np.array, k: int):
|
|
1131
1271
|
https://acta.sapientia.ro/content/docs/evaluation-metrics-for-anomaly-detection.pdf
|
1132
1272
|
|
1133
1273
|
Parameters:
|
1134
|
-
|
1135
|
-
|
1136
|
-
|
1137
|
-
|
1274
|
+
y_true (np.array):
|
1275
|
+
The ground truth binary labels for the time series data.
|
1276
|
+
y_pred (np.array):
|
1277
|
+
The predicted binary labels for the time series data.
|
1278
|
+
k (int):
|
1279
|
+
Half-window size for tolerance around each true anomaly point. A prediction within k
|
1280
|
+
time steps of a true point counts toward detection.
|
1138
1281
|
|
1139
1282
|
Returns:
|
1140
|
-
|
1283
|
+
float: The total detected in range.
|
1141
1284
|
"""
|
1142
1285
|
if np.sum(y_pred) == 0:
|
1143
1286
|
return 0
|
@@ -1174,12 +1317,15 @@ def weighted_detection_difference(y_true: np.array, y_pred: np.array, k: int):
|
|
1174
1317
|
https://acta.sapientia.ro/content/docs/evaluation-metrics-for-anomaly-detection.pdf
|
1175
1318
|
|
1176
1319
|
Parameters:
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1320
|
+
y_true (np.array):
|
1321
|
+
The ground truth binary labels for the time series data.
|
1322
|
+
y_pred (np.array):
|
1323
|
+
The predicted binary labels for the time series data.
|
1324
|
+
k (int):
|
1325
|
+
The maximum number of time steps within which an anomaly must be predicted to be considered detected.
|
1180
1326
|
|
1181
1327
|
Returns:
|
1182
|
-
|
1328
|
+
float: The weighted detection difference.
|
1183
1329
|
"""
|
1184
1330
|
if np.sum(y_pred) == 0:
|
1185
1331
|
return 0
|
@@ -1231,13 +1377,17 @@ def binary_pate(y_true: np.array, y_pred: np.array, early: int, delay: int):
|
|
1231
1377
|
https://arxiv.org/abs/2405.12096
|
1232
1378
|
|
1233
1379
|
Parameters:
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
|
1380
|
+
y_true (np.array):
|
1381
|
+
The ground truth binary labels for the time series data.
|
1382
|
+
y_pred (np.array):
|
1383
|
+
The predicted binary labels for the time series data.
|
1384
|
+
early (int):
|
1385
|
+
The maximum number of time steps before an anomaly must be predicted to be considered early.
|
1386
|
+
delay (int):
|
1387
|
+
The maximum number of time steps after an anomaly must be predicted to be considered delayed.
|
1238
1388
|
|
1239
1389
|
Returns:
|
1240
|
-
|
1390
|
+
float: The PATE score.
|
1241
1391
|
"""
|
1242
1392
|
|
1243
1393
|
return PATE(y_true, y_pred, early, delay, binary_scores=True)
|
@@ -1255,14 +1405,16 @@ def mean_time_to_detect(y_true: np.array, y_pred: np.array):
|
|
1255
1405
|
the average number of time steps between the true onset of an anomaly and its first detection.
|
1256
1406
|
|
1257
1407
|
Parameters:
|
1258
|
-
|
1259
|
-
|
1408
|
+
y_true (np.array):
|
1409
|
+
The ground truth binary labels for the time series data.
|
1410
|
+
y_pred (np.array):
|
1411
|
+
The predicted binary labels for the time series data.
|
1260
1412
|
|
1261
1413
|
For more information, see the original paper:
|
1262
1414
|
https://arxiv.org/pdf/2211.05244
|
1263
1415
|
|
1264
1416
|
Returns:
|
1265
|
-
|
1417
|
+
float: The mean time to detect.
|
1266
1418
|
"""
|
1267
1419
|
|
1268
1420
|
b = Binary_detection(len(y_true),y_true,y_pred)
|
@@ -15,8 +15,13 @@ def precision_at_k(y_true : np.array, y_anomaly_scores: np.array):
|
|
15
15
|
y_true. That is, k = sum(y_true).
|
16
16
|
|
17
17
|
Parameters:
|
18
|
-
|
19
|
-
|
18
|
+
y_true (np.array):
|
19
|
+
The ground truth binary labels for the time series data.
|
20
|
+
y_anomaly_scores (np.array):
|
21
|
+
The predicted anomaly scores for the time series data.
|
22
|
+
|
23
|
+
Returns:
|
24
|
+
float: The precision at k score.
|
20
25
|
"""
|
21
26
|
m = PatK_pw(y_true,y_anomaly_scores)
|
22
27
|
|
@@ -31,8 +36,10 @@ def auc_roc_pw(y_true : np.array, y_anomaly_scores: np.array):
|
|
31
36
|
independently when calculating true positives, false positives, and false negatives.
|
32
37
|
|
33
38
|
Parameters:
|
34
|
-
y_true (np.array):
|
35
|
-
|
39
|
+
y_true (np.array):
|
40
|
+
Ground-truth binary labels for the time series (0 = normal, 1 = anomaly).
|
41
|
+
y_anomaly_scores (np.array):
|
42
|
+
Continuous anomaly scores assigned to each point in the series.
|
36
43
|
|
37
44
|
Returns:
|
38
45
|
float: AUC-ROC score.
|
@@ -52,8 +59,10 @@ def auc_pr_pw(y_true : np.array ,y_anomaly_scores: np.array):
|
|
52
59
|
independently when calculating precision and recall.
|
53
60
|
|
54
61
|
Parameters:
|
55
|
-
y_true (np.array):
|
56
|
-
|
62
|
+
y_true (np.array):
|
63
|
+
Ground-truth binary labels for the time series (0 = normal, 1 = anomaly).
|
64
|
+
y_anomaly_scores (np.array):
|
65
|
+
Continuous anomaly scores assigned to each point in the series.
|
57
66
|
|
58
67
|
Returns:
|
59
68
|
float: AUC-PR score.
|
@@ -76,8 +85,10 @@ def auc_pr_pa(y_true: np.array, y_anomaly_scores: np.array):
|
|
76
85
|
which are used to construct the PR curve.
|
77
86
|
|
78
87
|
Parameters:
|
79
|
-
y_true (np.array):
|
80
|
-
|
88
|
+
y_true (np.array):
|
89
|
+
Ground-truth binary labels for the time series (0 = normal, 1 = anomaly).
|
90
|
+
y_anomaly_scores (np.array):
|
91
|
+
Continuous anomaly scores assigned to each point in the series.
|
81
92
|
|
82
93
|
Returns:
|
83
94
|
float: AUC-PR score (with point-adjusted evaluation).
|
@@ -166,8 +177,10 @@ def auc_pr_sw(y_true: np.array, y_anomaly_scores: np.array):
|
|
166
177
|
to compute precision and recall for constructing the PR curve.
|
167
178
|
|
168
179
|
Parameters:
|
169
|
-
y_true (np.array):
|
170
|
-
|
180
|
+
y_true (np.array):
|
181
|
+
Ground-truth binary labels for the time series (0 = normal, 1 = anomaly).
|
182
|
+
y_anomaly_scores (np.array):
|
183
|
+
Continuous anomaly scores assigned to each point in the series.
|
171
184
|
|
172
185
|
Returns:
|
173
186
|
float: AUC-PR score (with segment-wise evaluation).
|
@@ -271,16 +284,21 @@ def vus_roc(y_true : np.array ,y_anomaly_scores: np.array, window=4):
|
|
271
284
|
the ROC-AUC over different values of the tolerance parameter, from 0 to `window`, thus producing
|
272
285
|
a volume under the ROC surface.
|
273
286
|
|
287
|
+
For more information, see the original paper:
|
288
|
+
https://dl.acm.org/doi/10.14778/3551793.3551830
|
289
|
+
|
274
290
|
Parameters:
|
275
|
-
y_true (np.array):
|
276
|
-
|
277
|
-
|
291
|
+
y_true (np.array):
|
292
|
+
Ground-truth binary labels (0 = normal, 1 = anomaly).
|
293
|
+
y_anomaly_scores (np.array):
|
294
|
+
Anomaly scores for each time point.
|
295
|
+
window (int):
|
296
|
+
Maximum temporal tolerance `l` used to smooth the evaluation.
|
278
297
|
|
279
298
|
Returns:
|
280
299
|
float: VUS-ROC score.
|
281
300
|
|
282
|
-
|
283
|
-
https://dl.acm.org/doi/10.14778/3551793.3551830
|
301
|
+
|
284
302
|
"""
|
285
303
|
m = VUS_ROC(y_true,y_anomaly_scores,max_window=window)
|
286
304
|
|
@@ -296,16 +314,21 @@ def vus_pr(y_true : np.array ,y_anomaly_scores: np.array, window=4):
|
|
296
314
|
anomalies that are temporally close to the true events. The final metric integrates the PR-AUC
|
297
315
|
over several levels of temporal tolerance (from 0 to `window`), yielding a volume under the PR surface.
|
298
316
|
|
317
|
+
For more information, see the original paper:
|
318
|
+
https://dl.acm.org/doi/10.14778/3551793.3551830
|
319
|
+
|
299
320
|
Parameters:
|
300
|
-
y_true (np.array):
|
301
|
-
|
302
|
-
|
321
|
+
y_true (np.array):
|
322
|
+
Ground-truth binary labels (0 = normal, 1 = anomaly).
|
323
|
+
y_anomaly_scores (np.array):
|
324
|
+
Anomaly scores for each time point.
|
325
|
+
window (int):
|
326
|
+
Maximum temporal tolerance `l` used to smooth the evaluation.
|
303
327
|
|
304
328
|
Returns:
|
305
329
|
float: VUS-PR score.
|
306
330
|
|
307
|
-
|
308
|
-
https://dl.acm.org/doi/10.14778/3551793.3551830
|
331
|
+
|
309
332
|
"""
|
310
333
|
m = VUS_PR(y_true,y_anomaly_scores,max_window=window)
|
311
334
|
|
@@ -331,10 +354,14 @@ def real_pate(y_true: np.array, y_anomaly_scores: np.array, early: int, delay: i
|
|
331
354
|
https://arxiv.org/abs/2405.12096
|
332
355
|
|
333
356
|
Parameters:
|
334
|
-
y_true (np.array):
|
335
|
-
|
336
|
-
|
337
|
-
|
357
|
+
y_true (np.array):
|
358
|
+
Ground truth binary labels (0 = normal, 1 = anomaly).
|
359
|
+
y_anomaly_scores (np.array):
|
360
|
+
Real-valued anomaly scores for each time point.
|
361
|
+
early (int):
|
362
|
+
Length of the early buffer zone before each anomaly interval.
|
363
|
+
delay (int):
|
364
|
+
Length of the delay buffer zone after each anomaly interval.
|
338
365
|
|
339
366
|
Returns:
|
340
367
|
float: The real-valued PATE score.
|
tsadmetrics/utils.py
CHANGED
@@ -7,14 +7,20 @@ def compute_metrics(y_true: np.array,y_pred: np.array, metrics: list, metrics_pa
|
|
7
7
|
Computes the specified metrics for the given true and predicted values.
|
8
8
|
|
9
9
|
Parameters:
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
y_true (np.array):
|
11
|
+
True labels.
|
12
|
+
y_pred (np.array):
|
13
|
+
Predicted labels or scores.
|
14
|
+
metrics (list):
|
15
|
+
List of metric names to compute.
|
16
|
+
metrics_params (dict):
|
17
|
+
Dictionary of parameters for each metric.
|
18
|
+
is_anomaly_score (bool):
|
19
|
+
Flag indicating if y_true and y_pred are anomaly scores. Otherwise, they are treated as binary labels.
|
20
|
+
verbose (bool):
|
21
|
+
Flag to print additional information.
|
16
22
|
Returns:
|
17
|
-
|
23
|
+
results (DataFrame): DataFrame containing the computed metrics and their values.
|
18
24
|
"""
|
19
25
|
if not (np.array_equal(np.unique(y_true), [0, 1]) or np.array_equal(np.unique(y_true), [0]) or np.array_equal(np.unique(y_true), [1])):
|
20
26
|
raise ValueError("y_true must be binary labels (0 or 1).")
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: tsadmetrics
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.13
|
4
4
|
Summary: =?unknown-8bit?q?Librer=C3=ADa_para_evaluaci=C3=B3n_de_detecci=C3=B3n_de_anomal=C3=ADas?= en series temporales
|
5
5
|
Home-page: https://github.com/pathsko/TSADmetrics
|
6
6
|
Author: Pedro Rafael Velasco Priego
|
@@ -16,11 +16,11 @@ tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
16
|
tests/test_binary.py,sha256=dj9BsKBo5rpWw4JGiKKoVkg4rIW4YylTie2VxH2DAGo,29787
|
17
17
|
tests/test_non_binary.py,sha256=syANlwm0DKsL6geGeq6nQI6ZVe6T_YXWTyk2-Hmck4s,11308
|
18
18
|
tsadmetrics/__init__.py,sha256=MTWOa43fgOdkMNo5NglCReRnB8hoF0ob2PIvDziCNHw,1575
|
19
|
-
tsadmetrics/binary_metrics.py,sha256=
|
19
|
+
tsadmetrics/binary_metrics.py,sha256=UdXoITIATf585Kvz5i3xhdqEVUogrUHMmJgxj-HoeB0,62477
|
20
20
|
tsadmetrics/metric_utils.py,sha256=fm8v0X37_AlqWpkcUT9r3680QsjLljrHe2YuXkRLAZ4,10873
|
21
|
-
tsadmetrics/non_binary_metrics.py,sha256=
|
21
|
+
tsadmetrics/non_binary_metrics.py,sha256=O6AqceHrjCVV1kJPBzXQIgtiu6afzoiJz2biNsxf3_4,13389
|
22
22
|
tsadmetrics/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
23
|
-
tsadmetrics/utils.py,sha256=
|
23
|
+
tsadmetrics/utils.py,sha256=BqsG4DyP3AffuMFQCJ-Qy4YaDu4IkFudZWYCvyTGvvY,2444
|
24
24
|
tsadmetrics/_tsadeval/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
25
25
|
tsadmetrics/_tsadeval/auc_roc_pr_plot.py,sha256=PHqJUXq2qI248XV9o04D8SsUJgowetaKq0Cu5bYrIAE,12689
|
26
26
|
tsadmetrics/_tsadeval/discontinuity_graph.py,sha256=Ci65l_DPi6HTtb8NvQJe1najgGrRuEpOMWvSyi2AeR0,4088
|
@@ -53,7 +53,7 @@ tsadmetrics/_tsadeval/prts/time_series_metrics/fscore.py,sha256=pJz4iuPyVGNvwsaR
|
|
53
53
|
tsadmetrics/_tsadeval/prts/time_series_metrics/precision.py,sha256=jLkcMg7UNl25SHtZUBGkP-RV8HsvaZCtjakryl7PFWU,3204
|
54
54
|
tsadmetrics/_tsadeval/prts/time_series_metrics/precision_recall.py,sha256=OhUJSm_I7VZ_gX_SSg8AYUq3_NW9rMIy7lAVsnOFw4Q,417
|
55
55
|
tsadmetrics/_tsadeval/prts/time_series_metrics/recall.py,sha256=LL-0pPer3ymovVRlktaHo5XDzpgiDhWOVfdPOzKR6og,3152
|
56
|
-
tsadmetrics-0.1.
|
57
|
-
tsadmetrics-0.1.
|
58
|
-
tsadmetrics-0.1.
|
59
|
-
tsadmetrics-0.1.
|
56
|
+
tsadmetrics-0.1.13.dist-info/METADATA,sha256=k3BVjOM_Ife2-uXsEWu3o-6tRTUXUqLDd9I9NBV-61g,831
|
57
|
+
tsadmetrics-0.1.13.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
|
58
|
+
tsadmetrics-0.1.13.dist-info/top_level.txt,sha256=s2VIr_ePl-WZbYt9FsYbsDGM7J-Qc5cgpwEOeQ3FVpM,31
|
59
|
+
tsadmetrics-0.1.13.dist-info/RECORD,,
|
File without changes
|
File without changes
|