public class NDCGPredictMetric extends PredictMetric<MeanAccumulator>
Evaluate a recommender’s predictions with normalized discounted cumulative gain.
This is a prediction evaluator that uses base-2 nDCG to evaluate recommender accuracy. The items are ordered by predicted preference and the nDCG is computed using the user’s real rating as the gain for each item. Doing this only over the queried items, rather than in the general recommend condition, avoids penalizing recommenders for recommending items that would be better if the user had known about them and provided ratings (e.g., for doing their job).
nDCG is computed per-user and then averaged over all users.
Modifier and Type | Class and Description |
---|---|
static class |
NDCGPredictMetric.Spec
Specification for configuring nDCG metrics.
|
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_COLUMN |
Constructor and Description |
---|
NDCGPredictMetric()
Create a new log_2 nDCG metric with column name “Predict.nDCG”.
|
NDCGPredictMetric(Discount disc)
Create a new nDCG metric with column name “Predict.nDCG”.
|
NDCGPredictMetric(Discount disc,
String name)
Create a new nDCG metric.
|
NDCGPredictMetric(NDCGPredictMetric.Spec spec)
Construct a predict metric from a spec.
|
Modifier and Type | Method and Description |
---|---|
MeanAccumulator |
createContext(AlgorithmInstance algorithm,
DataSet dataSet,
Recommender recommender)
Create the context for an experimental condition (algorithm/data set pair).
|
MetricResult |
getAggregateMeasurements(MeanAccumulator context)
Get the aggregate results from an accumulator.
|
MetricResult |
measureUser(TestUser user,
ResultMap predictions,
MeanAccumulator context)
Measure a single result.
|
getAggregateColumnLabels, getColumnLabels, getRequiredRoots
public static final String DEFAULT_COLUMN
public NDCGPredictMetric()
Create a new log_2 nDCG metric with column name “Predict.nDCG”.
public NDCGPredictMetric(Discount disc)
Create a new nDCG metric with column name “Predict.nDCG”.
disc
- The discount.public NDCGPredictMetric(NDCGPredictMetric.Spec spec)
Construct a predict metric from a spec.
spec
- The metric spec.@Nullable public MeanAccumulator 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<MeanAccumulator>
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(MeanAccumulator context)
Metric
Get the aggregate results from an accumulator. The default implementation returns MetricResult.empty()
.
getAggregateMeasurements
in class Metric<MeanAccumulator>
context
- The context for an experimental condition.@Nonnull public MetricResult measureUser(TestUser user, ResultMap predictions, MeanAccumulator context)
PredictMetric
Measure a single result. The result may come from either prediction or recommendation.
measureUser
in class PredictMetric<MeanAccumulator>
user
- The user’s test data.predictions
- The predictions.