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

📄 attributeselection.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. *//* *    AttributeSelection.java *    Copyright (C) 1999 Mark Hall * */package weka.filters.supervised.attribute;import weka.attributeSelection.ASEvaluation;import weka.attributeSelection.ASSearch;import weka.attributeSelection.AttributeEvaluator;import weka.attributeSelection.AttributeTransformer;import weka.attributeSelection.BestFirst;import weka.attributeSelection.CfsSubsetEval;import weka.attributeSelection.Ranker;import weka.attributeSelection.UnsupervisedAttributeEvaluator;import weka.attributeSelection.UnsupervisedSubsetEvaluator;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.SparseInstance;import weka.core.Utils;import weka.core.Capabilities.Capability;import weka.filters.Filter;import weka.filters.SupervisedFilter;import java.util.Enumeration;import java.util.Vector;/**  <!-- globalinfo-start --> * A supervised attribute filter that can be used to select attributes. It is very flexible and allows various search and evaluation methods to be combined. * <p/> <!-- globalinfo-end --> *  <!-- options-start --> * Valid options are: <p/> *  * <pre> -S &lt;"Name of search class [search options]"&gt; *  Sets search method for subset evaluators. *  eg. -S "weka.attributeSelection.BestFirst -S 8"</pre> *  * <pre> -E &lt;"Name of attribute/subset evaluation class [evaluator options]"&gt; *  Sets attribute/subset evaluator. *  eg. -E "weka.attributeSelection.CfsSubsetEval -L"</pre> *  * <pre>  * Options specific to evaluator weka.attributeSelection.CfsSubsetEval: * </pre> *  * <pre> -M *  Treat missing values as a seperate *  value.</pre> *  * <pre> -L *  Don't include locally predictive attributes.</pre> *  * <pre>  * Options specific to search weka.attributeSelection.BestFirst: * </pre> *  * <pre> -P &lt;start set&gt; *  Specify a starting set of attributes. *  Eg. 1,3,5-7.</pre> *  * <pre> -D &lt;0 = backward | 1 = forward | 2 = bi-directional&gt; *  Direction of search. (default = 1).</pre> *  * <pre> -N &lt;num&gt; *  Number of non-improving nodes to *  consider before terminating search.</pre> *  * <pre> -S &lt;num&gt; *  Size of lookup cache for evaluated subsets. *  Expressed as a multiple of the number of *  attributes in the data set. (default = 1)</pre> *  <!-- options-end --> * * @author Mark Hall (mhall@cs.waikato.ac.nz) * @version $Revision: 1.6 $ */public class AttributeSelection   extends Filter  implements SupervisedFilter, OptionHandler {    /** for serialization */  static final long serialVersionUID = -296211247688169716L;  /** the attribute selection evaluation object */  private weka.attributeSelection.AttributeSelection m_trainSelector;  /** the attribute evaluator to use */  private ASEvaluation m_ASEvaluator;  /** the search method if any */  private ASSearch m_ASSearch;  /** holds a copy of the full set of valid  options passed to the filter */  private String [] m_FilterOptions;  /** holds the selected attributes  */  private int [] m_SelectedAttributes;  /**   * Returns a string describing this filter   *   * @return a description of the filter suitable for   * displaying in the explorer/experimenter gui   */  public String globalInfo() {    return "A supervised attribute filter that can be used to select "       + "attributes. It is very flexible and allows various search "       + "and evaluation methods to be combined.";  }  /**   * Constructor   */  public AttributeSelection () {        resetOptions();  }  /**   * Returns an enumeration describing the available options.   * @return an enumeration of all the available options.   */  public Enumeration listOptions() {        Vector newVector = new Vector(6);    newVector.addElement(new Option(	"\tSets search method for subset evaluators.\n"	+ "\teg. -S \"weka.attributeSelection.BestFirst -S 8\"", 	"S", 1,	"-S <\"Name of search class [search options]\">"));    newVector.addElement(new Option(	"\tSets attribute/subset evaluator.\n"	+ "\teg. -E \"weka.attributeSelection.CfsSubsetEval -L\"",	"E", 1,	"-E <\"Name of attribute/subset evaluation class [evaluator options]\">"));        if ((m_ASEvaluator != null) && (m_ASEvaluator instanceof OptionHandler)) {      Enumeration enu = ((OptionHandler)m_ASEvaluator).listOptions();            newVector.addElement(new Option("", "", 0, "\nOptions specific to "	   + "evaluator " + m_ASEvaluator.getClass().getName() + ":"));      while (enu.hasMoreElements()) {	newVector.addElement((Option)enu.nextElement());      }    }      if ((m_ASSearch != null) && (m_ASSearch instanceof OptionHandler)) {      Enumeration enu = ((OptionHandler)m_ASSearch).listOptions();          newVector.addElement(new Option("", "", 0, "\nOptions specific to "	      + "search " + m_ASSearch.getClass().getName() + ":"));      while (enu.hasMoreElements()) {	newVector.addElement((Option)enu.nextElement());      }    }    return newVector.elements();  }  /**   * Parses a given list of options. <p/>   *    <!-- options-start -->   * Valid options are: <p/>   *    * <pre> -S &lt;"Name of search class [search options]"&gt;   *  Sets search method for subset evaluators.   *  eg. -S "weka.attributeSelection.BestFirst -S 8"</pre>   *    * <pre> -E &lt;"Name of attribute/subset evaluation class [evaluator options]"&gt;   *  Sets attribute/subset evaluator.   *  eg. -E "weka.attributeSelection.CfsSubsetEval -L"</pre>   *    * <pre>    * Options specific to evaluator weka.attributeSelection.CfsSubsetEval:   * </pre>   *    * <pre> -M   *  Treat missing values as a seperate   *  value.</pre>   *    * <pre> -L   *  Don't include locally predictive attributes.</pre>   *    * <pre>    * Options specific to search weka.attributeSelection.BestFirst:   * </pre>   *    * <pre> -P &lt;start set&gt;   *  Specify a starting set of attributes.   *  Eg. 1,3,5-7.</pre>   *    * <pre> -D &lt;0 = backward | 1 = forward | 2 = bi-directional&gt;   *  Direction of search. (default = 1).</pre>   *    * <pre> -N &lt;num&gt;   *  Number of non-improving nodes to   *  consider before terminating search.</pre>   *    * <pre> -S &lt;num&gt;   *  Size of lookup cache for evaluated subsets.   *  Expressed as a multiple of the number of   *  attributes in the data set. (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 {        String optionString;    resetOptions();    if (Utils.getFlag('X',options)) {	throw new Exception("Cross validation is not a valid option"			    + " when using attribute selection as a Filter.");    }    optionString = Utils.getOption('E',options);    if (optionString.length() != 0) {      optionString = optionString.trim();      // split a quoted evaluator name from its options (if any)      int breakLoc = optionString.indexOf(' ');      String evalClassName = optionString;      String evalOptionsString = "";      String [] evalOptions=null;      if (breakLoc != -1) {	evalClassName = optionString.substring(0, breakLoc);	evalOptionsString = optionString.substring(breakLoc).trim();	evalOptions = Utils.splitOptions(evalOptionsString);      }      setEvaluator(ASEvaluation.forName(evalClassName, evalOptions));    }    if (m_ASEvaluator instanceof AttributeEvaluator) {      setSearch(new Ranker());    }    optionString = Utils.getOption('S',options);    if (optionString.length() != 0) {      optionString = optionString.trim();      int breakLoc = optionString.indexOf(' ');      String SearchClassName = optionString;      String SearchOptionsString = "";      String [] SearchOptions=null;      if (breakLoc != -1) {	SearchClassName = optionString.substring(0, breakLoc);	SearchOptionsString = optionString.substring(breakLoc).trim();	SearchOptions = Utils.splitOptions(SearchOptionsString);      }      setSearch(ASSearch.forName(SearchClassName, SearchOptions));    }    Utils.checkForRemainingOptions(options);  }

⌨️ 快捷键说明

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