Details

      Description

      TreePrinter and ForestPrinter are made for checking the model on MAHOUT-840.
      I think they are useful for checking the model and making unit testing.

      1. MAHOUT-926.patch
        21 kB
        Ikumasa Mukai
      2. MAHOUT-926.patch
        21 kB
        Ikumasa Mukai

        Issue Links

          Activity

          Hide
          Hudson added a comment -

          Integrated in Mahout-Quality #1273 (See https://builds.apache.org/job/Mahout-Quality/1273/)
          MAHOUT-926 Tree/Forest Visualizer

          adeneche : http://svn.apache.org/viewcvs.cgi/?root=Apache-SVN&view=rev&rev=1224751
          Files :

          • /mahout/trunk/core/src/main/java/org/apache/mahout/classifier/df/tools/ForestVisualizer.java
          • /mahout/trunk/core/src/main/java/org/apache/mahout/classifier/df/tools/TreeVisualizer.java
          • /mahout/trunk/core/src/test/java/org/apache/mahout/classifier/df/tools
          • /mahout/trunk/core/src/test/java/org/apache/mahout/classifier/df/tools/VisualizerTest.java
          Show
          Hudson added a comment - Integrated in Mahout-Quality #1273 (See https://builds.apache.org/job/Mahout-Quality/1273/ ) MAHOUT-926 Tree/Forest Visualizer adeneche : http://svn.apache.org/viewcvs.cgi/?root=Apache-SVN&view=rev&rev=1224751 Files : /mahout/trunk/core/src/main/java/org/apache/mahout/classifier/df/tools/ForestVisualizer.java /mahout/trunk/core/src/main/java/org/apache/mahout/classifier/df/tools/TreeVisualizer.java /mahout/trunk/core/src/test/java/org/apache/mahout/classifier/df/tools /mahout/trunk/core/src/test/java/org/apache/mahout/classifier/df/tools/VisualizerTest.java
          Hide
          Deneche A. Hakim added a comment -

          I am checking the patch right now, if no problem is encountered I will commit it right after. This is really a cool addition to Mahout's DF.

          Show
          Deneche A. Hakim added a comment - I am checking the patch right now, if no problem is encountered I will commit it right after. This is really a cool addition to Mahout's DF.
          Hide
          Ikumasa Mukai added a comment -

          I made a patch which can be used on your code like this.
          Sorry for late to attach.

          To dump tree:

          DecisionTreeBuilder builder = new DecisionTreeBuilder();
          Node tree = builder.build(RandomUtils.getRandom(), data);
          TreeVisualizer.print(tree, data.getDataset(),
           new String[] {"sepallength", "sepalwidth", "petallength", "petalwidth", "class"});
          

          To check the route:

          TreeVisualizer.predictTracePrint(tree, testData,
            new String[] {"sepallength", "sepalwidth", "petallength", "petalwidth", "class"});
          

          The result for predictTracePrint.

          (petallength = 4.7) >= 3.3 -> (petalwidth = 1.4) < 1.8 -> (petallength = 4.7) < 5 -> (petalwidth = 1.4) < 1.7 -> Iris-versicolor
          

          In addition, ForestVisualizer can be used as a cli tool.

          .. ForestVisualizer -ds dataset/iris.info -m model/iris -n sepallength sepalwidth petallength petalwidth class
          

          The result.

          Tree[1]:
          petallength < 3.5 : Iris-setosa
          petallength >= 3.5
          |   petalwidth < 1.8
          |   |   petallength < 5 : Iris-versicolor
          |   |   petallength >= 5
          |   |   |   petalwidth < 1.7 : Iris-virginica
          |   |   |   petalwidth >= 1.7 : Iris-versicolor
          |   petalwidth >= 1.8
          |   |   petallength < 4.9
          |   |   |   sepallength < 6 : Iris-versicolor
          |   |   |   sepallength >= 6 : Iris-virginica
          |   |   petallength >= 4.9 : Iris-virginica
          Tree[2]:
          petallength < 3.3 : Iris-setosa
          petallength >= 3.3
          |   petalwidth < 1.8
          |   |   sepalwidth < 2.3 : Iris-virginica
          |   |   sepalwidth >= 2.3
          |   |   |   petallength < 5.6
          |   |   |   |   sepallength < 5.5
          |   |   |   |   |   sepalwidth < 2.5 : Iris-versicolor
          |   |   |   |   |   sepalwidth >= 2.5 : Iris-virginica
          |   |   |   |   sepallength >= 5.5 : Iris-versicolor
          |   |   |   petallength >= 5.6 : Iris-virginica
          |   petalwidth >= 1.8 : Iris-virginica
          Tree[3]:
          petallength < 3.3 : Iris-setosa
          petallength >= 3.3
          |   petalwidth < 1.8
          |   |   petallength < 5 : Iris-versicolor
          |   |   petallength >= 5
          |   |   |   petalwidth < 1.7 : Iris-virginica
          |   |   |   petalwidth >= 1.7 : Iris-versicolor
          |   petalwidth >= 1.8 : Iris-virginica
          Tree[4]:
          .
          -snip-
          .
          

          All trees in the forest are dumped.

          Show
          Ikumasa Mukai added a comment - I made a patch which can be used on your code like this. Sorry for late to attach. To dump tree: DecisionTreeBuilder builder = new DecisionTreeBuilder(); Node tree = builder.build(RandomUtils.getRandom(), data); TreeVisualizer.print(tree, data.getDataset(), new String [] { "sepallength" , "sepalwidth" , "petallength" , "petalwidth" , "class" }); To check the route: TreeVisualizer.predictTracePrint(tree, testData, new String [] { "sepallength" , "sepalwidth" , "petallength" , "petalwidth" , "class" }); The result for predictTracePrint. (petallength = 4.7) >= 3.3 -> (petalwidth = 1.4) < 1.8 -> (petallength = 4.7) < 5 -> (petalwidth = 1.4) < 1.7 -> Iris-versicolor In addition, ForestVisualizer can be used as a cli tool. .. ForestVisualizer -ds dataset/iris.info -m model/iris -n sepallength sepalwidth petallength petalwidth class The result. Tree[1]: petallength < 3.5 : Iris-setosa petallength >= 3.5 | petalwidth < 1.8 | | petallength < 5 : Iris-versicolor | | petallength >= 5 | | | petalwidth < 1.7 : Iris-virginica | | | petalwidth >= 1.7 : Iris-versicolor | petalwidth >= 1.8 | | petallength < 4.9 | | | sepallength < 6 : Iris-versicolor | | | sepallength >= 6 : Iris-virginica | | petallength >= 4.9 : Iris-virginica Tree[2]: petallength < 3.3 : Iris-setosa petallength >= 3.3 | petalwidth < 1.8 | | sepalwidth < 2.3 : Iris-virginica | | sepalwidth >= 2.3 | | | petallength < 5.6 | | | | sepallength < 5.5 | | | | | sepalwidth < 2.5 : Iris-versicolor | | | | | sepalwidth >= 2.5 : Iris-virginica | | | | sepallength >= 5.5 : Iris-versicolor | | | petallength >= 5.6 : Iris-virginica | petalwidth >= 1.8 : Iris-virginica Tree[3]: petallength < 3.3 : Iris-setosa petallength >= 3.3 | petalwidth < 1.8 | | petallength < 5 : Iris-versicolor | | petallength >= 5 | | | petalwidth < 1.7 : Iris-virginica | | | petalwidth >= 1.7 : Iris-versicolor | petalwidth >= 1.8 : Iris-virginica Tree[4]: . -snip- . All trees in the forest are dumped.
          Hide
          Ikumasa Mukai added a comment -

          We can get the result like this.

          i. iris - classification

          petallength < 3.3 : Iris-setosa
          petallength >= 3.3
          |   petalwidth < 1.8
          |   |   petallength < 5
          |   |   |   petalwidth < 1.7 : Iris-versicolor
          |   |   |   petalwidth >= 1.7 : Iris-virginica
          |   |   petallength >= 5
          |   |   |   petalwidth < 1.6 : Iris-virginica
          |   |   |   petalwidth >= 1.6
          |   |   |   |   sepallength < 7.2 : Iris-versicolor
          |   |   |   |   sepallength >= 7.2 : Iris-virginica
          |   petalwidth >= 1.8
          |   |   petallength < 4.9
          |   |   |   sepallength < 6 : Iris-versicolor
          |   |   |   sepallength >= 6 : Iris-virginica
          |   |   petallength >= 4.9 : Iris-virginica
          

          ii. cars - regression

          speed < 30
          |   speed < 12
          |   |   speed < 3 : 4
          |   |   speed >= 3
          |   |   |   speed < 7 : 7
          |   |   |   speed >= 7 : 6.5
          |   speed >= 12
          |   |   speed < 23
          |   |   |   speed < 21
          |   |   |   |   speed < 19
          |   |   |   |   |   speed < 15 : 12
          |   |   |   |   |   speed >= 15
          |   |   |   |   |   |   speed < 16.5 : 8
          |   |   |   |   |   |   speed >= 16.5
          |   |   |   |   |   |   |   speed < 17.5 : 11
          |   |   |   |   |   |   |   speed >= 17.5 : 10
          |   |   |   |   speed >= 19 : 13.5
          |   |   |   speed >= 21 : 7
          |   |   speed >= 23
          |   |   |   speed < 27
          |   |   |   |   speed < 25 : 12
          |   |   |   |   speed >= 25 : 13
          |   |   |   speed >= 27 : 11.5
          speed >= 30
          |   speed < 84.5
          ---snip---
          
          Show
          Ikumasa Mukai added a comment - We can get the result like this. i. iris - classification petallength < 3.3 : Iris-setosa petallength >= 3.3 | petalwidth < 1.8 | | petallength < 5 | | | petalwidth < 1.7 : Iris-versicolor | | | petalwidth >= 1.7 : Iris-virginica | | petallength >= 5 | | | petalwidth < 1.6 : Iris-virginica | | | petalwidth >= 1.6 | | | | sepallength < 7.2 : Iris-versicolor | | | | sepallength >= 7.2 : Iris-virginica | petalwidth >= 1.8 | | petallength < 4.9 | | | sepallength < 6 : Iris-versicolor | | | sepallength >= 6 : Iris-virginica | | petallength >= 4.9 : Iris-virginica ii. cars - regression speed < 30 | speed < 12 | | speed < 3 : 4 | | speed >= 3 | | | speed < 7 : 7 | | | speed >= 7 : 6.5 | speed >= 12 | | speed < 23 | | | speed < 21 | | | | speed < 19 | | | | | speed < 15 : 12 | | | | | speed >= 15 | | | | | | speed < 16.5 : 8 | | | | | | speed >= 16.5 | | | | | | | speed < 17.5 : 11 | | | | | | | speed >= 17.5 : 10 | | | | speed >= 19 : 13.5 | | | speed >= 21 : 7 | | speed >= 23 | | | speed < 27 | | | | speed < 25 : 12 | | | | speed >= 25 : 13 | | | speed >= 27 : 11.5 speed >= 30 | speed < 84.5 ---snip---

            People

            • Assignee:
              Deneche A. Hakim
              Reporter:
              Ikumasa Mukai
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development