class_docstr: Compute one or more top-N metrics over recommendation lists.
  
  This method groups the recommendations by the specified columns,
  and computes the metric over each group.  The default set of grouping
  columns is all columns *except* the following:
  
  * ``item``
  * ``rank``
  * ``score``
  * ``rating``
  
  The truth frame, ``truth``, is expected to match over (a subset of) the
  grouping columns, and contain at least an ``item`` column.  If it also
  contains a ``rating`` column, that is used as the users' rating for
  metrics that require it; otherwise, a rating value of 1 is assumed.
  
  Args:
      group_cols(list):
          The columns to group by, or ``None`` to use the default.
docstr: Add a metric to the analysis.
  
  A metric is a function of two arguments: the a single group of the recommendation
  frame, and the corresponding truth frame.  The truth frame will be indexed by
  item ID.  The recommendation frame will be in the order in the data.  Many metrics
  are defined in :mod:`lenskit.metrics.topn`; they are re-exported from
  :mod:`lenskit.topn` for convenience.
  
  Args:
      metric: The metric to compute.
      name: The name to assign the metric. If not provided, the function name is used.
      **kwargs: Additional arguments to pass to the metric.
docstr_tok: ["Add","a","metric","to","the","analysis",".","A","metric","is","a","function","of","two","arguments",":","the","a","single","group","of","the","recommendation","frame",",","and","the","corresponding","truth","frame",".","The","truth","frame","will","be","indexed","by","item","ID",".","The","recommendation","frame","will","be","in","the","order","in","the","data",".","Many","metrics","are","defined","in",":","mod",":","`","lenskit.metrics.topn","`",";","they","are","re-exported","from",":","mod",":","`","lenskit.topn","`","for","convenience",".","Args",":","metric",":","The","metric","to","compute",".","name",":","The","name","to","assign","the","metric",".","If","not","provided",",","the","function","name","is","used",".","*","*","kwargs",":","Additional","arguments","to","pass","to","the","metric","."]
code: def add_metric(self, metric, *, name=None, **kwargs):
      """
      Add a metric to the analysis.
  
      A metric is a function of two arguments: the a single group of the recommendation
      frame, and the corresponding truth frame.  The truth frame will be indexed by
      item ID.  The recommendation frame will be in the order in the data.  Many metrics
      are defined in :mod:`lenskit.metrics.topn`; they are re-exported from
      :mod:`lenskit.topn` for convenience.
  
      Args:
          metric: The metric to compute.
          name: The name to assign the metric. If not provided, the function name is used.
          **kwargs: Additional arguments to pass to the metric.
      """
      if name is None:
          name = metric.__name__
  
      self.metrics.append((metric, name, kwargs))
  
file_path: lkpy/lenskit/topn.py
imports: import logging
  import functools
  import numpy
  import pandas
  from .metrics.topn import *
  from .util import Stopwatch
label_desc: Use image node_id 2 for calling the RecListAnalysis obj's underlying member method code with example usage: obj.add_metric(metric) without return types