code: def precision(recs, truth, k=None):
      """
      Compute recommendation precision.  This is computed as:
  
      .. math::
          \\frac{|L \\cap I_u^{\\mathrm{test}}|}{|L|}
  
      In the uncommon case that ``k`` is specified and ``len(recs) < k``, this metric uses
      ``len(recs)`` as the denominator.
  
      This metric has a bulk implementation.
      """
      if k is not None:
          recs = recs.iloc[:k]
  
      nrecs = len(recs)
      if nrecs == 0:
          return None
  
      ngood = recs["item"].isin(truth.index).sum()
      return ngood / nrecs
  
file_path: lkpy/lenskit/metrics/topn.py
imports: import logging
  import warnings
  import numpy
  import pandas
label_desc: Use image node_id 2 for calling a global function with example usage: precision(recs, truth, k) and returns: unknown, None