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: metrics is no longer publicly exposed as a list of wrappers.

Stability:
Caller (see Stability Levels).
key_fields: list[str]#

Columns naming the keys of measured lists.

empty_copy()#

Create a copy of this measurement collector with no collected data.

reset()#

Remove all collected data from this collector.

property metric_names: list[str]#

Get the list of metric names.

Return type:

list[str]

add_metric(metric, label=None)#

Add a metric to this accumulator.

Parameters:
add_list_measurement(output, test, **keys)#

Measure a single list and accumulate the intermediate results.

Parameters:
add_collection_measurements(outputs, test, **keys)#

Measure a collection of item lists against truth data.

Parameters:
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:
Return type:

RunMetrics

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:

pandas.DataFrame

summary_metrics()#

Compute summary statistics by calling each metric’s summarize() method.

Note

This returns overall summaries — summaries are not collected separately for different calls to measure_collection().

Returns:

A dictionary with flattened metric results.

Return type:

dict[str, float]