lenskit.metrics.MeasurementCollector#
- class lenskit.metrics.MeasurementCollector#
Collect metric measurements over multiple recommendation lists.
This class automates collecting metric values and translating accumulated summaries into data frames. See Collecting and Aggregating Metrics for a more detailed discussion of how to use this class.
Changed in version 2026.1:
metricsis no longer publicly exposed as a list of wrappers.- Stability:
- Caller (see Stability Levels).
- empty_copy()#
Create a copy of this measurement collector with no collected data.
- reset()#
Remove all collected data from this collector.
- add_metric(metric, label=None)#
Add a metric to this accumulator.
- Parameters:
metric (lenskit.metrics._base.Metric | lenskit.metrics._base.MetricFunction | type[lenskit.metrics._base.Metric]) – The metric to add.
label (str | None) – The label to use for the metric’s results. If unset, obtains from the metric.
- add_list_measurement(output, test, **keys)#
Measure a single list and accumulate the intermediate results.
- Parameters:
output (lenskit.data.ItemList) – The recommendation list to measure.
test (lenskit.data.ItemList) – The ground truth test data.
**keys (Any) – Identifying keys for this list (e.g., user_id).
- add_collection_measurements(outputs, test, **keys)#
Measure a collection of item lists against truth data.
- Parameters:
outputs (lenskit.data.ItemListCollection) – The item lists to measure.
test (lenskit.data.ItemListCollection) – Test data item lists.
keys (Any) – Additional keys to label measurements from these lists.
- measure_run(outputs, test)#
Convenience method to measure a set of recommendations and return the results.
The measurement collector must be empty. The provided lists are measured, but their measurements are not added to this collector.
This method is intended to free up users from the need to manage collector state.
- Parameters:
outputs (lenskit.data.ItemListCollection)
- Return type:
- list_metrics()#
Get the per-list metric results as a DataFrame.
- Returns:
DataFrame with one row per list and one column per metric.
- Return type: