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:
suffixgoodItems| 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,
java.lang.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,
RecommenderEngine engine)
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(Recommender rec,
TestUser user,
int targetLength,
LongList recs,
TopNMAPMetric.Context context)
Measurement method that only uses the recommend list.
|
measureUsergetAggregateColumnLabels, getColumnLabels, getRequiredRootspublic 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, java.lang.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, RecommenderEngine engine)
MetricCreate 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<TopNMAPMetric.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(TopNMAPMetric.Context context)
MetricGet 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(Recommender rec, TestUser user, int targetLength, LongList recs, TopNMAPMetric.Context context)
ListOnlyTopNMetricMeasurement 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<TopNMAPMetric.Context>rec - The recommender used to recommend for this user.user - The user.targetLength - The target list length.recs - The list of recommendations.context - The context.