Skip to content

Instantly share code, notes, and snippets.

View suzanv's full-sized avatar

Suzan Verberne suzanv

View GitHub Profile
@kell18
kell18 / ndcg_recsys.py
Last active January 10, 2023 04:31
NDCG for recommender systems
from math import log
import unittest
def dcg_at_k(scores):
assert scores
return scores[0] + sum(sc / log(ind, 2) for sc, ind in zip(scores[1:], range(2, len(scores)+1)))
def ndcg_at_k(predicted_scores, user_scores):
assert len(predicted_scores) == len(user_scores)
@bwhite
bwhite / rank_metrics.py
Created September 15, 2012 03:23
Ranking Metrics
"""Information Retrieval metrics
Useful Resources:
http://www.cs.utexas.edu/~mooney/ir-course/slides/Evaluation.ppt
http://www.nii.ac.jp/TechReports/05-014E.pdf
http://www.stanford.edu/class/cs276/handouts/EvaluationNew-handout-6-per.pdf
http://hal.archives-ouvertes.fr/docs/00/72/67/60/PDF/07-busa-fekete.pdf
Learning to Rank for Information Retrieval (Tie-Yan Liu)
"""
import numpy as np