lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomm...@apache.org
Subject svn commit: r1403798 - /lucene/dev/trunk/lucene/classification/src/java/org/apache/lucene/classification/KNearestNeighborClassifier.java
Date Tue, 30 Oct 2012 17:41:32 GMT
Author: tommaso
Date: Tue Oct 30 17:41:32 2012
New Revision: 1403798

URL: http://svn.apache.org/viewvc?rev=1403798&view=rev
Log:
[LUCENE-4345] - adding kNN score as count / k for the most frequent class in results

Modified:
    lucene/dev/trunk/lucene/classification/src/java/org/apache/lucene/classification/KNearestNeighborClassifier.java

Modified: lucene/dev/trunk/lucene/classification/src/java/org/apache/lucene/classification/KNearestNeighborClassifier.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/classification/src/java/org/apache/lucene/classification/KNearestNeighborClassifier.java?rev=1403798&r1=1403797&r2=1403798&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/classification/src/java/org/apache/lucene/classification/KNearestNeighborClassifier.java
(original)
+++ lucene/dev/trunk/lucene/classification/src/java/org/apache/lucene/classification/KNearestNeighborClassifier.java
Tue Oct 30 17:41:32 2012
@@ -32,6 +32,7 @@ import java.util.Map;
 /**
  * A k-Nearest Neighbor classifier (see <code>http://en.wikipedia.org/wiki/K-nearest_neighbors</code>)
based
  * on {@link MoreLikeThis}
+ *
  * @lucene.experimental
  */
 public class KNearestNeighborClassifier implements Classifier {
@@ -44,6 +45,7 @@ public class KNearestNeighborClassifier 
 
   /**
    * Create a {@link Classifier} using kNN algorithm
+   *
    * @param k the number of neighbors to analyze as an <code>int</code>
    */
   public KNearestNeighborClassifier(int k) {
@@ -62,8 +64,7 @@ public class KNearestNeighborClassifier 
       Integer count = classCounts.get(cl);
       if (count != null) {
         classCounts.put(cl, count + 1);
-      }
-      else {
+      } else {
         classCounts.put(cl, 1);
       }
     }
@@ -76,7 +77,7 @@ public class KNearestNeighborClassifier 
         assignedClass = cl;
       }
     }
-    double score = 1; // TODO : derive score from query
+    double score = classCounts.get(assignedClass) / k;
     return new ClassificationResult(assignedClass, score);
   }
 



Mime
View raw message