org.mymedialite.eval.measures
Class PrecisionAndRecall

java.lang.Object
  extended by org.mymedialite.eval.measures.PrecisionAndRecall

public class PrecisionAndRecall
extends java.lang.Object

Precision and recall at different positions in the list. Precision and recall are classical evaluation measures from information retrieval. This class contains methods for computing precision and recall up to different positions in the recommendation list, and the average precision (AP). The mean of the AP over different users is called mean average precision (MAP)


Method Summary
static double AP(java.util.List<java.lang.Integer> ranked_items, java.util.Collection<java.lang.Integer> correct_items, java.util.Collection<java.lang.Integer> ignore_items)
          Compute the average precision (AP) of a list of ranked items.
static int hitsAt(java.util.List<java.lang.Integer> ranked_items, java.util.Collection<java.lang.Integer> correct_items, java.util.Collection<java.lang.Integer> ignore_items, int n)
          Compute the number of hits until position N of a list of ranked items.
static double precisionAt(java.util.List<java.lang.Integer> ranked_items, java.util.Collection<java.lang.Integer> correct_items, java.util.Collection<java.lang.Integer> ignore_items, int n)
          Compute the precision@N of a list of ranked items.
static java.util.HashMap<java.lang.Integer,java.lang.Double> precisionAt(java.util.List<java.lang.Integer> ranked_items, java.util.Collection<java.lang.Integer> correct_items, java.util.Collection<java.lang.Integer> ignore_items, int[] ns)
          Compute the precision@N of a list of ranked items at several N.
static double precisionAt(java.util.List<java.lang.Integer> ranked_items, java.util.Collection<java.lang.Integer> correct_items, int n)
          Compute the precision@N of a list of ranked items.
static double recallAt(java.util.List<java.lang.Integer> ranked_items, java.util.Collection<java.lang.Integer> correct_items, java.util.Collection<java.lang.Integer> ignore_items, int n)
          Compute the recall@N of a list of ranked items.
static java.util.HashMap<java.lang.Integer,java.lang.Double> recallAt(java.util.List<java.lang.Integer> ranked_items, java.util.Collection<java.lang.Integer> correct_items, java.util.Collection<java.lang.Integer> ignore_items, int[] ns)
          Compute the recall@N of a list of ranked items at several N.
static double recallAt(java.util.List<java.lang.Integer> ranked_items, java.util.Collection<java.lang.Integer> correct_items, int n)
          Compute the recall@N of a list of ranked items.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

AP

public static double AP(java.util.List<java.lang.Integer> ranked_items,
                        java.util.Collection<java.lang.Integer> correct_items,
                        java.util.Collection<java.lang.Integer> ignore_items)
Compute the average precision (AP) of a list of ranked items.

Parameters:
ranked_items - a list of ranked item IDs, the highest-ranking item first
correct_items - a collection of positive/correct item IDs
ignore_items - a collection of item IDs which should be ignored for the evaluation
Returns:
the AP for the given list

precisionAt

public static java.util.HashMap<java.lang.Integer,java.lang.Double> precisionAt(java.util.List<java.lang.Integer> ranked_items,
                                                                                java.util.Collection<java.lang.Integer> correct_items,
                                                                                java.util.Collection<java.lang.Integer> ignore_items,
                                                                                int[] ns)
Compute the precision@N of a list of ranked items at several N.

Parameters:
ranked_items - a list of ranked item IDs, the highest-ranking item first
correct_items - a collection of positive/correct item IDs
ignore_items - a collection of item IDs which should be ignored for the evaluation
ns - the cutoff positions in the list
Returns:
the precision@N for the given data at the different positions N

precisionAt

public static double precisionAt(java.util.List<java.lang.Integer> ranked_items,
                                 java.util.Collection<java.lang.Integer> correct_items,
                                 int n)
Compute the precision@N of a list of ranked items.

Parameters:
ranked_items - a list of ranked item IDs, the highest-ranking item first
correct_items - a collection of positive/correct item IDs
n - the cutoff position in the list
Returns:
the precision@N for the given data

precisionAt

public static double precisionAt(java.util.List<java.lang.Integer> ranked_items,
                                 java.util.Collection<java.lang.Integer> correct_items,
                                 java.util.Collection<java.lang.Integer> ignore_items,
                                 int n)
Compute the precision@N of a list of ranked items.

Parameters:
ranked_items - a list of ranked item IDs, the highest-ranking item first
correct_items - a collection of positive/correct item IDs
ignore_items - a collection of item IDs which should be ignored for the evaluation
n - the cutoff position in the list
Returns:
the precision@N for the given data

recallAt

public static java.util.HashMap<java.lang.Integer,java.lang.Double> recallAt(java.util.List<java.lang.Integer> ranked_items,
                                                                             java.util.Collection<java.lang.Integer> correct_items,
                                                                             java.util.Collection<java.lang.Integer> ignore_items,
                                                                             int[] ns)
Compute the recall@N of a list of ranked items at several N.

Parameters:
ranked_items - a list of ranked item IDs, the highest-ranking item first
correct_items - a collection of positive/correct item IDs
ignore_items - a collection of item IDs which should be ignored for the evaluation
ns - the cutoff positions in the list
Returns:
the recall@N for the given data at the different positions N

recallAt

public static double recallAt(java.util.List<java.lang.Integer> ranked_items,
                              java.util.Collection<java.lang.Integer> correct_items,
                              int n)
Compute the recall@N of a list of ranked items.

Parameters:
ranked_items - a list of ranked item IDs, the highest-ranking item first
correct_items - a collection of positive/correct item IDs
n - the cutoff position in the list
Returns:
the recall@N for the given data

recallAt

public static double recallAt(java.util.List<java.lang.Integer> ranked_items,
                              java.util.Collection<java.lang.Integer> correct_items,
                              java.util.Collection<java.lang.Integer> ignore_items,
                              int n)
Compute the recall@N of a list of ranked items.

Parameters:
ranked_items - a list of ranked item IDs, the highest-ranking item first
correct_items - a collection of positive/correct item IDs
ignore_items - a collection of item IDs which should be ignored for the evaluation
n - the cutoff position in the list
Returns:
the recall@N for the given data

hitsAt

public static int hitsAt(java.util.List<java.lang.Integer> ranked_items,
                         java.util.Collection<java.lang.Integer> correct_items,
                         java.util.Collection<java.lang.Integer> ignore_items,
                         int n)
Compute the number of hits until position N of a list of ranked items.

Parameters:
ranked_items - a list of ranked item IDs, the highest-ranking item first
correct_items - a collection of positive/correct item IDs
ignore_items - a collection of item IDs which should be ignored for the evaluation
n - the cutoff position in the list
Returns:
the hits@N for the given data