2 Star 1 Fork 0

glorious years/finalProject

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
test_cal_av_acc.py 1.56 KB
一键复制 编辑 原始数据 按行查看 历史
glorious years 提交于 2024-11-17 20:18 . final all
import json
import os
import json
import numpy as np
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity
from tqdm import tqdm
# 读取评估结果文件
def load_evaluation_results(file_path):
with open(file_path, 'r') as f:
data = json.load(f)
return data
# 计算每种打分的平均值
def calculate_average_scores(results):
jaccard_scores = []
cosine_scores = []
deepseek_scores = []
for result in results:
jaccard_scores.append(result['jaccard_score'])
cosine_scores.append(result['cosine_score'])
deepseek_scores.append(result['deepseek_score'])
avg_jaccard_score = sum(jaccard_scores) / len(jaccard_scores)
avg_cosine_score = sum(cosine_scores) / len(cosine_scores)
avg_deepseek_score = sum(deepseek_scores) / len(deepseek_scores)
return {
'avg_jaccard_score': avg_jaccard_score,
'avg_cosine_score': avg_cosine_score,
'avg_deepseek_score': avg_deepseek_score
}
# 保存平均打分结果
def save_average_scores(avg_scores, output_path):
with open(output_path, 'w') as f:
json.dump(avg_scores, f, indent=4)
if __name__ == "__main__":
file_path = 'data/iu_xray/iu_xray/evaluation_results.json'
output_path = 'data/iu_xray/iu_xray/average_scores.json'
evaluation_results = load_evaluation_results(file_path)
avg_scores = calculate_average_scores(evaluation_results)
print(avg_scores)
# save_average_scores(avg_scores, output_path)
# print(f"Average scores saved to {output_path}")
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/lxh_package/final-project.git
[email protected]:lxh_package/final-project.git
lxh_package
final-project
finalProject
master

搜索帮助