Skip to content

Instantly share code, notes, and snippets.

@xgfs
Created March 12, 2016 10:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xgfs/665521f7394034b304f4 to your computer and use it in GitHub Desktop.
Save xgfs/665521f7394034b304f4 to your computer and use it in GitHub Desktop.
graph ndcg
import numpy as np
def dcg(values):
gains = np.exp2(values) - 1
discounts = np.log2(np.arange(len(values)) + 2)
return np.sum(gains / discounts)
def ndcg(actual, predicted):
return dcg(np.in1d(actual, predicted).astype(np.int)) / dcg(np.ones(len(actual)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment