累积累计收益DCG_SCORE SKLEARN
from sklearn.metrics import ndcg_score, dcg_score
import numpy as np
actual= [3,2,0,0,1]
ideal= sorted(actual, reverse=True)
#list to np asarray
actualarr=np.asarray([actual])
idealarr= np.asarray([ideal])
print ("actual score as array", actualarr)
print("ideal score as array", idealarr)
#Discounted Cumulative Gain
dcg= dcg_score(idealarr, actualarr)
print("DCG: ", dcg)
我不明白为什么dcg_score
以y_score为参数。当我奏效DCG Longhand(sum Residenta/log2(i+1))时,我可以得到相同的答案〜4.6,但是我只需使用True Scores [3,2,0,0,0,0]就可以实现这一目标。
,为什么它还需要理想得分[3,2,1,0,0]
在功能中?
from sklearn.metrics import ndcg_score, dcg_score
import numpy as np
actual= [3,2,0,0,1]
ideal= sorted(actual, reverse=True)
#list to np asarray
actualarr=np.asarray([actual])
idealarr= np.asarray([ideal])
print ("actual score as array", actualarr)
print("ideal score as array", idealarr)
#Discounted Cumulative Gain
dcg= dcg_score(idealarr, actualarr)
print("DCG: ", dcg)
I don't understand why dcg_score
takes y_score as a parameter. When I work out DCG longhand (sum relevance/log2(i+1)) I can get the same answer ~4.6, but i can achieve this just with the true scores [3,2,0,0,1]
, so why does it also require the ideal score [3,2,1,0,0]
in the function?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我知道
sklearn.metrics.ndcg
通过从y_true
中取值就可以计算其总和,就像根据y_score
重新排序。如:“总和在预测分数引起的顺序中排名的真实分数”
这意味着使用真实相关值在诱导的排名上计算公制。
一个小示例:
输出:
显示幼稚的对同一排名顺序产生不同的度量。
I understood that
sklearn.metrics.ndcg
computes its sum by taking values fromy_true
as if it was reordered according toy_score
.As explained inside the code: "Sum the true scores ranked in the order induced by the predicted scores"
This means the metric is computed on the induced ranking, using true relevance values.
A small example:
outputs:
which shows naive produces a different metric for the same ranking order.