THUIR / PreHash

61 stars 11 forks source link

代码里算ndcg 为啥用的是split_l 而不是 split_p? #3

Closed youngerrainbow closed 4 years ago

youngerrainbow commented 4 years ago
                if metric.startswith('ndcg@'):
                    max_k = max([len(d) for d in split_l])
                    k_data = np.array([(list(d) + [0] * max_k)[:max_k] for d in split_l])
                    best_rank = -np.sort(-k_data, axis=1)
                    best_dcg = np.sum(best_rank[:, :k] / np.log2(np.arange(2, k + 2)), axis=1)
                    best_dcg[best_dcg == 0] = 1
                    dcg = np.sum(k_data[:, :k] / np.log2(np.arange(2, k + 2)), axis=1)
                    ndcgs = dcg / best_dcg
                    evaluations.append(np.average(ndcgs))