class_docstr: Computes NDCG (normalized discounted cumulative gain).
class_docstr_tok: ["Computes","NDCG","(","normalized","discounted","cumulative","gain",")","."]
docstr: Returns gains and example_weight sorted by prediction.
docstr_tok: ["Returns","gains","and","example_weight","sorted","by","prediction","."]
code: def _to_gains_example_weight(
      self, element: metric_types.StandardMetricInputs
  ) -> Tuple[np.ndarray, float]:
      """Returns gains and example_weight sorted by prediction."""
      _, predictions, example_weight = next(
          metric_util.to_label_prediction_example_weight(
              element,
              eval_config=self._eval_config,
              model_name=self._model_name,
              output_name=self._output_name,
              example_weighted=self._example_weighted,
              flatten=False,
              require_single_example_weight=True,
          )
      )  # pytype: disable=wrong-arg-types
      gains = util.get_by_keys(
          element.combined_features, [self._gain_key]
      )
      if gains.size != predictions.size:
          raise ValueError(
              "expected {} to be same size as predictions {} != {}: "
              "gains={}, metric_keys={}, "
              "StandardMetricInputs={}".format(
                  self._gain_key,
                  gains.size,
                  predictions.size,
                  gains,
                  self._metric_keys,
                  element,
              )
          )
      gains = gains.reshape(predictions.shape)
      # Ignore non-positive gains.
      if gains.max() <= 0:
          example_weight = 0.0
      return (
          gains[np.argsort(predictions)[::-1]],
          float(example_weight),
      )
  
imports: from typing import Dict, Iterable, List, Optional, Tuple, Union
  import apache_beam
  import numpy
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.metrics import metric_util
  from tensorflow_model_analysis.proto import config_pb2
  from tensorflow_model_analysis.utils import util
label_desc: Use image node_id 3 for calling the _NDCGCombiner obj's underlying member method code with example usage: obj._to_gains_example_weight(element) and returns: gains,  float