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

📄 attributeselectedclassifier.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. *//* *    AttributeSelectedClassifier.java *    Copyright (C) 2000 Mark Hall * */package weka.classifiers.meta;import weka.attributeSelection.ASEvaluation;import weka.attributeSelection.ASSearch;import weka.attributeSelection.AttributeSelection;import weka.classifiers.SingleClassifierEnhancer;import weka.core.AdditionalMeasureProducer;import weka.core.Capabilities;import weka.core.Drawable;import weka.core.Instance;import weka.core.Instances;import weka.core.Option;import weka.core.OptionHandler;import weka.core.Utils;import weka.core.WeightedInstancesHandler;import weka.core.Capabilities.Capability;import java.util.Enumeration;import java.util.Random;import java.util.Vector;/** <!-- globalinfo-start --> * Dimensionality of training and test data is reduced by attribute selection before being passed on to a classifier. * <p/> <!-- globalinfo-end --> * <!-- options-start --> * Valid options are: <p/> *  * <pre> -E &lt;attribute evaluator specification&gt; *  Full class name of attribute evaluator, followed *  by its options. *  eg: "weka.attributeSelection.CfsSubsetEval -L" *  (default weka.attributeSelection.CfsSubsetEval)</pre> *  * <pre> -S &lt;search method specification&gt; *  Full class name of search method, followed *  by its options. *  eg: "weka.attributeSelection.BestFirst -D 1" *  (default weka.attributeSelection.BestFirst)</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 --> * * @author Mark Hall (mhall@cs.waikato.ac.nz) * @version $Revision: 1.24 $ */public class AttributeSelectedClassifier   extends SingleClassifierEnhancer  implements OptionHandler, Drawable, AdditionalMeasureProducer,             WeightedInstancesHandler {  /** for serialization */  static final long serialVersionUID = -5951805453487947577L;    /** The attribute selection object */  protected AttributeSelection m_AttributeSelection = null;  /** The attribute evaluator to use */  protected ASEvaluation m_Evaluator =     new weka.attributeSelection.CfsSubsetEval();  /** The search method to use */  protected ASSearch m_Search = new weka.attributeSelection.BestFirst();  /** The header of the dimensionally reduced data */  protected Instances m_ReducedHeader;  /** The number of class vals in the training data (1 if class is numeric) */  protected int m_numClasses;  /** The number of attributes selected by the attribute selection phase */  protected double m_numAttributesSelected;  /** The time taken to select attributes in milliseconds */  protected double m_selectionTime;  /** The time taken to select attributes AND build the classifier */  protected double m_totalTime;    /**   * String describing default classifier.   *    * @return the default classifier classname   */  protected String defaultClassifierString() {        return "weka.classifiers.trees.J48";  }    /**   * Default constructor.   */  public AttributeSelectedClassifier() {    m_Classifier = new weka.classifiers.trees.J48();  }  /**   * Returns a string describing this search method   * @return a description of the search method suitable for   * displaying in the explorer/experimenter gui   */  public String globalInfo() {    return "Dimensionality of training and test data is reduced by "      +"attribute selection before being passed on to a classifier.";  }  /**   * Returns an enumeration describing the available options.   *   * @return an enumeration of all the available options.   */  public Enumeration listOptions() {     Vector newVector = new Vector(3);        newVector.addElement(new Option(	      "\tFull class name of attribute evaluator, followed\n"	      + "\tby its options.\n"	      + "\teg: \"weka.attributeSelection.CfsSubsetEval -L\"\n"	      + "\t(default weka.attributeSelection.CfsSubsetEval)",	      "E", 1, "-E <attribute evaluator specification>"));    newVector.addElement(new Option(	      "\tFull class name of search method, followed\n"	      + "\tby its options.\n"	      + "\teg: \"weka.attributeSelection.BestFirst -D 1\"\n"	      + "\t(default weka.attributeSelection.BestFirst)",	      "S", 1, "-S <search method specification>"));        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 &lt;attribute evaluator specification&gt;   *  Full class name of attribute evaluator, followed   *  by its options.   *  eg: "weka.attributeSelection.CfsSubsetEval -L"   *  (default weka.attributeSelection.CfsSubsetEval)</pre>   *    * <pre> -S &lt;search method specification&gt;   *  Full class name of search method, followed   *  by its options.   *  eg: "weka.attributeSelection.BestFirst -D 1"   *  (default weka.attributeSelection.BestFirst)</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 -->   *   * @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 {    // same for attribute evaluator    String evaluatorString = Utils.getOption('E', options);    if (evaluatorString.length() == 0)      evaluatorString = weka.attributeSelection.CfsSubsetEval.class.getName();    String [] evaluatorSpec = Utils.splitOptions(evaluatorString);    if (evaluatorSpec.length == 0) {      throw new Exception("Invalid attribute evaluator specification string");    }    String evaluatorName = evaluatorSpec[0];    evaluatorSpec[0] = "";    setEvaluator(ASEvaluation.forName(evaluatorName, evaluatorSpec));    // same for search method    String searchString = Utils.getOption('S', options);    if (searchString.length() == 0)      searchString = weka.attributeSelection.BestFirst.class.getName();    String [] searchSpec = Utils.splitOptions(searchString);    if (searchSpec.length == 0) {      throw new Exception("Invalid search specification string");    }    String searchName = searchSpec[0];    searchSpec[0] = "";    setSearch(ASSearch.forName(searchName, searchSpec));    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;    // same attribute evaluator    options[current++] = "-E";    options[current++] = "" +getEvaluatorSpec();        // same for search    options[current++] = "-S";    options[current++] = "" + getSearchSpec();    System.arraycopy(superOptions, 0, options, current, 		     superOptions.length);        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 evaluatorTipText() {    return "Set the attribute evaluator to use. This evaluator is used "      +"during the attribute selection phase before the classifier is "      +"invoked.";

⌨️ 快捷键说明

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