public class TopNMRRMetric extends ListOnlyTopNMetric<TopNMRRMetric.Context>
Compute the mean reciprocal rank.
This metric is registered with the type name mrr
. It has two configuration parameters:
suffix
goodItems
Modifier and Type | Class and Description |
---|---|
static class |
TopNMRRMetric.AggregateResult |
static class |
TopNMRRMetric.Context |
static class |
TopNMRRMetric.UserResult |
Constructor and Description |
---|
TopNMRRMetric()
Construct a new MRR metric using the user’s test items as good.
|
TopNMRRMetric(ItemSelector goodItems,
java.lang.String sfx)
Construct a new recall and precision top n metric
|
TopNMRRMetric(PRMetricSpec spec)
Construct an MRR metric from a spec.
|
Modifier and Type | Method and Description |
---|---|
TopNMRRMetric.Context |
createContext(AlgorithmInstance algorithm,
DataSet dataSet,
RecommenderEngine engine)
Create the context for an experimental condition (algorithm/data set pair).
|
MetricResult |
getAggregateMeasurements(TopNMRRMetric.Context context)
Get the aggregate results from an accumulator.
|
MetricResult |
measureUser(Recommender rec,
TestUser user,
int targetLength,
LongList recommendations,
TopNMRRMetric.Context context)
Measurement method that only uses the recommend list.
|
measureUser
getAggregateColumnLabels, getColumnLabels, getRequiredRoots
public TopNMRRMetric()
Construct a new MRR metric using the user’s test items as good.
public TopNMRRMetric(PRMetricSpec spec)
Construct an MRR metric from a spec.
spec
- The metric speclpublic TopNMRRMetric(ItemSelector goodItems, java.lang.String sfx)
Construct a new recall and precision top n metric
goodItems
- The list of items to consider “true positives”, all other items will be treated as “false positives”.sfx
- A suffix to append to the metric.@Nullable public TopNMRRMetric.Context createContext(AlgorithmInstance algorithm, DataSet dataSet, RecommenderEngine engine)
Metric
Create the context for an experimental condition (algorithm/data set pair). The default implementation returns null
.
Note: Contexts must be thread-safe, in that multiple concurrent calls to the appropriate user-measurement function with the same context must be safe. This can be handled either by the context itself, or by the user-measurement function.
createContext
in class Metric<TopNMRRMetric.Context>
algorithm
- The algorithm.dataSet
- The data set.engine
- The LensKit recommender engine, if applicable. This can be null for an external algorithm that does not provide a LensKit recommender.null
.@Nonnull public MetricResult getAggregateMeasurements(TopNMRRMetric.Context context)
Metric
Get the aggregate results from an accumulator. The default implementation returns MetricResult.empty()
.
getAggregateMeasurements
in class Metric<TopNMRRMetric.Context>
context
- The context for an experimental condition.@Nonnull public MetricResult measureUser(Recommender rec, TestUser user, int targetLength, LongList recommendations, TopNMRRMetric.Context context)
ListOnlyTopNMetric
Measurement method that only uses the recommend list.
Thread Safety: This method may be called concurrently by multiple threads with the same recommender and context.
measureUser
in class ListOnlyTopNMetric<TopNMRRMetric.Context>
rec
- The recommender used to recommend for this user.user
- The user.targetLength
- The target list length.recommendations
- The list of recommendations.context
- The context.