赞
踩
1. 猫
2. 狗
3. 猪
def calculatePRAndF1(): with open("data/testresult.txt", mode="r", encoding="utf8") as f: allLocPre = 0 # 所有被模型识别为地名的数量 locPreCorr = 0 # 被模型识别为地名且正确的数量 allLocReal = 0 # 所有地名的数量 for line in f: line = line.strip() if line == "": continue word, realFlag, preFlag = line.split() # 字, 实际状态标注, 预测状态标注 if preFlag != "O": allLocPre += 1 if realFlag != "O": allLocReal += 1 if realFlag == preFlag: if not realFlag == "O": locPreCorr += 1 precision = locPreCorr * 1.0 / allLocPre # 查准率 recall = locPreCorr * 1.0 / allLocReal # 召回率 f1 = 2 * precision * recall / (precision + recall) # 调和平均 return precision, recall, f1
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。