precision,recall 计算代码

版权声明:我是小仙女 转载要告诉小仙女哦 https://blog.csdn.net/qq_40210472/article/details/88848919

之前写precision,recall的代码都是用了两层循环,今天看到一个比较优美的写法,用python 的set,以及交集intersection,所以Mark一下。这个文档将会Mark所有觉得不错的计算评测标准的代码

precision Recall

def cal_precision_recall(targets,predictions,k):

# targets是真实值,predictions是预测值
	pred = predictions[:k]
	num_hit = len(set(predictions).intersection(set(targets)))
	precision = float(num_hit/predictions)
	recall = float(num_hit/targets)
	return precison , recall 
	


猜你喜欢

转载自blog.csdn.net/qq_40210472/article/details/88848919
今日推荐