mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sro...@apache.org
Subject svn commit: r1213930 - in /mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste: eval/IRStatistics.java impl/eval/GenericRecommenderIRStatsEvaluator.java impl/eval/IRStatisticsImpl.java
Date Tue, 13 Dec 2011 21:08:56 GMT
Author: srowen
Date: Tue Dec 13 21:08:56 2011
New Revision: 1213930

URL: http://svn.apache.org/viewvc?rev=1213930&view=rev
Log:
MAHOUT-925 Add basic idea of 'reach'

Modified:
    mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/eval/IRStatistics.java
    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/eval/IRStatistics.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/eval/IRStatistics.java?rev=1213930&r1=1213929&r2=1213930&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/eval/IRStatistics.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/eval/IRStatistics.java Tue
Dec 13 21:08:56 2011
@@ -72,4 +72,9 @@ public interface IRStatistics {
    */
   double getNormalizedDiscountedCumulativeGain();
   
+  /**
+   * @return the fraction of all users for whom recommendations could be produced
+   */
+  double getReach();
+  
 }

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=1213930&r1=1213929&r2=1213930&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
Tue Dec 13 21:08:56 2011
@@ -97,6 +97,8 @@ public final class GenericRecommenderIRS
     RunningAverage recall = new FullRunningAverage();
     RunningAverage fallOut = new FullRunningAverage();
     RunningAverage nDCG = new FullRunningAverage();
+    int numUsersRecommendedFor = 0;
+    int numUsersWithRecommendations = 0;
 
     LongPrimitiveIterator it = dataModel.getUserIDs();
     while (it.hasNext()) {
@@ -194,6 +196,12 @@ public final class GenericRecommenderIRS
         }
       }
       nDCG.addDatum(cumulativeGain / idealizedGain);
+      
+      // Reach
+      numUsersRecommendedFor++;
+      if (numRecommendedItems > 0) {
+        numUsersWithRecommendations++;
+      }
 
       long end = System.currentTimeMillis();
 
@@ -203,7 +211,14 @@ public final class GenericRecommenderIRS
       });
     }
 
-    return new IRStatisticsImpl(precision.getAverage(), recall.getAverage(), fallOut.getAverage(),
nDCG.getAverage());
+    double reach = (double) numUsersWithRecommendations / (double) numUsersRecommendedFor;
+
+    return new IRStatisticsImpl(
+        precision.getAverage(),
+        recall.getAverage(),
+        fallOut.getAverage(),
+        nDCG.getAverage(),
+        reach);
   }
   
   private static void processOtherUser(long id,

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=1213930&r1=1213929&r2=1213930&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
Tue Dec 13 21:08:56 2011
@@ -29,16 +29,19 @@ public final class IRStatisticsImpl impl
   private final double recall;
   private final double fallOut;
   private final double ndcg;
+  private final double reach;
   
-  IRStatisticsImpl(double precision, double recall, double fallOut, double ndcg) {
+  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(fallOut >= 0.0 && fallOut <= 1.0, "Illegal
nDCG: " + ndcg);
+    Preconditions.checkArgument(reach >= 0.0 && reach <= 1.0, "Illegal reach:
" + ndcg);
     this.precision = precision;
     this.recall = recall;
     this.fallOut = fallOut;
     this.ndcg = ndcg;
+    this.reach = reach;
   }
   
   @Override
@@ -71,11 +74,16 @@ public final class IRStatisticsImpl impl
   public double getNormalizedDiscountedCumulativeGain() {
     return ndcg;
   }
+
+  @Override
+  public double getReach() {
+	  return reach;
+  }
   
   @Override
   public String toString() {
     return "IRStatisticsImpl[precision:" + precision + ",recall:" + recall + ",fallOut:"
-        + fallOut + ",nDCG:" + ndcg + ']';
+        + fallOut + ",nDCG:" + ndcg + ",reach:" + reach + ']';
   }
   
 }



Mime
View raw message