lenskit.metrics.Metric#
- class lenskit.metrics.Metric#
Bases:
ABC
Base class for LensKit metrics. Individual metrics need to implement a sub-interface, such as
ListMetric
and/orGlobalMetric
.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.
- Stability:
- Full (see Stability Levels).
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).- __init__()#
Methods
__init__
()extract_list_metrics
(data, /)Extract per-list metric(s) from intermediate measurement data.
measure_list
(output, test, /)Compute measurements for a single list.
summarize
(values, /)Aggregate intermediate values into summary statistics.
Attributes
The metric's default label in output.
- property label: str#
The metric’s default label in output. The base implementation returns the class name by default.
- abstractmethod measure_list(output, test, /)#
Compute measurements for a single list.
- extract_list_metrics(data, /)#
Extract per-list metric(s) from intermediate measurement data.