Created
November 11, 2018 21:46
-
-
Save christinebuckler/3fb685b0c8bb016b04788c606f859692 to your computer and use it in GitHub Desktop.
NDCG metric function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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