Closed youngerrainbow closed 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))