class_docstr: Precision metric.
docstr: Calculate precision@k.
  
  Example:
      >>> y_true = [0, 0, 0, 1]
      >>> y_pred = [0.2, 0.4, 0.3, 0.1]
      >>> Precision(k=1)(y_true, y_pred)
      0.0
      >>> Precision(k=2)(y_true, y_pred)
      0.0
      >>> Precision(k=4)(y_true, y_pred)
      0.25
      >>> Precision(k=5)(y_true, y_pred)
      0.2
  
  :param y_true: The ground true label of each document.
  :param y_pred: The predicted scores of each document.
  :return: Precision @ k
  :raises: ValueError: len(r) must be >= k.
docstr_tok: ["Calculate","precision","@","k.","Example",":",">",">",">","y_true","=","[","0",",","0",",","0",",","1","]",">",">",">","y_pred","=","[","0.2",",","0.4",",","0.3",",","0.1","]",">",">",">","Precision","(","k=1",")","(","y_true",",","y_pred",")","0.0",">",">",">","Precision","(","k=2",")","(","y_true",",","y_pred",")","0.0",">",">",">","Precision","(","k=4",")","(","y_true",",","y_pred",")","0.25",">",">",">","Precision","(","k=5",")","(","y_true",",","y_pred",")","0.2",":","param","y_true",":","The","ground","true","label","of","each","document",".",":","param","y_pred",":","The","predicted","scores","of","each","document",".",":","return",":","Precision","@","k",":","raises",":","ValueError",":","len","(","r",")","must","be",">","=","k","."]
code: def __call__(self, y_true: np.array, y_pred: np.array) -> float:
      """
      Calculate precision@k.
  
      Example:
          >>> y_true = [0, 0, 0, 1]
          >>> y_pred = [0.2, 0.4, 0.3, 0.1]
          >>> Precision(k=1)(y_true, y_pred)
          0.0
          >>> Precision(k=2)(y_true, y_pred)
          0.0
          >>> Precision(k=4)(y_true, y_pred)
          0.25
          >>> Precision(k=5)(y_true, y_pred)
          0.2
  
      :param y_true: The ground true label of each document.
      :param y_pred: The predicted scores of each document.
      :return: Precision @ k
      :raises: ValueError: len(r) must be >= k.
      """
      if self._k <= 0:
          raise ValueError(
              f"k must be greater than 0." f"{self._k} received."
          )
      coupled_pair = sort_and_couple(y_true, y_pred)
      precision = 0.0
      for idx, (label, score) in enumerate(coupled_pair):
          if idx >= self._k:
              break
          if label > self._threshold:
              precision += 1.0
      return precision / self._k
  
imports: import numpy
  from matchzoo.engine.base_metric import BaseMetric, sort_and_couple
label_desc: Use image node_id 3 for calling the Precision obj's underlying member method code with example usage: obj.__call__(y_true, y_pred) and returns: unknown