Skip to content

Instantly share code, notes, and snippets.

@christinebuckler
Created November 11, 2018 21:46
Show Gist options
  • Save christinebuckler/3fb685b0c8bb016b04788c606f859692 to your computer and use it in GitHub Desktop.
Save christinebuckler/3fb685b0c8bb016b04788c606f859692 to your computer and use it in GitHub Desktop.
NDCG metric function
# Normalize Discounted Communicative Gain
# NDCG evaluated within list impression for top n items (where NCG is actually ranking and IDCG is the ideal ranking).
# Relevance score is generally related to funnel metrics.
def dcg(data, n):
rel = data['relevance_score']
dcg = sum((rel/np.log2(i + 1)) for i in range(1, n+1)])
return dcg
def ndcg(dcg, idcg):
ndcg = dcg/idcg
return ndcg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment