def testEvaluateRankingLastZeroWithCutoff(self): ev = NdcgEval() dot_prod = np.dot(self.query.get_feature_vectors(), self.zero_weights.transpose()) ranking = ev._sort_docids_by_score(self.query.get_docids(), dot_prod, ties="last") self.assertAlmostEquals(0.4452805, ev.evaluate_ranking(ranking, self.query, cutoff=10))
def testEvaluateRankingLastZeroWithCutoff(self): ev = NdcgEval() dot_prod = np.dot(self.query.get_feature_vectors(), self.zero_weights.transpose()) ranking = ev._sort_docids_by_score(self.query.get_docids(), dot_prod, ties="last") self.assertAlmostEquals( 0.4452805, ev.evaluate_ranking(ranking, self.query, cutoff=10))
def testGetNdcg(self): ev = NdcgEval() self.assertAlmostEqual(ev.get_ndcg([0, 0, 1, 0], [1, 0, 0, 0]), 0.5) self.assertAlmostEqual(ev.get_ndcg([0, 1, 0, 0], [1, 0, 0, 0]), 0.6309298) self.assertAlmostEqual(ev.get_ndcg([0, 0, 0, 0], [1, 0, 0, 0]), 0)