Skip to content

Commit

Permalink
metric ndcg with power 2
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhwinter committed Aug 22, 2017
1 parent d42adac commit ba83c56
Show file tree
Hide file tree
Showing 2 changed files 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
Binary file added ltr/metrics.pyc
Binary file not shown.

0 comments on commit ba83c56

Please sign in to comment.