summaryrefslogtreecommitdiff
path: root/evaluation/affiliation.py
diff options
context:
space:
mode:
authorZHENG Yanqin <[email protected]>2023-05-25 07:37:53 +0000
committerZHENG Yanqin <[email protected]>2023-05-25 07:37:53 +0000
commite9896bd62bb29da00ec00a121374167ad91bfe47 (patch)
treed94845574c8ef7473d0204d28b4efd4038035463 /evaluation/affiliation.py
parentfad9aa875c84b38cbb5a6010e104922b1eea7291 (diff)
parent4c5734c624705449c6b21c4b2bc5554e7259fdba (diff)
Merge branch 'master' into 'main'HEADmain
readme See merge request zyq/time_series_anomaly_detection!1
Diffstat (limited to 'evaluation/affiliation.py')
-rw-r--r--evaluation/affiliation.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/evaluation/affiliation.py b/evaluation/affiliation.py
new file mode 100644
index 0000000..362330e
--- /dev/null
+++ b/evaluation/affiliation.py
@@ -0,0 +1,23 @@
+from .affiliation_bin.generics import convert_vector_to_events
+from .affiliation_bin.metrics import pr_from_events
+
+
+def evaluate(y_true: list, y_pred: list) -> float:
+ """
+ F1PA评估方法,经过point adjust调整标签后再用F1评分
+ :param y_true: 真实标签
+ :param y_pred: 检测标签
+ :return: affiliation的三个score
+ """
+ true, pred = y_true.copy(), y_pred.copy()
+ events_pred = convert_vector_to_events(pred)
+ events_gt = convert_vector_to_events(true)
+ Trange = (0, len(pred))
+
+ res = pr_from_events(events_pred, events_gt, Trange)
+ aff_precision = res["precision"]
+ aff_recall = res["recall"]
+ if aff_recall == 0 or aff_precision == 0:
+ return 0
+ aff_f1 = 2 * aff_precision * aff_recall / (aff_precision + aff_recall)
+ return aff_f1 \ No newline at end of file