{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Performance for all_with_p_s.csv:\n", "TP: 1724, TN: 11907, FP: 919, FN: 272\n", "Precision: 0.6523, Recall: 0.8637, Accuracy: 0.9196\n" ] } ], "source": [ "import pandas as pd\n", "\n", "# Set the group number\n", "group_number = 1 # Change this to the desired group number\n", "\n", "# File paths for the two datasets\n", "test_s_path = f'../post_process/0.result/{group_number}/test_s.csv'\n", "\n", "# Load the CSV files\n", "test_s_csv = pd.read_csv(test_s_path, low_memory=False)\n", "test_s_csv.fillna('', inplace=True)\n", "\n", "def evaluate_performance(test_csv):\n", " # Initialize counters for TP, TN, FP, FN\n", " TP = 0\n", " TN = 0\n", " FP = 0\n", " FN = 0\n", "\n", " # Iterate over the DataFrame rows\n", " for index, row in test_csv.iterrows():\n", " # True Positive (TP): s_correct is True and MDM is True\n", " if row['s_correct'] and row['MDM']:\n", " TP += 1\n", " # True Negative (TN): s_thing is null and MDM is False\n", " elif row['s_thing'] == '' and not row['MDM']:\n", " TN += 1\n", " # False Positive (FP): \n", " # 1) s_thing is not null and MDM is False \n", " # OR \n", " # 2) s_thing is not null and s_correct is False and MDM is True\n", " elif (row['s_thing'] != '' and not row['MDM']) or (row['s_thing'] != '' and not row['s_correct'] and row['MDM']):\n", " FP += 1\n", " # False Negative (FN): s_thing is null and MDM is True\n", " elif row['s_thing'] == '' and row['MDM']:\n", " FN += 1\n", "\n", " # Calculate total\n", " total = TP + TN + FP + FN\n", "\n", " # Calculate Precision, Recall, and Accuracy\n", " precision = TP / (TP + FP) if (TP + FP) > 0 else 0\n", " recall = TP / (TP + FN) if (TP + FN) > 0 else 0\n", " accuracy = (TP + TN) / total if total > 0 else 0\n", "\n", " return TP, TN, FP, FN, precision, recall, accuracy\n", "\n", "# Evaluate both datasets\n", "tp_s_results = evaluate_performance(test_s_csv)\n", "\n", "# Print the results for both datasets\n", "print(\"Performance for all_with_p_s.csv:\")\n", "print(f\"TP: {tp_s_results[0]}, TN: {tp_s_results[1]}, FP: {tp_s_results[2]}, FN: {tp_s_results[3]}\")\n", "print(f\"Precision: {tp_s_results[4]:.4f}, Recall: {tp_s_results[5]:.4f}, Accuracy: {tp_s_results[6]:.4f}\")" ] } ], "metadata": { "kernelspec": { "display_name": "base", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.14" } }, "nbformat": 4, "nbformat_minor": 2 }