mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sro...@apache.org
Subject svn commit: r833675 - in /lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste: eval/ impl/eval/
Date Sat, 07 Nov 2009 13:27:56 GMT
Author: srowen
Date: Sat Nov  7 13:27:55 2009
New Revision: 833675

URL: http://svn.apache.org/viewvc?rev=833675&view=rev
Log:
MAHOUT-196

Modified:
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/eval/RecommenderEvaluator.java
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/eval/AbstractDifferenceRecommenderEvaluator.java
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/eval/AverageAbsoluteDifferenceRecommenderEvaluator.java
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/eval/RMSRecommenderEvaluator.java

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/eval/RecommenderEvaluator.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/eval/RecommenderEvaluator.java?rev=833675&r1=833674&r2=833675&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/eval/RecommenderEvaluator.java
(original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/eval/RecommenderEvaluator.java
Sat Nov  7 13:27:55 2009
@@ -67,4 +67,32 @@
                   double trainingPercentage,
                   double evaluationPercentage) throws TasteException;
 
+  float getMaxPreference();
+
+  /**
+   * Sets the maximum preference value that is possible in the current problem
+   * domain being evaluated. For example, if the domain is movie ratings on a
+   * scale of 1 to 5, this should be set to 5. While a
+   * {@link org.apache.mahout.cf.taste.recommender.Recommender}
+   * may estimate a preference value above 5.0, it isn't "fair" to consider
+   * that the system is actually suggesting an impossible rating of, say,
+   * 5.4 stars. In practice the application would cap this estimate to 5.0.
+   * Since {@link RecommenderEvaluator}s evaluate the difference between
+   * estimated and actual value, this at least prevents this effect from
+   * unfairly penalizing a {@link org.apache.mahout.cf.taste.recommender.Recommender}.
+   *
+   * @see #setMinPreference(float)
+   */
+  void setMaxPreference(float maxPreference);
+
+  float getMinPreference();
+
+  /**
+   * Sets the minimum preference value that is possible in the current problem
+   * domain being evaluated.
+   *
+   * @see #setMinPreference(float)
+   */
+  void setMinPreference(float minPreference);
+
 }
\ No newline at end of file

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/eval/AbstractDifferenceRecommenderEvaluator.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/eval/AbstractDifferenceRecommenderEvaluator.java?rev=833675&r1=833674&r2=833675&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/eval/AbstractDifferenceRecommenderEvaluator.java
(original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/eval/AbstractDifferenceRecommenderEvaluator.java
Sat Nov  7 13:27:55 2009
@@ -38,23 +38,45 @@
 import java.util.List;
 import java.util.Random;
 
-/** <p>Abstract superclass of a couple implementations, providing shared functionality.</p>
*/
+/**
+ * Abstract superclass of a couple implementations, providing shared functionality.
+ */
 abstract class AbstractDifferenceRecommenderEvaluator implements RecommenderEvaluator {
 
   private static final Logger log = LoggerFactory.getLogger(AbstractDifferenceRecommenderEvaluator.class);
 
   private final Random random;
+  private float maxPreference;
+  private float minPreference;
 
   AbstractDifferenceRecommenderEvaluator() {
     random = RandomUtils.getRandom();
+    maxPreference = Float.NaN;
+    minPreference = Float.NaN;
+  }
+
+  public final float getMaxPreference() {
+    return maxPreference;
+  }
+
+  public final void setMaxPreference(float maxPreference) {
+    this.maxPreference = maxPreference;
+  }
+
+  public final float getMinPreference() {
+    return minPreference;
+  }
+
+  public final void setMinPreference(float minPreference) {
+    this.minPreference = minPreference;
   }
 
   @Override
-  public double evaluate(RecommenderBuilder recommenderBuilder,
-                         DataModelBuilder dataModelBuilder,
-                         DataModel dataModel,
-                         double trainingPercentage,
-                         double evaluationPercentage) throws TasteException {
+  public final double evaluate(RecommenderBuilder recommenderBuilder,
+                               DataModelBuilder dataModelBuilder,
+                               DataModel dataModel,
+                               double trainingPercentage,
+                               double evaluationPercentage) throws TasteException {
 
     if (recommenderBuilder == null) {
       throw new IllegalArgumentException("recommenderBuilder is null");
@@ -127,6 +149,16 @@
     }
   }
 
+  protected final float capEstimatedPreference(float estimate) {
+    if (estimate > maxPreference) {
+      return maxPreference;
+    }
+    if (estimate < minPreference) {
+      return minPreference;
+    }
+    return estimate;
+  }
+
   abstract double getEvaluation(FastByIDMap<PreferenceArray> testUserPrefs, Recommender
recommender)
       throws TasteException;
 

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/eval/AverageAbsoluteDifferenceRecommenderEvaluator.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/eval/AverageAbsoluteDifferenceRecommenderEvaluator.java?rev=833675&r1=833674&r2=833675&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/eval/AverageAbsoluteDifferenceRecommenderEvaluator.java
(original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/eval/AverageAbsoluteDifferenceRecommenderEvaluator.java
Sat Nov  7 13:27:55 2009
@@ -52,6 +52,7 @@
           float estimatedPreference =
               recommender.estimatePreference(testUserID, realPref.getItemID());
           if (!Float.isNaN(estimatedPreference)) {
+            estimatedPreference = capEstimatedPreference(estimatedPreference);
             average.addDatum(Math.abs(realPref.getValue() - estimatedPreference));
           }
         } catch (NoSuchUserException nsue) {

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/eval/RMSRecommenderEvaluator.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/eval/RMSRecommenderEvaluator.java?rev=833675&r1=833674&r2=833675&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/eval/RMSRecommenderEvaluator.java
(original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/eval/RMSRecommenderEvaluator.java
Sat Nov  7 13:27:55 2009
@@ -51,6 +51,7 @@
           float estimatedPreference =
               recommender.estimatePreference(testUserID, realPref.getItemID());
           if (!Float.isNaN(estimatedPreference)) {
+            estimatedPreference = capEstimatedPreference(estimatedPreference);          
 
             double diff = realPref.getValue() - estimatedPreference;
             average.addDatum(diff * diff);
           }



Mime
View raw message