public class MAPTopNMetric extends AbstractMetric<MAPTopNMetric.Context,MAPTopNMetric.AggregateResult,MAPTopNMetric.UserResult>
The algorithm computed here is equivalent to Ben Hammer's Python implementation, as referenced by Kaggle.
Modifier and Type | Class and Description |
---|---|
static class |
MAPTopNMetric.AggregateResult |
static class |
MAPTopNMetric.Builder |
static class |
MAPTopNMetric.Context |
static class |
MAPTopNMetric.UserResult |
Constructor and Description |
---|
MAPTopNMetric(String pre,
String sfx,
int listSize,
ItemSelector candidates,
ItemSelector exclude,
ItemSelector goodItems)
Construct a new mean average precision top n metric
|
Modifier and Type | Method and Description |
---|---|
MAPTopNMetric.Context |
createContext(Attributed algo,
TTDataSet ds,
Recommender rec)
Create the context for an experimental condition (algorithm/data set pair).
|
MAPTopNMetric.UserResult |
doMeasureUser(TestUser user,
MAPTopNMetric.Context context)
Measure a user with typed results.
|
protected String |
getPrefix()
A prefix to be applied to column names.
|
protected String |
getSuffix()
A suffix to be applied to column names.
|
protected MAPTopNMetric.AggregateResult |
getTypedResults(MAPTopNMetric.Context context)
Get the typed results from an accumulator.
|
close, getColumnLabels, getResults, getUserColumnLabels, measureUser
public MAPTopNMetric(String pre, String sfx, int listSize, ItemSelector candidates, ItemSelector exclude, ItemSelector goodItems)
pre
- the prefix label for this evaluation, or null
for no prefix.sfx
- the suffix label for this evaluation, or null
for no suffix.listSize
- The number of recommendations to fetch.candidates
- The candidate selector, provides a list of items which can be recommendedexclude
- The exclude selector, provides a list of items which must not be recommended
(These items are removed from the candidate items to form the final candidate set)goodItems
- The list of items to consider "true positives", all other items will be treated
as "false positives".protected String getPrefix()
AbstractMetric
null
, this prefix will be applied and
separated with a period.getPrefix
in class AbstractMetric<MAPTopNMetric.Context,MAPTopNMetric.AggregateResult,MAPTopNMetric.UserResult>
protected String getSuffix()
AbstractMetric
null
, this suffix will be applied and
separated with a period.getSuffix
in class AbstractMetric<MAPTopNMetric.Context,MAPTopNMetric.AggregateResult,MAPTopNMetric.UserResult>
public MAPTopNMetric.Context createContext(Attributed algo, TTDataSet ds, Recommender rec)
Metric
algo
- The algorithm.ds
- The data set.rec
- The LensKit recommender, if applicable. This can be null for an external
algorithm that does not provide a LensKit recommender.Metric.measureUser(TestUser, Object)
. If
the metric does not accumulate any results, this method can return null
.public MAPTopNMetric.UserResult doMeasureUser(TestUser user, MAPTopNMetric.Context context)
AbstractMetric
doMeasureUser
in class AbstractMetric<MAPTopNMetric.Context,MAPTopNMetric.AggregateResult,MAPTopNMetric.UserResult>
user
- The user to measure.context
- The context.null
to emit NAs for the user.protected MAPTopNMetric.AggregateResult getTypedResults(MAPTopNMetric.Context context)
AbstractMetric
getTypedResults
in class AbstractMetric<MAPTopNMetric.Context,MAPTopNMetric.AggregateResult,MAPTopNMetric.UserResult>
context
- The context.null
to emit NAs.