⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 decorate.java

📁 代码是一个分类器的实现,其中使用了部分weka的源代码。可以将项目导入eclipse运行
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* *    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. *//* *    Decorate.java *    Copyright (C) 2002 Prem Melville * */package weka.classifiers.meta;import weka.classifiers.Classifier;import weka.classifiers.RandomizableIteratedSingleClassifierEnhancer;import weka.core.Capabilities;import weka.core.Instance;import weka.core.Instances;import weka.core.Option;import weka.core.TechnicalInformation;import weka.core.TechnicalInformationHandler;import weka.core.UnsupportedClassTypeException;import weka.core.Utils;import weka.core.Capabilities.Capability;import weka.core.TechnicalInformation.Field;import weka.core.TechnicalInformation.Type;import java.util.Enumeration;import java.util.Random;import java.util.Vector;/** <!-- globalinfo-start --> * DECORATE is a meta-learner for building diverse ensembles of classifiers by using specially constructed artificial training examples. Comprehensive experiments have demonstrated that this technique is consistently more accurate than the base classifier, Bagging and Random Forests.Decorate also obtains higher accuracy than Boosting on small training sets, and achieves comparable performance on larger training sets. <br/> * <br/> * For more details see: <br/> * <br/> * P. Melville, R. J. Mooney: Constructing Diverse Classifier Ensembles Using Artificial Training Examples. In: Eighteenth International Joint Conference on Artificial Intelligence, 505-510, 2003.<br/> * <br/> * P. Melville, R. J. Mooney (2004). Creating Diversity in Ensembles Using Artificial Data. Information Fusion: Special Issue on Diversity in Multiclassifier Systems.. * <p/> <!-- globalinfo-end --> * <!-- technical-bibtex-start --> * BibTeX: * <pre> * &#64;inproceedings{Melville2003, *    author = {P. Melville and R. J. Mooney}, *    booktitle = {Eighteenth International Joint Conference on Artificial Intelligence}, *    pages = {505-510}, *    title = {Constructing Diverse Classifier Ensembles Using Artificial Training Examples}, *    year = {2003} * } *  * &#64;article{Melville2004, *    author = {P. Melville and R. J. Mooney}, *    journal = {Information Fusion: Special Issue on Diversity in Multiclassifier Systems}, *    note = {submitted}, *    title = {Creating Diversity in Ensembles Using Artificial Data}, *    year = {2004} * } * </pre> * <p/> <!-- technical-bibtex-end --> * <!-- options-start --> * Valid options are: <p/> *  * <pre> -E *  Desired size of ensemble. *  (default 10)</pre> *  * <pre> -R *  Factor that determines number of artificial examples to generate. *  Specified proportional to training set size. *  (default 1.0)</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.J48)</pre> *  * <pre>  * Options specific to classifier weka.classifiers.trees.J48: * </pre> *  * <pre> -U *  Use unpruned tree.</pre> *  * <pre> -C &lt;pruning confidence&gt; *  Set confidence threshold for pruning. *  (default 0.25)</pre> *  * <pre> -M &lt;minimum number of instances&gt; *  Set minimum number of instances per leaf. *  (default 2)</pre> *  * <pre> -R *  Use reduced error pruning.</pre> *  * <pre> -N &lt;number of folds&gt; *  Set number of folds for reduced error *  pruning. One fold is used as pruning set. *  (default 3)</pre> *  * <pre> -B *  Use binary splits only.</pre> *  * <pre> -S *  Don't perform subtree raising.</pre> *  * <pre> -L *  Do not clean up after the tree has been built.</pre> *  * <pre> -A *  Laplace smoothing for predicted probabilities.</pre> *  * <pre> -Q &lt;seed&gt; *  Seed for random data shuffling (default 1).</pre> *  <!-- options-end --> * * Options after -- are passed to the designated classifier.<p> * * @author Prem Melville (melville@cs.utexas.edu) * @version $Revision: 1.8 $  */public class Decorate     extends RandomizableIteratedSingleClassifierEnhancer    implements TechnicalInformationHandler {          /** for serialization */    static final long serialVersionUID = -6020193348750269931L;      /** Vector of classifiers that make up the committee/ensemble. */    protected Vector m_Committee = null;        /** The desired ensemble size. */    protected int m_DesiredSize = 10;        /** Amount of artificial/random instances to use - specified as a        fraction of the training data size. */    protected double m_ArtSize = 1.0 ;    /** The random number generator. */    protected Random m_Random = new Random(0);        /** Attribute statistics - used for generating artificial examples. */    protected Vector m_AttributeStats = null;      /**   * Constructor.   */  public Decorate() {        m_Classifier = new weka.classifiers.trees.J48();  }  /**   * String describing default classifier.   *    * @return the default classifier classname   */  protected String defaultClassifierString() {        return "weka.classifiers.trees.J48";  }        /**     * Returns an enumeration describing the available options     *     * @return an enumeration of all the available options     */    public Enumeration listOptions() {	Vector newVector = new Vector(8);	newVector.addElement(new Option(              "\tDesired size of ensemble.\n"               + "\t(default 10)",              "E", 1, "-E"));	newVector.addElement(new Option( 	    "\tFactor that determines number of artificial examples to generate.\n"           +"\tSpecified proportional to training set size.\n"           + "\t(default 1.0)",	    "R", 1, "-R"));        Enumeration enu = super.listOptions();        while (enu.hasMoreElements()) {          newVector.addElement(enu.nextElement());        }        return newVector.elements();    }        /**     * Parses a given list of options. <p/>     *        <!-- options-start -->     * Valid options are: <p/>     *      * <pre> -E     *  Desired size of ensemble.     *  (default 10)</pre>     *      * <pre> -R     *  Factor that determines number of artificial examples to generate.     *  Specified proportional to training set size.     *  (default 1.0)</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.J48)</pre>     *      * <pre>      * Options specific to classifier weka.classifiers.trees.J48:     * </pre>     *      * <pre> -U     *  Use unpruned tree.</pre>     *      * <pre> -C &lt;pruning confidence&gt;     *  Set confidence threshold for pruning.     *  (default 0.25)</pre>     *      * <pre> -M &lt;minimum number of instances&gt;     *  Set minimum number of instances per leaf.     *  (default 2)</pre>     *      * <pre> -R     *  Use reduced error pruning.</pre>     *      * <pre> -N &lt;number of folds&gt;     *  Set number of folds for reduced error     *  pruning. One fold is used as pruning set.     *  (default 3)</pre>     *      * <pre> -B     *  Use binary splits only.</pre>     *      * <pre> -S     *  Don't perform subtree raising.</pre>     *      * <pre> -L     *  Do not clean up after the tree has been built.</pre>     *      * <pre> -A     *  Laplace smoothing for predicted probabilities.</pre>     *      * <pre> -Q &lt;seed&gt;     *  Seed for random data shuffling (default 1).</pre>     *      <!-- options-end -->     *     * Options after -- are passed to the designated classifier.<p>     *     * @param options the list of options as an array of strings     * @throws Exception if an option is not supported     */    public void setOptions(String[] options) throws Exception {	String desiredSize = Utils.getOption('E', options);	if (desiredSize.length() != 0) {	    setDesiredSize(Integer.parseInt(desiredSize));	} else {	    setDesiredSize(10);	}		String artSize = Utils.getOption('R', options);	if (artSize.length() != 0) {	    setArtificialSize(Double.parseDouble(artSize));	} else {	    setArtificialSize(1.0);	}        super.setOptions(options);    }        /**     * Gets the current settings of the Classifier.     *     * @return an array of strings suitable for passing to setOptions     */    public String [] getOptions() {      String [] superOptions = super.getOptions();      String [] options = new String [superOptions.length + 4];            int current = 0;      options[current++] = "-E"; options[current++] = "" + getDesiredSize();      options[current++] = "-R"; options[current++] = "" + getArtificialSize();            System.arraycopy(superOptions, 0, options, current,                        superOptions.length);            current += superOptions.length;      while (current < options.length) {        options[current++] = "";      }      return options;    }  /**   * Returns the tip text for this property   * @return tip text for this property suitable for   * displaying in the explorer/experimenter gui   */  public String desiredSizeTipText() {      return "the desired number of member classifiers in the Decorate ensemble. Decorate may terminate "	+"before this size is reached (depending on the value of numIterations). "	+"Larger ensemble sizes usually lead to more accurate models, but increases "	+"training time and model complexity.";  }      /**   * Returns the tip text for this property   * @return tip text for this property suitable for   * displaying in the explorer/experimenter gui   */  public String numIterationsTipText() {    return "the maximum number of Decorate iterations to run. Each iteration generates a classifier, "	+"but does not necessarily add it to the ensemble. Decorate stops when the desired ensemble "	+"size is reached. This parameter should be greater than "	+"equal to the desiredSize. If the desiredSize is not being reached it may help to "	+"increase this value.";  }      /**   * Returns the tip text for this property   * @return tip text for this property suitable for   * displaying in the explorer/experimenter gui   */  public String artificialSizeTipText() {    return "determines the number of artificial examples to use during training. Specified as "	+"a proportion of the training data. Higher values can increase ensemble diversity.";  }  /**   * Returns a string describing classifier   * @return a description suitable for   * displaying in the explorer/experimenter gui   */  public String globalInfo() {      return "DECORATE is a meta-learner for building diverse ensembles of "	  +"classifiers by using specially constructed artificial training "	  +"examples. Comprehensive experiments have demonstrated that this "	  +"technique is consistently more accurate than the base classifier, Bagging and Random Forests."	  +"Decorate also obtains higher accuracy than Boosting on small training sets, and achieves "	  +"comparable performance on larger training sets. \n\n"	  +"For more details see: \n\n"	  + getTechnicalInformation().toString();  }  /**   * Returns an instance of a TechnicalInformation object, containing    * detailed information about the technical background of this class,

⌨️ 快捷键说明

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