代码拉取完成,页面将自动刷新
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}")
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。