From c3c45039ed6c5087732a7d3192c00319e40e6223 Mon Sep 17 00:00:00 2001 From: Youngjoon Lee <5462944+youngjoon-lee@users.noreply.github.com> Date: Mon, 10 Jun 2024 19:11:40 +0900 Subject: [PATCH] calculate precision, recall, and f1 score for suspected origins --- mixnet/v2/sim/analysis.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mixnet/v2/sim/analysis.py b/mixnet/v2/sim/analysis.py index 44e8d54..4f7b4e0 100644 --- a/mixnet/v2/sim/analysis.py +++ b/mixnet/v2/sim/analysis.py @@ -118,6 +118,15 @@ class Analysis: plt.tight_layout() plt.show() + # Calculate precision, recall, and F1 score + truth = set(truth_df[truth_df[COL_MSG_CNT] > 0][COL_NODE_ID]) + suspected = set(suspected_df[suspected_df[COL_MSG_CNT] > 0][COL_NODE_ID]) + true_positives = truth.intersection(suspected) + precision = len(true_positives) / len(suspected) * 100.0 if len(suspected) > 0 else 0.0 + recall = len(true_positives) / len(truth) * 100.0 if len(truth) > 0 else 0.0 + f1_score = 2 * precision * recall / (precision + recall) if precision + recall > 0 else 0.0 + print(f"Precision: {precision:.2f}%, Recall: {recall:.2f}%, F1 Score: {f1_score:.2f}%") + def messages_in_node_over_time(self): dataframes = [] for window, msg_pools in enumerate(self.sim.p2p.adversary.msg_pools_per_window):