M5P.java
Upload User: rhdiban
Upload Date: 2013-08-09
Package Size: 15085k
Code Size: 3k
Category:

Windows Develop

Development Platform:

Java

  1. /*
  2.  *    M5P.java
  3.  *    Copyright (C) 2001 Mark Hall
  4.  *
  5.  *    This program is free software; you can redistribute it and/or modify
  6.  *    it under the terms of the GNU General Public License as published by
  7.  *    the Free Software Foundation; either version 2 of the License, or
  8.  *    (at your option) any later version.
  9.  *
  10.  *    This program is distributed in the hope that it will be useful,
  11.  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *    GNU General Public License for more details.
  14.  *
  15.  *    You should have received a copy of the GNU General Public License
  16.  *    along with this program; if not, write to the Free Software
  17.  *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19. package weka.classifiers.trees.m5;
  20. import java.io.*;
  21. import java.util.*;
  22. import weka.core.*;
  23. /**
  24.  * M5P. Implements routines for generating M5 model trees.
  25.  *
  26.  * Valid options are:<p>
  27.  * 
  28.  * -U <br>
  29.  * Use unsmoothed predictions. <p>
  30.  *
  31.  * @author <a href="mailto:mhall@cs.waikato.ac.nz">Mark Hall</a>
  32.  * @version $Revision: 1.1 $
  33.  */
  34. public class M5P extends M5Base 
  35.   implements Drawable {
  36.   /**
  37.    * Creates a new <code>M5P</code> instance.
  38.    */
  39.   public M5P() {
  40.     super();
  41.     setGenerateRules(false);
  42.   }
  43.   /**
  44.    * Return a dot style String describing the tree.
  45.    *
  46.    * @return a <code>String</code> value
  47.    * @exception Exception if an error occurs
  48.    */
  49.   public String graph() throws Exception {
  50.     StringBuffer text = new StringBuffer();
  51.     
  52.     text.append("digraph M5Tree {n");
  53.     Rule temp = (Rule)m_ruleSet.elementAt(0);
  54.     temp.m_topOfTree.graph(text);
  55.     text.append("}n");
  56.     return text.toString();
  57.   }
  58.   /**
  59.    * Set whether to save instance data at each node in the
  60.    * tree for visualization purposes
  61.    *
  62.    * @param save a <code>boolean</code> value
  63.    */
  64.   public void setSaveInstances(boolean save) {
  65.     m_saveInstances = save;
  66.   }
  67.   /**
  68.    * Get whether instance data is being save.
  69.    *
  70.    * @return a <code>boolean</code> value
  71.    */
  72.   public boolean getSaveInstances() {
  73.     return m_saveInstances;
  74.   }
  75.   /**
  76.    * Main method by which this class can be tested
  77.    * 
  78.    * @param args an array of options
  79.    */
  80.   public static void main(String[] args) {
  81.     try {
  82.       System.out.println(weka.classifiers.Evaluation.evaluateModel(
  83.  new M5P(), 
  84.  args));
  85.     } catch (Exception e) {
  86.       System.err.println(e.getMessage());
  87.       e.printStackTrace();
  88.     } 
  89.   } 
  90. }