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

📄 m5base.java

📁 代码是一个分类器的实现,其中使用了部分weka的源代码。可以将项目导入eclipse运行
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* *    M5Base.java *    Copyright (C) 2000 Mark Hall * *    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. */package weka.classifiers.trees.m5;import weka.classifiers.Classifier;import weka.classifiers.functions.LinearRegression;import weka.core.AdditionalMeasureProducer;import weka.core.Capabilities;import weka.core.FastVector;import weka.core.Instance;import weka.core.Instances;import weka.core.Option;import weka.core.OptionHandler;import weka.core.TechnicalInformation;import weka.core.TechnicalInformationHandler;import weka.core.Utils;import weka.core.TechnicalInformation.Field;import weka.core.TechnicalInformation.Type;import weka.filters.Filter;import weka.filters.supervised.attribute.NominalToBinary;import weka.filters.unsupervised.attribute.RemoveUseless;import weka.filters.unsupervised.attribute.ReplaceMissingValues;import java.util.Enumeration;import java.util.Random;import java.util.Vector;/** * M5Base. Implements base routines * for generating M5 Model trees and rules. <p> *  * The original algorithm M5 was invented by Quinlan: <br/> *  * Quinlan J. R. (1992). Learning with continuous classes. Proceedings of * the Australian Joint Conference on Artificial Intelligence. 343--348. * World Scientific, Singapore. <p/> *  * Yong Wang made improvements and created M5': <br/> *  * Wang, Y and Witten, I. H. (1997). Induction of model trees for * predicting continuous classes. Proceedings of the poster papers of the * European Conference on Machine Learning. University of Economics, * Faculty of Informatics and Statistics, Prague. <p/> * * Valid options are:<p> *  * -U <br> * Use unsmoothed predictions. <p> * * -R <br> * Build regression tree/rule rather than model tree/rule * * @version $Revision: 1.16 $ */public abstract class M5Base   extends Classifier   implements OptionHandler,	     AdditionalMeasureProducer,	     TechnicalInformationHandler {  /**   * the instances covered by the tree/rules   */  private Instances		     m_instances;  /**   * the rule set   */  protected FastVector		     m_ruleSet;  /**   * generate a decision list instead of a single tree.   */  private boolean		     m_generateRules;  /**   * use unsmoothed predictions   */  private boolean		     m_unsmoothedPredictions;  /**   * filter to fill in missing values   */  private ReplaceMissingValues m_replaceMissing;  /**   * filter to convert nominal attributes to binary   */  private NominalToBinary      m_nominalToBinary;    /**   * for removing useless attributes    */  private RemoveUseless m_removeUseless;  /**   * Save instances at each node in an M5 tree for visualization purposes.   */  protected boolean m_saveInstances = false;  /**   * Make a regression tree/rule instead of a model tree/rule   */  protected boolean m_regressionTree;  /**   * Do not prune tree/rules   */  protected boolean m_useUnpruned = false;  /**   * The minimum number of instances to allow at a leaf node   */  protected double m_minNumInstances = 4;  /**   * Constructor   */  public M5Base() {    m_generateRules = false;    m_unsmoothedPredictions = false;    m_useUnpruned = false;    m_minNumInstances = 4;  }  /**   * returns information about the classifier   * @return a description suitable for   * displaying in the explorer/experimenter gui   */  public String globalInfo() {    return         "M5Base. Implements base routines for generating M5 Model trees and "       + "rules\n"      + "The original algorithm M5 was invented by R. Quinlan and Yong Wang "      + "made improvements.\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;    TechnicalInformation 	additional;        result = new TechnicalInformation(Type.INPROCEEDINGS);    result.setValue(Field.AUTHOR, "Ross J. Quinlan");    result.setValue(Field.TITLE, "Learning with Continuous Classes");    result.setValue(Field.BOOKTITLE, "5th Australian Joint Conference on Artificial Intelligence");    result.setValue(Field.YEAR, "1992");    result.setValue(Field.PAGES, "343-348");    result.setValue(Field.PUBLISHER, "World Scientific");    result.setValue(Field.ADDRESS, "Singapore");        additional = result.add(Type.INPROCEEDINGS);    additional.setValue(Field.AUTHOR, "Y. Wang and I. H. Witten");    additional.setValue(Field.TITLE, "Induction of model trees for predicting continuous classes");    additional.setValue(Field.BOOKTITLE, "Poster papers of the 9th European Conference on Machine Learning");    additional.setValue(Field.YEAR, "1997");    additional.setValue(Field.PUBLISHER, "Springer");        return result;  }  /**   * Returns an enumeration describing the available options   *    * @return an enumeration of all the available options   */  public Enumeration listOptions() {    Vector newVector = new Vector(4);    newVector.addElement(new Option("\tUse unpruned tree/rules", 				    "N", 0, "-N"));    newVector.addElement(new Option("\tUse unsmoothed predictions", 				    "U", 0, "-U"));    newVector.addElement(new Option("\tBuild regression tree/rule rather "				    +"than a model tree/rule", 				    "R", 0, "-R"));    newVector.addElement(new Option("\tSet minimum number of instances "				    +"per leaf\n\t(default 4)",				    "M",1,"-M <minimum number of instances>"));    return newVector.elements();  }   /**   * Parses a given list of options. <p/>   *    * Valid options are:<p>   *    * -U <br>   * Use unsmoothed predictions. <p>   *   * -R <br>   * Build a regression tree rather than a model tree. <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 {    setUnpruned(Utils.getFlag('N', options));    setUseUnsmoothed(Utils.getFlag('U', options));    setBuildRegressionTree(Utils.getFlag('R', options));    String optionString = Utils.getOption('M', options);    if (optionString.length() != 0) {      setMinNumInstances((new Double(optionString)).doubleValue());    }    Utils.checkForRemainingOptions(options);  }   /**   * Gets the current settings of the classifier.   *    * @return an array of strings suitable for passing to setOptions   */  public String[] getOptions() {    String[] options = new String[5];    int current = 0;    if (getUnpruned()) {      options[current++] = "-N";    }    if (getUseUnsmoothed()) {      options[current++] = "-U";    }     if (getBuildRegressionTree()) {      options[current++] = "-R";    }    options[current++] = "-M";     options[current++] = ""+getMinNumInstances();    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 unprunedTipText() {    return "Whether unpruned tree/rules are to be generated.";  }  /**   * Use unpruned tree/rules   *   * @param unpruned true if unpruned tree/rules are to be generated   */  public void setUnpruned(boolean unpruned) {    m_useUnpruned = unpruned;  }  /**   * Get whether unpruned tree/rules are being generated   *   * @return true if unpruned tree/rules are to be generated   */  public boolean getUnpruned() {    return m_useUnpruned;  }  /**   * Returns the tip text for this property   *    * @return 		tip text for this property suitable for   * 			displaying in the explorer/experimenter gui   */  public String generateRulesTipText() {    return "Whether to generate rules (decision list) rather than a tree.";  }  /**   * Generate rules (decision list) rather than a tree   *    * @param u true if rules are to be generated   */  protected void setGenerateRules(boolean u) {    m_generateRules = u;  }   /**   * get whether rules are being generated rather than a tree   *    * @return true if rules are to be generated   */

⌨️ 快捷键说明

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