public class TopNMAPMetric extends ListOnlyTopNMetric<TopNMAPMetric.Context>
Compute the mean average precision.
The algorithm computed here is equivalent to Ben Hammer’s Python implementation, as referenced by Kaggle.
This metric is registered under the name map
. It has two configuration parameters:
suffix
goodItems
Modifier and Type | Class and Description |
---|---|
static class |
TopNMAPMetric.AggregateResult |
static class |
TopNMAPMetric.Context |
static class |
TopNMAPMetric.UserResult |
Constructor and Description |
---|
TopNMAPMetric()
Construct a new MAP metric with the user’s test items as good.
|
TopNMAPMetric(ItemSelector good,
String sfx)
Construct a new mean average precision top n metric
|
TopNMAPMetric(PRMetricSpec spec)
Create a metric from a spec.
|
Modifier and Type | Method and Description |
---|---|
TopNMAPMetric.Context |
createContext(AlgorithmInstance algorithm,
DataSet dataSet,
Recommender recommender)
Create the context for an experimental condition (algorithm/data set pair).
|
MetricResult |
getAggregateMeasurements(TopNMAPMetric.Context context)
Get the aggregate results from an accumulator.
|
MetricResult |
measureUser(TestUser user,
int targetLength,
LongList recs,
TopNMAPMetric.Context context)
Measurement method that only uses the recommend list.
|
measureUser
getAggregateColumnLabels, getColumnLabels, getRequiredRoots
public TopNMAPMetric()
Construct a new MAP metric with the user’s test items as good.
public TopNMAPMetric(PRMetricSpec spec)
Create a metric from a spec.
spec
- The specification.public TopNMAPMetric(ItemSelector good, String sfx)
Construct a new mean average precision top n metric
sfx
- the suffix label for this evaluation, or null
for no suffix.good
- The list of items to consider “true positives”, all other items will be treated as “false positives”.@Nullable public TopNMAPMetric.Context createContext(AlgorithmInstance algorithm, DataSet dataSet, Recommender recommender)
Metric
Create the context for an experimental condition (algorithm/data set pair). The default implementation returns null
.
createContext
in class Metric<TopNMAPMetric.Context>
algorithm
- The algorithm.dataSet
- The data set.recommender
- The LensKit recommender, if applicable. This can be null for an external algorithm that does not provide a LensKit recommender.null
.@Nonnull public MetricResult getAggregateMeasurements(TopNMAPMetric.Context context)
Metric
Get the aggregate results from an accumulator. The default implementation returns MetricResult.empty()
.
getAggregateMeasurements
in class Metric<TopNMAPMetric.Context>
context
- The context for an experimental condition.@Nonnull public MetricResult measureUser(TestUser user, int targetLength, LongList recs, TopNMAPMetric.Context context)
ListOnlyTopNMetric
Measurement method that only uses the recommend list.
measureUser
in class ListOnlyTopNMetric<TopNMAPMetric.Context>
user
- The user.targetLength
- The target list length.recs
- The list of recommendations.context
- The context.