{
  "name": "NDCG@k defaults in scikit-learn, Keras RS and PyTorch Ignite",
  "description": "Compares how three Python libraries define NDCG@k: gain function, rank discount, tie handling and behaviour when a list has no relevant item. Compiled from each library's official documentation page; the scikit-learn gain and discount cell reports a recomputation of its documented examples, not a statement on the page.",
  "page": "https://casrai.org/guides/ndcg-k",
  "publisher": "CASRAI",
  "license": "https://creativecommons.org/licenses/by/4.0/",
  "dateModified": "2026-11-17T14:51:09Z",
  "temporalCoverage": null,
  "spatialCoverage": null,
  "columns": [
    {
      "name": "Library",
      "unit": "",
      "description": ""
    },
    {
      "name": "Default gain",
      "unit": "",
      "description": ""
    },
    {
      "name": "Rank discount",
      "unit": "",
      "description": ""
    },
    {
      "name": "Tie handling",
      "unit": "",
      "description": ""
    },
    {
      "name": "List with no relevant item",
      "unit": "",
      "description": ""
    }
  ],
  "rows": [
    {
      "Library": "scikit-learn ndcg_score",
      "Default gain": "Not stated on the function page; its documented examples are reproduced by linear gain",
      "Rank discount": "Not stated on the function page; examples match log base 2",
      "Tie handling": "Ties averaged by default; ignore_ties=True is wrong if ties are present",
      "List with no relevant item": "Not stated on the function page"
    },
    {
      "Library": "Keras RS NDCG",
      "Default gain": "2**y - 1 (gain_fn)",
      "Rank discount": "1 / log2(rank + 1) (rank_discount_fn)",
      "Tie handling": "shuffle_ties=True randomly shuffles scores before sorting; seed argument",
      "List with no relevant item": "nDCG@k defined as 0 when IDCG@k is 0"
    },
    {
      "Library": "PyTorch Ignite NDCG",
      "Default gain": "exp_rank: 2^relevance - 1 (linear_rank available)",
      "Rank discount": "1 / log2(i + 1), fixed",
      "Tie handling": "Not stated on the class page",
      "List with no relevant item": "Excluded when ignore_zero_hits=True (default); counted as 0 when False"
    }
  ],
  "sources": [
    {
      "title": "scikit-learn: sklearn.metrics.ndcg_score",
      "url": "https://scikit-learn.org/stable/modules/generated/sklearn.metrics.ndcg_score.html",
      "accessed": "2026-11-17"
    },
    {
      "title": "Keras RS: nDCG metric",
      "url": "https://keras.io/keras_rs/api/metrics/ndcg",
      "accessed": "2026-11-17"
    },
    {
      "title": "PyTorch Ignite: ignite.metrics.rec_sys.NDCG",
      "url": "https://docs.pytorch.org/ignite/master/generated/ignite.metrics.rec_sys.NDCG.html",
      "accessed": "2026-11-17"
    }
  ]
}