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

📄 racedincrementallogitboost.java

📁 代码是一个分类器的实现,其中使用了部分weka的源代码。可以将项目导入eclipse运行
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    Vector newVector = new Vector(9);    newVector.addElement(new Option(	      "\tMinimum size of chunks.\n"	      +"\t(default 500)",	      "C", 1, "-C <num>"));    newVector.addElement(new Option(	      "\tMaximum size of chunks.\n"	      +"\t(default 2000)",	      "M", 1, "-M <num>"));    newVector.addElement(new Option(	      "\tSize of validation set.\n"	      +"\t(default 1000)",	      "V", 1, "-V <num>"));    newVector.addElement(new Option(	      "\tCommittee pruning to perform.\n"	      +"\t0=none, 1=log likelihood (default)",	      "P", 1, "-P <pruning type>"));    newVector.addElement(new Option(	      "\tUse resampling for boosting.",	      "Q", 0, "-Q"));    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> -C &lt;num&gt;   *  Minimum size of chunks.   *  (default 500)</pre>   *    * <pre> -M &lt;num&gt;   *  Maximum size of chunks.   *  (default 2000)</pre>   *    * <pre> -V &lt;num&gt;   *  Size of validation set.   *  (default 1000)</pre>   *    * <pre> -P &lt;pruning type&gt;   *  Committee pruning to perform.   *  0=none, 1=log likelihood (default)</pre>   *    * <pre> -Q   *  Use resampling for boosting.</pre>   *    * <pre> -S &lt;num&gt;   *  Random number seed.   *  (default 1)</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.DecisionStump)</pre>   *    * <pre>    * Options specific to classifier weka.classifiers.trees.DecisionStump:   * </pre>   *    * <pre> -D   *  If set, classifier is run in debug mode and   *  may output additional info to the console</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 minChunkSize = Utils.getOption('C', options);    if (minChunkSize.length() != 0) {      setMinChunkSize(Integer.parseInt(minChunkSize));    } else {      setMinChunkSize(500);    }    String maxChunkSize = Utils.getOption('M', options);    if (maxChunkSize.length() != 0) {      setMaxChunkSize(Integer.parseInt(maxChunkSize));    } else {      setMaxChunkSize(2000);    }    String validationChunkSize = Utils.getOption('V', options);    if (validationChunkSize.length() != 0) {      setValidationChunkSize(Integer.parseInt(validationChunkSize));    } else {      setValidationChunkSize(1000);    }    String pruneType = Utils.getOption('P', options);    if (pruneType.length() != 0) {      setPruningType(new SelectedTag(Integer.parseInt(pruneType), TAGS_PRUNETYPE));    } else {      setPruningType(new SelectedTag(PRUNETYPE_LOGLIKELIHOOD, TAGS_PRUNETYPE));    }    setUseResampling(Utils.getFlag('Q', options));    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 + 9];    int current = 0;    if (getUseResampling()) {      options[current++] = "-Q";    }    options[current++] = "-C"; options[current++] = "" + getMinChunkSize();    options[current++] = "-M"; options[current++] = "" + getMaxChunkSize();    options[current++] = "-V"; options[current++] = "" + getValidationChunkSize();    options[current++] = "-P"; options[current++] = "" + m_PruningType;    System.arraycopy(superOptions, 0, options, current, 		     superOptions.length);    current += superOptions.length;    while (current < options.length) {      options[current++] = "";    }    return options;  }  /**   * @return a description of the classifier suitable for   * displaying in the explorer/experimenter gui   */  public String globalInfo() {    return "Classifier for incremental learning of large datasets by way of racing logit-boosted committees.";  }  /**   * Set the base learner.   *   * @param newClassifier 		the classifier to use.   * @throws IllegalArgumentException 	if base classifier cannot handle numeric    * 					class   */  public void setClassifier(Classifier newClassifier) {    Capabilities cap = newClassifier.getCapabilities();        if (!cap.handles(Capability.NUMERIC_CLASS))      throw new IllegalArgumentException("Base classifier cannot handle numeric class!");          super.setClassifier(newClassifier);  }  /**   * @return tip text for this property suitable for   * displaying in the explorer/experimenter gui   */  public String minChunkSizeTipText() {    return "The minimum number of instances to train the base learner with.";  }  /**   * Set the minimum chunk size   *   * @param chunkSize the minimum chunk size   */  public void setMinChunkSize(int chunkSize) {    m_minChunkSize = chunkSize;  }  /**   * Get the minimum chunk size   *   * @return the chunk size   */  public int getMinChunkSize() {    return m_minChunkSize;  }  /**   * @return tip text for this property suitable for   * displaying in the explorer/experimenter gui   */  public String maxChunkSizeTipText() {    return "The maximum number of instances to train the base learner with. The chunk sizes used will start at minChunkSize and grow twice as large for as many times as they are less than or equal to the maximum size.";  }  /**   * Set the maximum chunk size   *   * @param chunkSize the maximum chunk size   */  public void setMaxChunkSize(int chunkSize) {    m_maxChunkSize = chunkSize;  }  /**   * Get the maximum chunk size   *   * @return the chunk size   */  public int getMaxChunkSize() {    return m_maxChunkSize;  }  /**   * @return tip text for this property suitable for   * displaying in the explorer/experimenter gui   */  public String validationChunkSizeTipText() {    return "The number of instances to hold out for validation. These instances will be taken from the beginning of the stream, so learning will not start until these instances have been consumed first.";  }  /**   * Set the validation chunk size   *   * @param chunkSize the validation chunk size   */  public void setValidationChunkSize(int chunkSize) {    m_validationChunkSize = chunkSize;  }  /**   * Get the validation chunk size   *   * @return the chunk size   */  public int getValidationChunkSize() {    return m_validationChunkSize;  }  /**   * @return tip text for this property suitable for   * displaying in the explorer/experimenter gui   */  public String pruningTypeTipText() {    return "The pruning method to use within each committee. Log likelihood pruning will discard new models if they have a negative effect on the log likelihood of the validation data.";  }  /**   * Set the pruning type   *   * @param pruneType the pruning type   */  public void setPruningType(SelectedTag pruneType) {    if (pruneType.getTags() == TAGS_PRUNETYPE) {      m_PruningType = pruneType.getSelectedTag().getID();    }  }  /**   * Get the pruning type   *   * @return the type   */  public SelectedTag getPruningType() {    return new SelectedTag(m_PruningType, TAGS_PRUNETYPE);  }  /**   * @return tip text for this property suitable for   * displaying in the explorer/experimenter gui   */  public String useResamplingTipText() {    return "Force the use of resampling data rather than using the weight-handling capabilities of the base classifier. Resampling is always used if the base classifier cannot handle weighted instances.";  }  /**   * Set resampling mode   *   * @param r true if resampling should be done   */  public void setUseResampling(boolean r) {        m_UseResampling = r;  }  /**   * Get whether resampling is turned on   *   * @return true if resampling output is on   */  public boolean getUseResampling() {        return m_UseResampling;  }  /**   * Get the best committee chunk size   *    * @return the best committee chunk size   */  public int getBestCommitteeChunkSize() {    if (m_bestCommittee != null) {      return m_bestCommittee.chunkSize();    }    else return 0;  }  /**   * Get the number of members in the best committee   *    * @return the number of members   */  public int getBestCommitteeSize() {    if (m_bestCommittee != null) {      return m_bestCommittee.committeeSize();    }    else return 0;  }  /**   * Get the best committee's error on the validation data   *    * @return the best committee's error   */  public double getBestCommitteeErrorEstimate() {    if (m_bestCommittee != null) {      try {	return m_bestCommittee.validationError() * 100.0;      } catch (Exception e) {	System.err.println(e.getMessage());	return 100.0;      }    }    else return 100.0;  }  /**   * Get the best committee's log likelihood on the validation data   *    * @return best committee's log likelihood   */  public double getBestCommitteeLLEstimate() {    if (m_bestCommittee != null) {      try {	return m_bestCommittee.logLikelihood();      } catch (Exception e) {	System.err.println(e.getMessage());	return Double.MAX_VALUE;      }    }    else return Double.MAX_VALUE;  }    /**   * Returns description of the boosted classifier.   *   * @return description of the boosted classifier as a string   */  public String toString() {            if (m_bestCommittee != null) {      return m_bestCommittee.toString();    } else {      if ((m_validationSetChanged || m_zeroR == null) && m_validationSet != null	  && m_validationSet.numInstances() > 0) {	m_zeroR = new ZeroR();	try {	  m_zeroR.buildClassifier(m_validationSet);	} catch (Exception e) {}	m_validationSetChanged = false;      }      if (m_zeroR != null) {	return ("RacedIncrementalLogitBoost: insufficient data to build model, resorting to ZeroR:\n\n"		+ m_zeroR.toString());      }      else return ("RacedIncrementalLogitBoost: no model built yet.");    }  }  /**   * Main method for this class.   *    * @param argv the commandline parameters   */  public static void main(String[] argv) {    runClassifier(new RacedIncrementalLogitBoost(), argv);  }}

⌨️ 快捷键说明

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