lenskit.metrics.Metric ====================== .. py:class:: lenskit.metrics.Metric[L, S: MetricResult] :canonical: lenskit.metrics._base.Metric Bases: :py:obj:`abc.ABC`, :py:obj:`lenskit.data.accum.AccumulatorFactory`\ [\ :py:obj:`L`\ , :py:obj:`S`\ ] Base class for LensKit metrics. Simple metrics that compute a single value for a list should extend :class:`ListMetric`. This class defines the interface for metrics. Subclasses should implement the `measure_list` method to compute metric values. The `summarize()` method has a default implementation that computes the mean of the per-list metric values, but subclasses can override it to provide more appropriate summary statistics. .. versionchanged:: 2026.1 Removed the ``summarize`` method in favor of requiring metrics to implement :class:`AccumulatorFactory` to allow metric-controlled accumulation. :Stability: Full .. note:: For simplicity in the analysis code, you cannot simply implement the properties of this class on an arbitrary class in order to implement a metric with all available behavior such as labeling and defaults; you must actually extend this class. This requirement may be relaxed in the future. The default value to impute when computing statistics over missing values. If ``None``, no imputation is done (necessary for metrics like RMSE, where the missing value is theoretically infinite). .. py:property:: label :type: str The metric's default label in output. The base implementation returns the class name by default. .. py:method:: __str__() .. py:method:: measure_list(output, test, /) :abstractmethod: Compute measurements for a single list. :returns: - A float for simple metrics - Intermediate data for decomposed metrics - A dict mapping metric names to values for multi-metric classes .. py:method:: extract_list_metrics(data, /) Extract per-list metric(s) from intermediate measurement data. :returns: - A float for simple metrics - A dict mapping metric names to values for multi-metric classes - None if no per-list metrics are available .. py:method:: create_accumulator() :abstractmethod: Creaet an accumulator to aggregate per-list measurements into summary metrics. Each result from :meth:`measure_list` is passed to :meth:`Accumulator.add`.