本文簡要介紹python語言中 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 形狀(n_samples,n_labels)
多標簽分類的真實目標,或要排名的實體的真實分數。
- y_score:ndarray 形狀(n_samples,n_labels)
目標分數可以是概率估計、置信度值或決策的非閾值度量(由 “decision_function” 在某些分類器上返回)。
- k:整數,默認=無
隻考慮排名中最高的 k 分數。如果沒有,使用所有輸出。
- log_base:浮點數,默認=2
用於折扣的對數的底。低值意味著更大的折扣(最高結果更重要)。
- sample_weight:ndarray 形狀 (n_samples,),默認 = 無
樣本權重。如果
None
,所有樣本都被賦予相同的權重。- ignore_ties:布爾,默認=假
假設 y_score 中沒有關係(如果 y_score 是連續的,則可能是這種情況)以提高效率。
- discounted_cumulative_gain:浮點數
平均樣本 DCG 分數。
參數:
返回:
參考:
Wikipedia entry for Discounted Cumulative Gain 。
Jarvelin, K. 和 Kekalainen, J. (2002)。 IR 技術的基於累積增益的評估。 ACM 信息係統交易 (TOIS),20(4),422-446。
Wang, Y., Wang, L., Li, Y., He, D., Chen, W., & Liu, T. Y.(2013 年 5 月)。 NDCG排名措施的理論分析。在第 26 屆學習理論年會論文集(COLT 2013)中。
McSherry, F. 和 Najork, M.(2008 年 3 月)。在存在並列分數的情況下有效地計算信息檢索性能度量。在歐洲信息檢索會議上(第 414-421 頁)。施普林格,柏林,海德堡。
例子:
>>> import numpy as np >>> 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
相關用法
- Python sklearn d2_tweedie_score用法及代碼示例
- Python sklearn deprecated用法及代碼示例
- Python sklearn dict_learning用法及代碼示例
- Python sklearn det_curve用法及代碼示例
- Python sklearn dict_learning_online用法及代碼示例
- Python sklearn jaccard_score用法及代碼示例
- Python sklearn WhiteKernel用法及代碼示例
- Python sklearn CalibrationDisplay.from_predictions用法及代碼示例
- Python sklearn VotingRegressor用法及代碼示例
- Python sklearn gen_batches用法及代碼示例
- Python sklearn ExpSineSquared用法及代碼示例
- Python sklearn MDS用法及代碼示例
- Python sklearn adjusted_rand_score用法及代碼示例
- Python sklearn MLPClassifier用法及代碼示例
- Python sklearn train_test_split用法及代碼示例
- Python sklearn RandomTreesEmbedding用法及代碼示例
- Python sklearn GradientBoostingRegressor用法及代碼示例
- Python sklearn GridSearchCV用法及代碼示例
- Python sklearn log_loss用法及代碼示例
- Python sklearn r2_score用法及代碼示例
- Python sklearn ndcg_score用法及代碼示例
- Python sklearn ShrunkCovariance用法及代碼示例
- Python sklearn SelfTrainingClassifier用法及代碼示例
- Python sklearn load_svmlight_file用法及代碼示例
- Python sklearn make_pipeline用法及代碼示例
注:本文由純淨天空篩選整理自scikit-learn.org大神的英文原創作品 sklearn.metrics.dcg_score。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。