mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smar...@apache.org
Subject mahout git commit: MAHOUT-1605: Make VisualizerTest locale independent, this closes apache/mahout#107
Date Sun, 05 Apr 2015 16:12:28 GMT
Repository: mahout
Updated Branches:
  refs/heads/master 3a476e44f -> d8e0568e7


MAHOUT-1605: Make VisualizerTest locale independent, this closes apache/mahout#107


Project: http://git-wip-us.apache.org/repos/asf/mahout/repo
Commit: http://git-wip-us.apache.org/repos/asf/mahout/commit/d8e0568e
Tree: http://git-wip-us.apache.org/repos/asf/mahout/tree/d8e0568e
Diff: http://git-wip-us.apache.org/repos/asf/mahout/diff/d8e0568e

Branch: refs/heads/master
Commit: d8e0568e7ff45e5fcbccf4a5aaa2df6059c4aade
Parents: 3a476e4
Author: Suneel Marthi <suneel.marthi@gmail.com>
Authored: Sun Apr 5 12:14:21 2015 -0400
Committer: Suneel Marthi <suneel.marthi@gmail.com>
Committed: Sun Apr 5 12:14:21 2015 -0400

----------------------------------------------------------------------
 CHANGELOG                                       |  2 +
 .../classifier/df/tools/VisualizerTest.java     | 94 ++++++++++----------
 2 files changed, 49 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mahout/blob/d8e0568e/CHANGELOG
----------------------------------------------------------------------
diff --git a/CHANGELOG b/CHANGELOG
index 9b4acce..a4bda4a 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,6 +2,8 @@ Mahout Change Log
 
 Release 0.10.0 - unreleased
 
+  MAHOUT-1605: Make VisualizerTest locale independent (Frank Rosner, Anand Avati via smarthi)
+
   MAHOUT-1652: Java 7 upgrade (smarthi)
 
   MAHOUT-1635: Getting an exception when I provide classification labels manually for Naive
Bayes (apalumbo)

http://git-wip-us.apache.org/repos/asf/mahout/blob/d8e0568e/mr/src/test/java/org/apache/mahout/classifier/df/tools/VisualizerTest.java
----------------------------------------------------------------------
diff --git a/mr/src/test/java/org/apache/mahout/classifier/df/tools/VisualizerTest.java b/mr/src/test/java/org/apache/mahout/classifier/df/tools/VisualizerTest.java
index 482682d..eacce36 100644
--- a/mr/src/test/java/org/apache/mahout/classifier/df/tools/VisualizerTest.java
+++ b/mr/src/test/java/org/apache/mahout/classifier/df/tools/VisualizerTest.java
@@ -17,9 +17,6 @@
 
 package org.apache.mahout.classifier.df.tools;
 
-import java.util.List;
-import java.util.Random;
-
 import org.apache.mahout.classifier.df.DecisionForest;
 import org.apache.mahout.classifier.df.builder.DecisionTreeBuilder;
 import org.apache.mahout.classifier.df.data.Data;
@@ -36,10 +33,16 @@ import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
-import com.google.common.collect.Lists;
+import java.text.DecimalFormat;
+import java.util.List;
+import java.util.Random;
+import java.util.ArrayList;
 
 public final class VisualizerTest extends MahoutTestCase {
   
+  private static final char DECIMAL_SEPARATOR =
+      ((DecimalFormat) DecimalFormat.getInstance()).getDecimalFormatSymbols().getDecimalSeparator();
+  
   private static final String[] TRAIN_DATA = {"sunny,85,85,FALSE,no",
       "sunny,80,90,TRUE,no", "overcast,83,86,FALSE,yes",
       "rainy,70,96,FALSE,yes", "rainy,68,80,FALSE,yes", "rainy,65,70,TRUE,no",
@@ -51,12 +54,12 @@ public final class VisualizerTest extends MahoutTestCase {
   private static final String[] TEST_DATA = {"rainy,70,96,TRUE,-",
       "overcast,64,65,TRUE,-", "sunny,75,90,TRUE,-",};
   
-  private static final String[] ATTR_NAMES = {"outlook", "temperature",
+  private static final String[] ATTRIBUTE_NAMES = {"outlook", "temperature",
       "humidity", "windy", "play"};
   
-  private Random rng;
+  private Random randomNumberGenerator;
   
-  private Data data;
+  private Data trainingData;
   
   private Data testData;
   
@@ -65,16 +68,13 @@ public final class VisualizerTest extends MahoutTestCase {
   public void setUp() throws Exception {
     super.setUp();
     
-    rng = RandomUtils.getRandom(1);
+    randomNumberGenerator = RandomUtils.getRandom(1);
     
-    // Dataset
     Dataset dataset = DataLoader
         .generateDataset("C N N C L", false, TRAIN_DATA);
     
-    // Training data
-    data = DataLoader.loadData(dataset, TRAIN_DATA);
+    trainingData = DataLoader.loadData(dataset, TRAIN_DATA);
     
-    // Test data
     testData = DataLoader.loadData(dataset, TEST_DATA);
   }
   
@@ -82,42 +82,42 @@ public final class VisualizerTest extends MahoutTestCase {
   public void testTreeVisualize() throws Exception {
     // build tree
     DecisionTreeBuilder builder = new DecisionTreeBuilder();
-    builder.setM(data.getDataset().nbAttributes() - 1);
-    Node tree = builder.build(rng, data);
+    builder.setM(trainingData.getDataset().nbAttributes() - 1);
+    Node tree = builder.build(randomNumberGenerator, trainingData);
 
-    String visualization = TreeVisualizer.toString(tree, data.getDataset(), ATTR_NAMES);
+    String visualization = TreeVisualizer.toString(tree, trainingData.getDataset(), ATTRIBUTE_NAMES);
 
     assertTrue(
-        ("\n" +
+        (String.format("\n" +
             "outlook = rainy\n" +
             "|   windy = FALSE : yes\n" +
             "|   windy = TRUE : no\n" +
             "outlook = sunny\n" +
-            "|   humidity < 77.5 : yes\n" +
-            "|   humidity >= 77.5 : no\n" +
-            "outlook = overcast : yes").equals(visualization) ||
-        ("\n" +
+            "|   humidity < 77%s5 : yes\n" +
+            "|   humidity >= 77%s5 : no\n" +
+                       "outlook = overcast : yes", DECIMAL_SEPARATOR, DECIMAL_SEPARATOR)).equals(visualization)
||
+        (String.format("\n" +
             "outlook = rainy\n" +
             "|   windy = TRUE : no\n" +
             "|   windy = FALSE : yes\n" +
             "outlook = overcast : yes\n" +
             "outlook = sunny\n" +
-            "|   humidity < 77.5 : yes\n" +
-            "|   humidity >= 77.5 : no").equals(visualization));
+            "|   humidity < 77%s5 : yes\n" +
+            "|   humidity >= 77%s5 : no", DECIMAL_SEPARATOR, DECIMAL_SEPARATOR)).equals(visualization));
   }
   
   @Test
   public void testPredictTrace() throws Exception {
     // build tree
     DecisionTreeBuilder builder = new DecisionTreeBuilder();
-    builder.setM(data.getDataset().nbAttributes() - 1);
-    Node tree = builder.build(rng, data);
+    builder.setM(trainingData.getDataset().nbAttributes() - 1);
+    Node tree = builder.build(randomNumberGenerator, trainingData);
     
     String[] prediction = TreeVisualizer.predictTrace(tree, testData,
-        ATTR_NAMES);
+			ATTRIBUTE_NAMES);
     Assert.assertArrayEquals(new String[] {
         "outlook = rainy -> windy = TRUE -> no", "outlook = overcast -> yes",
-        "outlook = sunny -> (humidity = 90) >= 77.5 -> no"}, prediction);
+        String.format("outlook = sunny -> (humidity = 90) >= 77%s5 -> no", DECIMAL_SEPARATOR)},
prediction);
   }
   
   @Test
@@ -127,12 +127,12 @@ public final class VisualizerTest extends MahoutTestCase {
         new CategoricalNode(0, new double[] {0, 1, 2}, new Node[] {
             new NumericalNode(1, 71, new Leaf(0), new Leaf(1)), new Leaf(1),
             new Leaf(0)}));
-    List<Node> trees = Lists.newArrayList();
+    List<Node> trees = new ArrayList<>();
     trees.add(root);
 
     // Forest
     DecisionForest forest = new DecisionForest(trees);
-    String visualization = ForestVisualizer.toString(forest, data.getDataset(), null);
+    String visualization = ForestVisualizer.toString(forest, trainingData.getDataset(), null);
     assertTrue(
         ("Tree[1]:\n2 < 90 : yes\n2 >= 90\n" +
             "|   0 = rainy\n" +
@@ -149,7 +149,7 @@ public final class VisualizerTest extends MahoutTestCase {
             "|   0 = overcast : yes\n" +
             "|   0 = sunny : no\n").equals(visualization));
 
-    visualization = ForestVisualizer.toString(forest, data.getDataset(), ATTR_NAMES);
+    visualization = ForestVisualizer.toString(forest, trainingData.getDataset(), ATTRIBUTE_NAMES);
     assertTrue(
         ("Tree[1]:\n" +
             "humidity < 90 : yes\n" +
@@ -171,41 +171,41 @@ public final class VisualizerTest extends MahoutTestCase {
   
   @Test
   public void testLeafless() throws Exception {
-    List<Instance> instances = Lists.newArrayList();
-    for (int i = 0; i < data.size(); i++) {
-      if (data.get(i).get(0) != 0.0d) {
-        instances.add(data.get(i));
+    List<Instance> instances = new ArrayList<>();
+    for (int i = 0; i < trainingData.size(); i++) {
+      if (trainingData.get(i).get(0) != 0.0d) {
+        instances.add(trainingData.get(i));
       }
     }
-    Data lessData = new Data(data.getDataset(), instances);
+    Data lessData = new Data(trainingData.getDataset(), instances);
     
     // build tree
     DecisionTreeBuilder builder = new DecisionTreeBuilder();
-    builder.setM(data.getDataset().nbAttributes() - 1);
+    builder.setM(trainingData.getDataset().nbAttributes() - 1);
     builder.setMinSplitNum(0);
     builder.setComplemented(false);
-    Node tree = builder.build(rng, lessData);
+    Node tree = builder.build(randomNumberGenerator, lessData);
 
-    String visualization = TreeVisualizer.toString(tree, data.getDataset(), ATTR_NAMES);
+    String visualization = TreeVisualizer.toString(tree, trainingData.getDataset(), ATTRIBUTE_NAMES);
     assertTrue(
-        ("\noutlook = sunny\n" +
-            "|   humidity < 77.5 : yes\n" +
-            "|   humidity >= 77.5 : no\n" +
-            "outlook = overcast : yes").equals(visualization) ||
-        ("\noutlook = overcast : yes\n" +
+        (String.format("\noutlook = sunny\n" +
+            "|   humidity < 77%s5 : yes\n" +
+            "|   humidity >= 77%s5 : no\n" +
+            "outlook = overcast : yes", DECIMAL_SEPARATOR, DECIMAL_SEPARATOR)).equals(visualization)
||
+        (String.format("\noutlook = overcast : yes\n" +
             "outlook = sunny\n" +
-            "|   humidity < 77.5 : yes\n" +
-            "|   humidity >= 77.5 : no").equals(visualization));
+            "|   humidity < 77%s5 : yes\n" +
+            "|   humidity >= 77%s5 : no", DECIMAL_SEPARATOR, DECIMAL_SEPARATOR)).equals(visualization));
   }
   
   @Test
   public void testEmpty() throws Exception {
-    Data emptyData = new Data(data.getDataset());
+    Data emptyData = new Data(trainingData.getDataset());
     
     // build tree
     DecisionTreeBuilder builder = new DecisionTreeBuilder();
-    Node tree = builder.build(rng, emptyData);
+    Node tree = builder.build(randomNumberGenerator, emptyData);
 
-    assertEquals(" : unknown", TreeVisualizer.toString(tree, data.getDataset(), ATTR_NAMES));
+    assertEquals(" : unknown", TreeVisualizer.toString(tree, trainingData.getDataset(), ATTRIBUTE_NAMES));
   }
 }


Mime
View raw message