mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gsing...@apache.org
Subject svn commit: r1201351 - in /mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd: TrainAdaptiveLogistic.java TrainLogistic.java
Date Sat, 12 Nov 2011 23:07:58 GMT
Author: gsingers
Date: Sat Nov 12 23:07:58 2011
New Revision: 1201351

URL: http://svn.apache.org/viewvc?rev=1201351&view=rev
Log:
since these examples are useful for general CSV files, spit out the line number if there is
an error in parsing the line so it can be tracked down

Modified:
    mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainAdaptiveLogistic.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainLogistic.java

Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainAdaptiveLogistic.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainAdaptiveLogistic.java?rev=1201351&r1=1201350&r2=1201351&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainAdaptiveLogistic.java
(original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainAdaptiveLogistic.java
Sat Nov 12 23:07:58 2011
@@ -59,11 +59,11 @@ public final class TrainAdaptiveLogistic
   private TrainAdaptiveLogistic() {
   }
 
-  public static void main(String[] args) throws IOException {
+  public static void main(String[] args) throws Exception {
     mainToOutput(args, new PrintWriter(System.out, true));
   }
 
-  static void mainToOutput(String[] args, PrintWriter output) throws IOException {
+  static void mainToOutput(String[] args, PrintWriter output) throws Exception {
     if (parseArgs(args)) {
 
       CsvRecordFactory csv = lmp.getCsvRecordFactory();
@@ -79,11 +79,17 @@ public final class TrainAdaptiveLogistic
         csv.firstLine(in.readLine());
 
         String line = in.readLine();
-
+        int lineCount = 2;
         while (line != null) {
           // for each new line, get target and predictors
           Vector input = new RandomAccessSparseVector(lmp.getNumFeatures());
-          int targetValue = csv.processLine(line, input);
+          int targetValue = 0;
+          try {
+            targetValue = csv.processLine(line, input);
+          } catch (Exception e) {
+            System.out.println("Exception at line " + lineCount);
+            throw e;
+          }
           // update model
           model.train(targetValue, input);
           k++;
@@ -106,6 +112,7 @@ public final class TrainAdaptiveLogistic
             }
           }
           line = in.readLine();
+          lineCount++;
         }
         in.close();
       }
@@ -116,7 +123,7 @@ public final class TrainAdaptiveLogistic
       }
       if (learner == null) {
         output.printf(Locale.ENGLISH,
-                      "%s\n", "AdaptiveLogisticRegression has not successfully trained any
model.");
+                      "%s\n", "AdaptiveLogisticRegression has failed to train a model.");
         return;
       }
 

Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainLogistic.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainLogistic.java?rev=1201351&r1=1201350&r2=1201351&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainLogistic.java
(original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainLogistic.java
Sat Nov 12 23:07:58 2011
@@ -60,11 +60,11 @@ public final class TrainLogistic {
   private TrainLogistic() {
   }
 
-  public static void main(String[] args) throws IOException {
+  public static void main(String[] args) throws Exception {
     mainToOutput(args, new PrintWriter(System.out, true));
   }
 
-  static void mainToOutput(String[] args, PrintWriter output) throws IOException {
+  static void mainToOutput(String[] args, PrintWriter output) throws Exception {
     if (parseArgs(args)) {
       double logPEstimate = 0;
       int samples = 0;
@@ -78,10 +78,17 @@ public final class TrainLogistic {
           csv.firstLine(in.readLine());
 
           String line = in.readLine();
+          int lineCount = 0;
           while (line != null) {
             // for each new line, get target and predictors
             Vector input = new RandomAccessSparseVector(lmp.getNumFeatures());
-            int targetValue = csv.processLine(line, input);
+            int targetValue = 0;
+            try {
+              targetValue = csv.processLine(line, input);
+            } catch (Exception e) {
+              System.out.println("Exception at line " + lineCount);
+              throw e;
+            }
 
             // check performance while this is still news
             double logP = lr.logLikelihood(targetValue, input);
@@ -115,7 +122,7 @@ public final class TrainLogistic {
       } finally {
         Closeables.closeQuietly(modelOutput);
       }
-      
+
       output.printf(Locale.ENGLISH, "%d\n", lmp.getNumFeatures());
       output.printf(Locale.ENGLISH, "%s ~ ", lmp.getTargetVariable());
       String sep = "";



Mime
View raw message