Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue in the function computing NDCG #19

Open
rguo12 opened this issue Feb 7, 2023 · 0 comments
Open

issue in the function computing NDCG #19

rguo12 opened this issue Feb 7, 2023 · 0 comments

Comments

@rguo12
Copy link

rguo12 commented Feb 7, 2023

Hi,

I just find there is an issue in the following function

def ndcg(y_pred, y_true, top):
   assert y_pred.shape[0] == y_true.shape[0]
   top = min(top, y_pred.shape[0])

   first_k_docs = sorted(zip(y_true, y_pred), key=cmp_to_key(doc_comparator))
   first_k_docs = np.array(first_k_docs)[:top,0]

   top_k_idxs = np.argsort(y_true)[::-1][:top]
   top_k_docs = y_true[top_k_idxs]

   dcg = cumulative_gain(first_k_docs)
   idcg = cumulative_gain(top_k_docs)

   return dcg / idcg if idcg > 0 else 1.

how can ndcg=1 if idcg == 0? If idcg == 0 you should just ignore that query. This definitely makes the NDCG look higher than it is expected to be.

Best,

Ruocheng Guo

@rguo12 rguo12 changed the title reproduce ranking results issue in the function computing NDCG Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant