sklearn.metrics.dcg_score¶
sklearn.metrics.dcg_score(y_true, y_score, *, k=None, log_base=2, sample_weight=None, ignore_ties=False)
计算折损累计增益。
在应用对数折损后,将真实分数按预测分数进行排序后,求和。
如果真实标签的y_score排名高,则此排名度量将产生一个高值。
通常,首选归一化折损累计增益(NDCG,由ndcg_score计算)。
参数 | 说明 |
---|---|
y_true | ndarray, shape (n_samples, n_labels) 多标签分类的真实目标,或要排名的实体的真实得分。 |
y_score | ndarray, shape (n_samples, n_labels) 目标得分可以是概率估计、置信度值或决策的非阈值度量(如某些分类器上的“ decision_function”所返回)。 |
k | int, optional (default=None) 仅考虑排名中最高的k得分。如果为None,则使用所有输出。 |
log_base | float, optional (default=2) 用于折扣的对数的底数。较低的值意味着更大的折损(最佳的结果更为重要)。 |
sample_weight | ndarray, shape (n_samples,), optional (default=None) 样本权重。如果为None,则所有样本的权重相同。 |
ignore_ties | bool, optional (default=False) 假设y_score在效率增益方面不存在关联(如果y_score是连续的,则可能是这种情况)。 |
返回值 | 说明 |
---|---|
discounted_cumulative_gain | float 平均样本的DCG得分。 |
另见
折损累计增益除以理想折损累计增益(获得理想排名的DCG),以得到0到1之间的得分。
参考
Wikipedia entry for Discounted Cumulative Gain
Jarvelin, K., & Kekalainen, J. (2002). Cumulated gain-based evaluation of IR techniques. ACM Transactions on Information Systems (TOIS), 20(4), 422-446.
Wang, Y., Wang, L., Li, Y., He, D., Chen, W., & Liu, T. Y. (2013, May). A theoretical analysis of NDCG ranking measures. In Proceedings of the 26th Annual Conference on Learning Theory (COLT 2013)
McSherry, F., & Najork, M. (2008, March). Computing information retrieval performance measures efficiently in the presence of tied scores. In European conference on information retrieval (pp. 414-421). Springer, Berlin, Heidelberg.
示例
>>> from sklearn.metrics import dcg_score
>>> # we have groud-truth relevance of some answers to a query:
>>> true_relevance = np.asarray([[10, 0, 0, 1, 5]])
>>> # we predict scores for the answers
>>> scores = np.asarray([[.1, .2, .3, 4, 70]])
>>> dcg_score(true_relevance, scores)
9.49...
>>> # we can set k to truncate the sum; only top k answers contribute
>>> dcg_score(true_relevance, scores, k=2)
5.63...
>>> # now we have some ties in our prediction
>>> scores = np.asarray([[1, 0, 0, 0, 1]])
>>> # by default ties are averaged, so here we get the average true
>>> # relevance of our top predictions: (10 + 5) / 2 = 7.5
>>> dcg_score(true_relevance, scores, k=1)
7.5
>>> # we can choose to ignore ties for faster results, but only
>>> # if we know there aren't ties in our scores, otherwise we get
>>> # wrong results:
>>> dcg_score(true_relevance,
... scores, k=1, ignore_ties=True)
5.0