Author: srowen
Date: Mon Dec 3 20:13:29 2012
New Revision: 1416651
URL: http://svn.apache.org/viewvc?rev=1416651&view=rev
Log:
Allow NaN as metric result value and make some small cosmetic code changes for
clarity
Modified:
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/eval/GenericRecommenderIRStatsEvaluator.java
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/eval/IRStatisticsImpl.java
Modified:
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/eval/GenericRecommenderIRStatsEvaluator.java
URL:
http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/eval/GenericRecommenderIRStatsEvaluator.java?rev=1416651&r1=1416650&r2=1416651&view=diff
==============================================================================
---
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/eval/GenericRecommenderIRStatsEvaluator.java
(original)
+++
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/eval/GenericRecommenderIRStatsEvaluator.java
Mon Dec 3 20:13:29 2012
@@ -141,7 +141,7 @@ public final class GenericRecommenderIRS
continue; // Oops we excluded all prefs for the user -- just move on
}
- int size = relevantItemIDs.size() +
trainingModel.getItemIDsFromUser(userID).size();
+ int size = numRelevantItems +
trainingModel.getItemIDsFromUser(userID).size();
if (size < 2 * at) {
// Really not enough prefs to meaningfully evaluate this user
continue;
@@ -177,7 +177,7 @@ public final class GenericRecommenderIRS
// In computing, assume relevant IDs have relevance 1 and others 0
double cumulativeGain = 0.0;
double idealizedGain = 0.0;
- for (int i = 0; i < recommendedItems.size(); i++) {
+ for (int i = 0; i < numRecommendedItems; i++) {
RecommendedItem item = recommendedItems.get(i);
double discount = 1.0 / log2(i + 2.0); // Classical formulation says
log(i+1), but i is 0-based here
if (relevantItemIDs.contains(item.getItemID())) {
@@ -187,7 +187,7 @@ public final class GenericRecommenderIRS
// Ideally results would be ordered with all relevant ones first, so
this theoretical
// ideal list starts with number of relevant items equal to the total
number of relevant items
- if (i < relevantItemIDs.size()) {
+ if (i < numRelevantItems) {
idealizedGain += discount;
}
}
@@ -204,19 +204,17 @@ public final class GenericRecommenderIRS
long end = System.currentTimeMillis();
log.info("Evaluated with user {} in {}ms", userID, end - start);
- log.info("Precision/recall/fall-out/nDCG: {} / {} / {} / {}", new
Object[] {
- precision.getAverage(), recall.getAverage(), fallOut.getAverage(),
nDCG.getAverage()
- });
+ log.info("Precision/recall/fall-out/nDCG/reach: {} / {} / {} / {} / {}",
+ precision.getAverage(), recall.getAverage(),
fallOut.getAverage(), nDCG.getAverage(),
+ (double) numUsersWithRecommendations / (double)
numUsersRecommendedFor);
}
- double reach = (double) numUsersWithRecommendations / (double)
numUsersRecommendedFor;
-
return new IRStatisticsImpl(
precision.getAverage(),
recall.getAverage(),
fallOut.getAverage(),
nDCG.getAverage(),
- reach);
+ (double) numUsersWithRecommendations / (double)
numUsersRecommendedFor);
}
private static double computeThreshold(PreferenceArray prefs) {
Modified:
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/eval/IRStatisticsImpl.java
URL:
http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/eval/IRStatisticsImpl.java?rev=1416651&r1=1416650&r2=1416651&view=diff
==============================================================================
---
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/eval/IRStatisticsImpl.java
(original)
+++
mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/eval/IRStatisticsImpl.java
Mon Dec 3 20:13:29 2012
@@ -32,11 +32,11 @@ public final class IRStatisticsImpl impl
private final double reach;
IRStatisticsImpl(double precision, double recall, double fallOut, double
ndcg, double reach) {
- Preconditions.checkArgument(precision >= 0.0 && precision <= 1.0, "Illegal
precision: " + precision);
- Preconditions.checkArgument(recall >= 0.0 && recall <= 1.0, "Illegal
recall: " + recall);
- Preconditions.checkArgument(fallOut >= 0.0 && fallOut <= 1.0, "Illegal
fallOut: " + fallOut);
- Preconditions.checkArgument(ndcg >= 0.0 && ndcg <= 1.0, "Illegal nDCG: " +
ndcg);
- Preconditions.checkArgument(reach >= 0.0 && reach <= 1.0, "Illegal reach:
" + reach);
+ Preconditions.checkArgument(Double.isNaN(precision) || (precision >= 0.0
&& precision <= 1.0), "Illegal precision: " + precision);
+ Preconditions.checkArgument(Double.isNaN(recall) || (recall >= 0.0 &&
recall <= 1.0), "Illegal recall: " + recall);
+ Preconditions.checkArgument(Double.isNaN(fallOut) || (fallOut >= 0.0 &&
fallOut <= 1.0), "Illegal fallOut: " + fallOut);
+ Preconditions.checkArgument(Double.isNaN(ndcg) || (ndcg >= 0.0 && ndcg <=
1.0), "Illegal nDCG: " + ndcg);
+ Preconditions.checkArgument(Double.isNaN(reach) || (reach >= 0.0 && reach
<= 1.0), "Illegal reach: " + reach);
this.precision = precision;
this.recall = recall;
this.fallOut = fallOut;