code: def average_precision(r, cut):
      """Score is average precision (area under PR curve)
      Relevance is binary (nonzero is relevant).
      Returns:
          Average precision
      """
      r = np.asarray(r)
      out = [precision_at_k(r, k + 1) for k in range(cut) if r[k]]
      if not out:
          return 0.0
      return np.sum(out) / float(min(cut, np.sum(r)))
  
file_path: dgl/examples/pytorch/NGCF/NGCF/utility/metrics.py
imports: import numpy
  from sklearn.metrics import roc_auc_score
label_desc: Use image node_id 3 for calling a global function with example usage: average_precision(r, cut) and returns: unknown, int