def coverage(recommends, train):
	"""计算覆盖率

	:param recommends: 给用户的推荐结果{用户 : 该用户的推荐列表}
	:param train: 训练集[(uid, iid)]
	:return: 覆盖率
	"""

	rec_items = set() #被推荐的物品集合
	total_items = set() #物品总集合

	for user, items in recommends.items():
		for item in items:
			rec_items.add(item)
	for user, item in train:
		total_items.add(item)

	return len(rec_items) / (len(total_items) * 1.0)