Skip to content

Commit

Permalink
Merge pull request #215 from dzhwinter/fix_ndcg
Browse files Browse the repository at this point in the history
metric ndcg with power 2
  • Loading branch information
dzhwinter committed Aug 23, 2017
2 parents ad64207 + 857f4f6 commit a249993
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions ltr/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def dcg(score_list):
n = len(score_list)
cost = .0
for i in range(n):
cost += float(score_list[i]) / np.log((i + 1) + 1)
cost += float(np.power(2, score_list[i])) / np.log((i + 1) + 1)
return cost

dcg_cost = dcg(score_list)
Expand All @@ -28,14 +28,11 @@ def dcg(score_list):
return dcg_cost / ideal_cost


class NdcgTest(unittest.TestCase):
def __init__(self):
pass

def runcase(self):
class TestNDCG(unittest.TestCase):
def test_array(self):
a = [3, 2, 3, 0, 1, 2]
value = ndcg(a)
self.assertAlmostEqual(0.961, value, places=3)
self.assertAlmostEqual(0.9583, value, places=3)


if __name__ == '__main__':
Expand Down

0 comments on commit a249993

Please sign in to comment.