Author: robinanil
Date: Fri Oct  8 20:07:06 2010
New Revision: 1005999

URL: http://svn.apache.org/viewvc?rev=1005999&view=rev
Log:
Some Bug fixes in naivebayes: On reading empty input, M/R crashes. Map file is 
not closed properly after written.

Modified:
    
mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/trainer/NaiveBayesInstanceMapper.java
    
mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/trainer/NaiveBayesSumReducer.java
    
mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/trainer/NaiveBayesTrainer.java
    
mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/trainer/NaiveBayesWeightsMapper.java

Modified: 
mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/trainer/NaiveBayesInstanceMapper.java
URL: 
http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/trainer/NaiveBayesInstanceMapper.java?rev=1005999&r1=1005998&r2=1005999&view=diff
==============================================================================
--- 
mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/trainer/NaiveBayesInstanceMapper.java
 (original)
+++ 
mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/trainer/NaiveBayesInstanceMapper.java
 Fri Oct  8 20:07:06 2010
@@ -40,7 +40,7 @@ public class NaiveBayesInstanceMapper ex
   protected void map(Text key, VectorWritable value, Context context)
       throws IOException, InterruptedException {
     if (!labelMap.containsKey(key.toString())) {
-      context.getCounter("NaiveBayes", "Skipped instance: not in label list");
+      context.getCounter("NaiveBayes", "Skipped instance: not in label 
list").increment(1);
       return;
     }  
     int label = labelMap.get(key.toString());

Modified: 
mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/trainer/NaiveBayesSumReducer.java
URL: 
http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/trainer/NaiveBayesSumReducer.java?rev=1005999&r1=1005998&r2=1005999&view=diff
==============================================================================
--- 
mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/trainer/NaiveBayesSumReducer.java
 (original)
+++ 
mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/trainer/NaiveBayesSumReducer.java
 Fri Oct  8 20:07:06 2010
@@ -42,5 +42,4 @@ public class NaiveBayesSumReducer extend
     }
     context.write(key, new VectorWritable(vector));
   }
-
 }

Modified: 
mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/trainer/NaiveBayesTrainer.java
URL: 
http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/trainer/NaiveBayesTrainer.java?rev=1005999&r1=1005998&r2=1005999&view=diff
==============================================================================
--- 
mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/trainer/NaiveBayesTrainer.java
 (original)
+++ 
mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/trainer/NaiveBayesTrainer.java
 Fri Oct  8 20:07:06 2010
@@ -197,6 +197,7 @@ public final class NaiveBayesTrainer {
       Writable key = new Text(label);
       dictWriter.append(key, new IntWritable(i++));
     }
+    dictWriter.close();
     return labelMapPath;
   }
 }

Modified: 
mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/trainer/NaiveBayesWeightsMapper.java
URL: 
http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/trainer/NaiveBayesWeightsMapper.java?rev=1005999&r1=1005998&r2=1005999&view=diff
==============================================================================
--- 
mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/trainer/NaiveBayesWeightsMapper.java
 (original)
+++ 
mahout/trunk/core/src/main/java/org/apache/mahout/classifier/naivebayes/trainer/NaiveBayesWeightsMapper.java
 Fri Oct  8 20:07:06 2010
@@ -81,8 +81,10 @@ public class NaiveBayesWeightsMapper ext
   
   @Override
   protected void cleanup(Context context) throws IOException, 
InterruptedException {
-    context.write(new Text(BayesConstants.FEATURE_SUM), new 
VectorWritable(featureSum));
-    context.write(new Text(BayesConstants.LABEL_SUM), new 
VectorWritable(labelSum));
+    if (featureSum != null) {
+      context.write(new Text(BayesConstants.FEATURE_SUM), new 
VectorWritable(featureSum));
+      context.write(new Text(BayesConstants.LABEL_SUM), new 
VectorWritable(labelSum));
+    }
     super.cleanup(context);
   }
 }


Reply via email to