class_docstr: Normalized discounted cumulative gain metric.
docstr: Calculate normalized discounted cumulative gain (ndcg).
  
  Relevance is positive real values or binary values.
  
  Example:
      >>> y_true = [0, 1, 2, 0]
      >>> y_pred = [0.4, 0.2, 0.5, 0.7]
      >>> ndcg = NormalizedDiscountedCumulativeGain
      >>> ndcg(k=1)(y_true, y_pred)
      0.0
      >>> round(ndcg(k=2)(y_true, y_pred), 2)
      0.52
      >>> round(ndcg(k=3)(y_true, y_pred), 2)
      0.52
      >>> type(ndcg()(y_true, y_pred))
      <class 'float'>
  
  :param y_true: The ground true label of each document.
  :param y_pred: The predicted scores of each document.
  
  :return: Normalized discounted cumulative gain.
docstr_tok: ["Calculate","normalized","discounted","cumulative","gain","(","ndcg",")",".","Relevance","is","positive","real","values","or","binary","values",".","Example",":",">",">",">","y_true","=","[","0",",","1",",","2",",","0","]",">",">",">","y_pred","=","[","0.4",",","0.2",",","0.5",",","0.7","]",">",">",">","ndcg","=","NormalizedDiscountedCumulativeGain",">",">",">","ndcg","(","k=1",")","(","y_true",",","y_pred",")","0.0",">",">",">","round","(","ndcg","(","k=2",")","(","y_true",",","y_pred",")",",","2",")","0.52",">",">",">","round","(","ndcg","(","k=3",")","(","y_true",",","y_pred",")",",","2",")","0.52",">",">",">","type","(","ndcg","(",")","(","y_true",",","y_pred",")",")","<","class","'float","'",">",":","param","y_true",":","The","ground","true","label","of","each","document",".",":","param","y_pred",":","The","predicted","scores","of","each","document",".",":","return",":","Normalized","discounted","cumulative","gain","."]
code: def __call__(self, y_true: np.array, y_pred: np.array) -> float:
      """
      Calculate normalized discounted cumulative gain (ndcg).
  
      Relevance is positive real values or binary values.
  
      Example:
          >>> y_true = [0, 1, 2, 0]
          >>> y_pred = [0.4, 0.2, 0.5, 0.7]
          >>> ndcg = NormalizedDiscountedCumulativeGain
          >>> ndcg(k=1)(y_true, y_pred)
          0.0
          >>> round(ndcg(k=2)(y_true, y_pred), 2)
          0.52
          >>> round(ndcg(k=3)(y_true, y_pred), 2)
          0.52
          >>> type(ndcg()(y_true, y_pred))
          <class 'float'>
  
      :param y_true: The ground true label of each document.
      :param y_pred: The predicted scores of each document.
  
      :return: Normalized discounted cumulative gain.
      """
      dcg_metric = DiscountedCumulativeGain(
          k=self._k, threshold=self._threshold
      )
      idcg_val = dcg_metric(y_true, y_true)
      dcg_val = dcg_metric(y_true, y_pred)
      return dcg_val / idcg_val if idcg_val != 0 else 0
  
imports: import numpy
  from matchzoo.engine.base_metric import BaseMetric, sort_and_couple
  from .discounted_cumulative_gain import DiscountedCumulativeGain
label_desc: Use image node_id 3 for calling the NormalizedDiscountedCumulativeGain obj's underlying member method code with example usage: obj.__call__(y_true, y_pred) and returns: unknown