public class NDCGPredictMetric extends PredictMetric<org.apache.commons.math3.stat.descriptive.moment.Mean>
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 java.lang.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,
java.lang.String name)
Create a new nDCG metric.
|
NDCGPredictMetric(NDCGPredictMetric.Spec spec)
Construct a predict metric from a spec.
|
Modifier and Type | Method and Description |
---|---|
org.apache.commons.math3.stat.descriptive.moment.Mean |
createContext(AlgorithmInstance algorithm,
DataSet dataSet,
RecommenderEngine engine)
Create the context for an experimental condition (algorithm/data set pair).
|
MetricResult |
getAggregateMeasurements(org.apache.commons.math3.stat.descriptive.moment.Mean context)
Get the aggregate results from an accumulator.
|
MetricResult |
measureUser(TestUser user,
ResultMap predictions,
org.apache.commons.math3.stat.descriptive.moment.Mean context)
Measure a single result.
|
getAggregateColumnLabels, getColumnLabels, getRequiredRoots
public static final java.lang.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.public NDCGPredictMetric(Discount disc, java.lang.String name)
Create a new nDCG metric.
disc
- The discount.name
- The column name.@Nullable public org.apache.commons.math3.stat.descriptive.moment.Mean 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<org.apache.commons.math3.stat.descriptive.moment.Mean>
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(org.apache.commons.math3.stat.descriptive.moment.Mean context)
Metric
Get the aggregate results from an accumulator. The default implementation returns MetricResult.empty()
.
getAggregateMeasurements
in class Metric<org.apache.commons.math3.stat.descriptive.moment.Mean>
context
- The context for an experimental condition.@Nonnull public MetricResult measureUser(TestUser user, ResultMap predictions, org.apache.commons.math3.stat.descriptive.moment.Mean context)
PredictMetric
Measure a single result. The result may come from either prediction or recommendation.
Thread Safety: This method may be called concurrently by multiple threads with the same recommender and context.
measureUser
in class PredictMetric<org.apache.commons.math3.stat.descriptive.moment.Mean>
user
- The user’s test data.predictions
- The predictions.