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

📄 plsfilter.java

📁 代码是一个分类器的实现,其中使用了部分weka的源代码。可以将项目导入eclipse运行
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
   *  Updates the class attribute as well.   *  (default: off)</pre>   *    * <pre> -M   *  Turns replacing of missing values on.   *  (default: off)</pre>   *    * <pre> -A &lt;SIMPLS|PLS1&gt;   *  The algorithm to use.   *  (default: PLS1)</pre>   *    * <pre> -P &lt;none|center|standardize&gt;   *  The type of preprocessing that is applied to the data.   *  (default: center)</pre>   *    <!-- options-end -->   *   * @param options	the options to use   * @throws Exception	if the option setting fails   */  public void setOptions(String[] options) throws Exception {    String	tmpStr;    super.setOptions(options);    tmpStr = Utils.getOption("C", options);    if (tmpStr.length() != 0)      setNumComponents(Integer.parseInt(tmpStr));    else      setNumComponents(20);    setPerformPrediction(Utils.getFlag("U", options));        setReplaceMissing(Utils.getFlag("M", options));        tmpStr = Utils.getOption("A", options);    if (tmpStr.length() != 0)      setAlgorithm(new SelectedTag(tmpStr, TAGS_ALGORITHM));    else      setAlgorithm(new SelectedTag(ALGORITHM_PLS1, TAGS_ALGORITHM));        tmpStr = Utils.getOption("P", options);    if (tmpStr.length() != 0)      setPreprocessing(new SelectedTag(tmpStr, TAGS_PREPROCESSING));    else      setPreprocessing(new SelectedTag(PREPROCESSING_CENTER, TAGS_PREPROCESSING));  }  /**   * Returns the tip text for this property   *   * @return 		tip text for this property suitable for   * 			displaying in the explorer/experimenter gui   */  public String numComponentsTipText() {    return "The number of components to compute.";  }  /**   * sets the maximum number of attributes to use.   *    * @param value	the maximum number of attributes   */  public void setNumComponents(int value) {    m_NumComponents = value;  }  /**   * returns the maximum number of attributes to use.   *    * @return		the current maximum number of attributes   */  public int getNumComponents() {    return m_NumComponents;  }  /**   * Returns the tip text for this property   *   * @return 		tip text for this property suitable for   * 			displaying in the explorer/experimenter gui   */  public String performPredictionTipText() {    return "Whether to update the class attribute with the predicted value.";  }  /**   * Sets whether to update the class attribute with the predicted value.   *    * @param value	if true the class value will be replaced by the    * 			predicted value.   */  public void setPerformPrediction(boolean value) {    m_PerformPrediction = value;  }  /**   * Gets whether the class attribute is updated with the predicted value.   *    * @return		true if the class attribute is updated   */  public boolean getPerformPrediction() {    return m_PerformPrediction;  }  /**   * Returns the tip text for this property   *    * @return 		tip text for this property suitable for   * 			displaying in the explorer/experimenter gui   */  public String algorithmTipText() {    return "Sets the type of algorithm to use.";  }  /**   * Sets the type of algorithm to use    *   * @param value 	the algorithm type   */  public void setAlgorithm(SelectedTag value) {    if (value.getTags() == TAGS_ALGORITHM) {      m_Algorithm = value.getSelectedTag().getID();    }  }  /**   * Gets the type of algorithm to use    *   * @return 		the current algorithm type.   */  public SelectedTag getAlgorithm() {    return new SelectedTag(m_Algorithm, TAGS_ALGORITHM);  }  /**   * Returns the tip text for this property   *   * @return 		tip text for this property suitable for   * 			displaying in the explorer/experimenter gui   */  public String replaceMissingTipText() {    return "Whether to replace missing values.";  }  /**   * Sets whether to replace missing values.   *    * @param value	if true missing values are replaced with the   * 			ReplaceMissingValues filter.   */  public void setReplaceMissing(boolean value) {    m_ReplaceMissing = value;  }  /**   * Gets whether missing values are replace.   *    * @return		true if missing values are replaced with the    * 			ReplaceMissingValues filter   */  public boolean getReplaceMissing() {    return m_ReplaceMissing;  }  /**   * Returns the tip text for this property   *    * @return 		tip text for this property suitable for   * 			displaying in the explorer/experimenter gui   */  public String preprocessingTipText() {    return "Sets the type of preprocessing to use.";  }  /**   * Sets the type of preprocessing to use    *   * @param value 	the preprocessing type   */  public void setPreprocessing(SelectedTag value) {    if (value.getTags() == TAGS_PREPROCESSING) {      m_Preprocessing = value.getSelectedTag().getID();    }  }  /**   * Gets the type of preprocessing to use    *   * @return 		the current preprocessing type.   */  public SelectedTag getPreprocessing() {    return new SelectedTag(m_Preprocessing, TAGS_PREPROCESSING);  }  /**   * Determines the output format based on the input format and returns    * this. In case the output format cannot be returned immediately, i.e.,   * immediateOutputFormat() returns false, then this method will be called   * from batchFinished().   *   * @param inputFormat     the input format to base the output format on   * @return                the output format   * @throws Exception      in case the determination goes wrong   * @see   #hasImmediateOutputFormat()   * @see   #batchFinished()   */  protected Instances determineOutputFormat(Instances inputFormat)     throws Exception {    // generate header    FastVector atts = new FastVector();    String prefix = getAlgorithm().getSelectedTag().getReadable();    for (int i = 0; i < getNumComponents(); i++)      atts.addElement(new Attribute(prefix + "_" + (i+1)));    atts.addElement(new Attribute("Class"));    Instances result = new Instances(prefix, atts, 0);    result.setClassIndex(result.numAttributes() - 1);        return result;  }    /**   * returns the data minus the class column as matrix   *    * @param instances	the data to work on   * @return		the data without class attribute   */  protected Matrix getX(Instances instances) {    double[][]	x;    double[]	values;    Matrix	result;    int		i;    int		n;    int		j;    int		clsIndex;        clsIndex = instances.classIndex();    x        = new double[instances.numInstances()][];        for (i = 0; i < instances.numInstances(); i++) {      values = instances.instance(i).toDoubleArray();      x[i]   = new double[values.length - 1];            j = 0;      for (n = 0; n < values.length; n++) {	if (n != clsIndex) {	  x[i][j] = values[n];	  j++;	}      }    }        result = new Matrix(x);        return result;  }    /**   * returns the data minus the class column as matrix   *    * @param instance	the instance to work on   * @return		the data without the class attribute   */  protected Matrix getX(Instance instance) {    double[][]	x;    double[]	values;    Matrix	result;        x = new double[1][];    values = instance.toDoubleArray();    x[0] = new double[values.length - 1];    System.arraycopy(values, 0, x[0], 0, values.length - 1);        result = new Matrix(x);        return result;  }    /**   * returns the data class column as matrix   *    * @param instances	the data to work on   * @return		the class attribute   */  protected Matrix getY(Instances instances) {    double[][]	y;    Matrix	result;    int		i;        y = new double[instances.numInstances()][1];    for (i = 0; i < instances.numInstances(); i++)      y[i][0] = instances.instance(i).classValue();        result = new Matrix(y);        return result;  }    /**   * returns the data class column as matrix   *    * @param instance	the instance to work on   * @return		the class attribute   */  protected Matrix getY(Instance instance) {    double[][]	y;    Matrix	result;        y = new double[1][1];    y[0][0] = instance.classValue();        result = new Matrix(y);        return result;  }    /**   * returns the X and Y matrix again as Instances object, based on the given   * header (must have a class attribute set).   *    * @param header	the format of the instance object   * @param x		the X matrix (data)   * @param y		the Y matrix (class)   * @return		the assembled data   */  protected Instances toInstances(Instances header, Matrix x, Matrix y) {    double[]	values;    int		i;    int		n;    Instances	result;    int		rows;    int		cols;    int		offset;    int		clsIdx;        result = new Instances(header, 0);        rows   = x.getRowDimension();    cols   = x.getColumnDimension();    clsIdx = header.classIndex();        for (i = 0; i < rows; i++) {      values = new double[cols + 1];      offset = 0;      for (n = 0; n < values.length; n++) {	if (n == clsIdx) {	  offset--;	  values[n] = y.get(i, 0);	}	else {	  values[n] = x.get(i, n + offset);	}      }            result.add(new Instance(1.0, values));    }        return result;  }    /**   * returns the given column as a vector (actually a n x 1 matrix)   *    * @param m		the matrix to work on   * @param columnIndex	the column to return   * @return		the column as n x 1 matrix   */  protected Matrix columnAsVector(Matrix m, int columnIndex) {    Matrix	result;    int		i;        result = new Matrix(m.getRowDimension(), 1);        for (i = 0; i < m.getRowDimension(); i++)      result.set(i, 0, m.get(i, columnIndex));        return result;  }    /**   * stores the data from the (column) vector in the matrix at the specified    * index

⌨️ 快捷键说明

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