We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NDCG,Normalized Discounted Cumulative Gain,直译为归一化折损累计增益,是用来衡量排序质量的指标。
数据示例:
#!/usr/bin/env python3 # encoding: utf-8 """ NDCG """ import math def get_ndcg(lst, topn): """python calculate ndcg""" # ndcg@n 关心前n个排序是否正确,后面的排序不予考虑。 dcg_lst = list(lst)[:topn] idcg_lst = list(sorted(lst, reverse=True))[:topn] # 初始序列是0,故 i + 2 # idcg为理想情况下最大的DCG值 dcg = sum(j / math.log2(i + 2) for i, j in enumerate(dcg_lst)) idcg = sum(j / math.log2(i + 2) for i, j in enumerate(idcg_lst)) ndcg = dcg / idcg return dcg, idcg, ndcg if __name__ == "__main__": print(get_ndcg([3, 2, 3, 0, 1, 2, 3, 0], 6)) print(get_ndcg([3, 2, 3, 0, 1, 2], 6)) print(get_ndcg([6, 4, 6, 0, 2, 4, 6, 0], 6)) print(get_ndcg([6, 4, 6, 0, 2, 4], 6))
#!/usr/bin/env python3 # encoding: utf-8 """ MNDCG """ import math def get_map(lst, maxi): """python calculate ndcg""" # 标注区间要映射为从0到1,maxi是最高标准,mini应该是0 nlst = [i / maxi for i in lst] nmap = sum(nlst) / len(nlst) nlst = sorted(lst, reverse=True) dcg = sum(j / math.log2(i + 2) for i, j in enumerate(lst)) idcg = sum(j / math.log2(i + 2) for i, j in enumerate(nlst)) maxdcg = sum(5 / math.log2(i + 2) for i, j in enumerate(nlst)) ndcg = dcg / idcg mndcg = dcg / maxdcg # 此处是想计算nmap与ndcg的f1值,作为参考 f1value = 2 * (nmap * ndcg) / (nmap + ndcg) return nmap, ndcg, f1value, mndcg if __name__ == "__main__": print(get_map([0, 5, 5, 5, 5], 5)) print(get_map([5, 5, 0, 5, 5], 5)) print(get_map([5, 5, 5, 5, 0], 5)) print(get_map([5, 5, 0, 0, 5], 5)) print(get_map([5, 0, 0, 5, 5], 5)) print(get_map([5, 0, 0, 0, 5], 5)) print("----") print(get_map([1, 2, 0, 0, 0], 5)) print(get_map([1, 5, 0, 0, 0], 5)) print(get_map([2, 1, 0, 0, 0], 5)) print(get_map([5, 3, 0, 5, 0], 5))
output(nmap, ndcg, f1value, mndcg):
数据分析:
The text was updated successfully, but these errors were encountered:
No branches or pull requests
NDCG 指标简介
NDCG,Normalized Discounted Cumulative Gain,直译为归一化折损累计增益,是用来衡量排序质量的指标。
数据示例:
NDCG 相关名词
NDCG 优缺点分析
实践问题
NDCG 计算公式
MNDCG 计算公式
output(nmap, ndcg, f1value, mndcg):
数据分析:
参考文章
The text was updated successfully, but these errors were encountered: