randomsubspace.java

来自「Weka」· Java 代码 · 共 522 行 · 第 1/2 页

JAVA
522
字号
/* *    This program is free software; you can redistribute it and/or modify *    it under the terms of the GNU General Public License as published by *    the Free Software Foundation; either version 2 of the License, or *    (at your option) any later version. * *    This program is distributed in the hope that it will be useful, *    but WITHOUT ANY WARRANTY; without even the implied warranty of *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *    GNU General Public License for more details. * *    You should have received a copy of the GNU General Public License *    along with this program; if not, write to the Free Software *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *//* *    RandomSubSpace.java *    Copyright (C) 2006 University of Waikato, Hamilton, New Zealand * */package weka.classifiers.meta;import weka.filters.unsupervised.attribute.Remove;import weka.classifiers.Classifier;import weka.classifiers.RandomizableIteratedSingleClassifierEnhancer;import weka.core.Instance;import weka.core.Instances;import weka.core.Option;import weka.core.Randomizable;import weka.core.TechnicalInformation;import weka.core.TechnicalInformationHandler;import weka.core.Utils;import weka.core.WeightedInstancesHandler;import weka.core.TechnicalInformation.Field;import weka.core.TechnicalInformation.Type;import java.util.Enumeration;import java.util.Random;import java.util.Vector;import java.util.Arrays;import java.util.Collections;/** <!-- globalinfo-start --> * This method constructs a decision tree based classifier that maintains highest accuracy on training data and improves on generalization accuracy as it grows in complexity. The classifier consists of multiple trees constructed systematically by pseudorandomly selecting subsets of components of the feature vector, that is, trees constructed in randomly chosen subspaces.<br/> * <br/> * For more information, see<br/> * <br/> * Tin Kam Ho (1998). The Random Subspace Method for Constructing Decision Forests. IEEE Transactions on Pattern Analysis and Machine Intelligence. 20(8):832-844. URL http://citeseer.ist.psu.edu/ho98random.html. * <p/> <!-- globalinfo-end --> * <!-- technical-bibtex-start --> * BibTeX: * <pre> * &#64;article{Ho1998, *    author = {Tin Kam Ho}, *    journal = {IEEE Transactions on Pattern Analysis and Machine Intelligence}, *    number = {8}, *    pages = {832-844}, *    title = {The Random Subspace Method for Constructing Decision Forests}, *    volume = {20}, *    year = {1998}, *    ISSN = {0162-8828}, *    URL = {http://citeseer.ist.psu.edu/ho98random.html} * } * </pre> * <p/> <!-- technical-bibtex-end --> * <!-- options-start --> * Valid options are: <p/> *  * <pre> -P *  Size of each subspace: *   &lt; 1: percentage of the number of attributes *   &gt;=1: absolute number of attributes * </pre> *  * <pre> -S &lt;num&gt; *  Random number seed. *  (default 1)</pre> *  * <pre> -I &lt;num&gt; *  Number of iterations. *  (default 10)</pre> *  * <pre> -D *  If set, classifier is run in debug mode and *  may output additional info to the console</pre> *  * <pre> -W *  Full name of base classifier. *  (default: weka.classifiers.trees.REPTree)</pre> *  * <pre>  * Options specific to classifier weka.classifiers.trees.REPTree: * </pre> *  * <pre> -M &lt;minimum number of instances&gt; *  Set minimum number of instances per leaf (default 2).</pre> *  * <pre> -V &lt;minimum variance for split&gt; *  Set minimum numeric class variance proportion *  of train variance for split (default 1e-3).</pre> *  * <pre> -N &lt;number of folds&gt; *  Number of folds for reduced error pruning (default 3).</pre> *  * <pre> -S &lt;seed&gt; *  Seed for random data shuffling (default 1).</pre> *  * <pre> -P *  No pruning.</pre> *  * <pre> -L *  Maximum tree depth (default -1, no maximum)</pre> *  <!-- options-end --> * * Options after -- are passed to the designated classifier.<p> * * @author Bernhard Pfahringer (bernhard@cs.waikato.ac.nz) * @author Peter Reutemann (fracpete@cs.waikato.ac.nz) * @version $Revision: 1.3 $ */public class RandomSubSpace  extends RandomizableIteratedSingleClassifierEnhancer   implements WeightedInstancesHandler, TechnicalInformationHandler {  /** for serialization */  private static final long serialVersionUID = 1278172513912424947L;    /** The size of each bag sample, as a percentage of the training size */  protected double m_SubSpaceSize = 0.5;  /** a ZeroR model in case no model can be built from the data */  protected Classifier m_ZeroR;      /**   * Constructor.   */  public RandomSubSpace() {    super();        m_Classifier = new weka.classifiers.trees.REPTree();  }    /**   * Returns a string describing classifier   *    * @return 		a description suitable for   * 			displaying in the explorer/experimenter gui   */  public String globalInfo() {    return         "This method constructs a decision tree based classifier that "      + "maintains highest accuracy on training data and improves on "      + "generalization accuracy as it grows in complexity. The classifier "      + "consists of multiple trees constructed systematically by "      + "pseudorandomly selecting subsets of components of the feature vector, "      + "that is, trees constructed in randomly chosen subspaces.\n\n"      + "For more information, see\n\n"      + getTechnicalInformation().toString();  }  /**   * Returns an instance of a TechnicalInformation object, containing    * detailed information about the technical background of this class,   * e.g., paper reference or book this class is based on.   *    * @return 		the technical information about this class   */  public TechnicalInformation getTechnicalInformation() {    TechnicalInformation 	result;        result = new TechnicalInformation(Type.ARTICLE);    result.setValue(Field.AUTHOR, "Tin Kam Ho");    result.setValue(Field.YEAR, "1998");    result.setValue(Field.TITLE, "The Random Subspace Method for Constructing Decision Forests");    result.setValue(Field.JOURNAL, "IEEE Transactions on Pattern Analysis and Machine Intelligence");    result.setValue(Field.VOLUME, "20");    result.setValue(Field.NUMBER, "8");    result.setValue(Field.PAGES, "832-844");    result.setValue(Field.URL, "http://citeseer.ist.psu.edu/ho98random.html");    result.setValue(Field.ISSN, "0162-8828");        return result;  }  /**   * String describing default classifier.   *    * @return 		the default classifier classname   */  protected String defaultClassifierString() {    return "weka.classifiers.trees.REPTree";  }  /**   * Returns an enumeration describing the available options.   *   * @return 		an enumeration of all the available options.   */  public Enumeration listOptions() {    Vector result = new Vector();    result.addElement(new Option(	"\tSize of each subspace:\n"	+ "\t\t< 1: percentage of the number of attributes\n"	+ "\t\t>=1: absolute number of attributes\n",	"P", 1, "-P"));    Enumeration enu = super.listOptions();    while (enu.hasMoreElements()) {      result.addElement(enu.nextElement());    }        return result.elements();  }  /**   * Parses a given list of options. <p/>   *   <!-- options-start -->   * Valid options are: <p/>   *    * <pre> -P   *  Size of each subspace:   *   &lt; 1: percentage of the number of attributes   *   &gt;=1: absolute number of attributes   * </pre>   *    * <pre> -S &lt;num&gt;   *  Random number seed.   *  (default 1)</pre>   *    * <pre> -I &lt;num&gt;   *  Number of iterations.   *  (default 10)</pre>   *    * <pre> -D   *  If set, classifier is run in debug mode and   *  may output additional info to the console</pre>   *    * <pre> -W   *  Full name of base classifier.   *  (default: weka.classifiers.trees.REPTree)</pre>   *    * <pre>    * Options specific to classifier weka.classifiers.trees.REPTree:   * </pre>   *    * <pre> -M &lt;minimum number of instances&gt;   *  Set minimum number of instances per leaf (default 2).</pre>   *    * <pre> -V &lt;minimum variance for split&gt;   *  Set minimum numeric class variance proportion   *  of train variance for split (default 1e-3).</pre>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?