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

📄 ensembleevaluation.java

📁 wekaUT是 university texas austin 开发的基于weka的半指导学习(semi supervised learning)的分类器
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    }  }  /**   * Returns value of kappa statistic if class is nominal.   *   * @return the value of the kappa statistic   */  public final double kappa() {        double[] sumRows = new double[m_ConfusionMatrix.length];    double[] sumColumns = new double[m_ConfusionMatrix.length];    double sumOfWeights = 0;    for (int i = 0; i < m_ConfusionMatrix.length; i++) {      for (int j = 0; j < m_ConfusionMatrix.length; j++) {	sumRows[i] += m_ConfusionMatrix[i][j];	sumColumns[j] += m_ConfusionMatrix[i][j];	sumOfWeights += m_ConfusionMatrix[i][j];      }    }    double correct = 0, chanceAgreement = 0;    for (int i = 0; i < m_ConfusionMatrix.length; i++) {      chanceAgreement += (sumRows[i] * sumColumns[i]);      correct += m_ConfusionMatrix[i][i];    }    chanceAgreement /= (sumOfWeights * sumOfWeights);    correct /= sumOfWeights;    if (chanceAgreement < 1) {      return (correct - chanceAgreement) / (1 - chanceAgreement);    } else {      return 1;    }  }  /**   * Returns the correlation coefficient if the class is numeric.   *   * @return the correlation coefficient   * @exception Exception if class is not numeric   */  public final double correlationCoefficient() throws Exception {    if (m_ClassIsNominal) {      throw	new Exception("Can't compute correlation coefficient: " + 		      "class is nominal!");    }    double correlation = 0;    double varActual =       m_SumSqrClass - m_SumClass * m_SumClass / m_WithClass;    double varPredicted =       m_SumSqrPredicted - m_SumPredicted * m_SumPredicted /       m_WithClass;    double varProd =       m_SumClassPredicted - m_SumClass * m_SumPredicted / m_WithClass;    if (Utils.smOrEq(varActual * varPredicted, 0.0)) {      correlation = 0.0;    } else {      correlation = varProd / Math.sqrt(varActual * varPredicted);    }    return correlation;  }  /**   * Returns the mean absolute error. Refers to the error of the   * predicted values for numeric classes, and the error of the    * predicted probability distribution for nominal classes.   *   * @return the mean absolute error    */  public final double meanAbsoluteError() {    return m_SumAbsErr / m_WithClass;  }  /**   * Returns the mean absolute error of the prior.   *   * @return the mean absolute error    */  public final double meanPriorAbsoluteError() {    return m_SumPriorAbsErr / m_WithClass;  }  /**   * Returns the relative absolute error.   *   * @return the relative absolute error    * @exception Exception if it can't be computed   */  public final double relativeAbsoluteError() throws Exception {    return 100 * meanAbsoluteError() / meanPriorAbsoluteError();  }    /**   * Returns the root mean squared error.   *   * @return the root mean squared error    */  public final double rootMeanSquaredError() {    return Math.sqrt(m_SumSqrErr / m_WithClass);  }    /**   * Returns the root mean prior squared error.   *   * @return the root mean prior squared error    */  public final double rootMeanPriorSquaredError() {    return Math.sqrt(m_SumPriorSqrErr / m_WithClass);  }    /**   * Returns the root relative squared error if the class is numeric.   *   * @return the root relative squared error    */  public final double rootRelativeSquaredError() {    return 100.0 * rootMeanSquaredError() /       rootMeanPriorSquaredError();  }  /**   * Calculate the entropy of the prior distribution   *   * @return the entropy of the prior distribution   * @exception Exception if the class is not nominal   */  public final double priorEntropy() throws Exception {    if (!m_ClassIsNominal) {      throw	new Exception("Can't compute entropy of class prior: " + 		      "class numeric!");    }    double entropy = 0;    for(int i = 0; i < m_NumClasses; i++) {      entropy -= m_ClassPriors[i] / m_ClassPriorsSum 	* Utils.log2(m_ClassPriors[i] / m_ClassPriorsSum);    }    return entropy;  }  /**   * Return the total Kononenko & Bratko Information score in bits   *   * @return the K&B information score   * @exception Exception if the class is not nominal   */  public final double KBInformation() throws Exception {    if (!m_ClassIsNominal) {      throw	new Exception("Can't compute K&B Info score: " + 		      "class numeric!");    }    return m_SumKBInfo;  }  /**   * Return the Kononenko & Bratko Information score in bits per    * instance.   *   * @return the K&B information score   * @exception Exception if the class is not nominal   */  public final double KBMeanInformation() throws Exception {    if (!m_ClassIsNominal) {      throw	new Exception("Can't compute K&B Info score: "		       + "class numeric!");    }    return m_SumKBInfo / m_WithClass;  }  /**   * Return the Kononenko & Bratko Relative Information score   *   * @return the K&B relative information score   * @exception Exception if the class is not nominal   */  public final double KBRelativeInformation() throws Exception {    if (!m_ClassIsNominal) {      throw	new Exception("Can't compute K&B Info score: " + 		      "class numeric!");    }    return 100.0 * KBInformation() / priorEntropy();  }  /**   * Returns the total entropy for the null model   *    * @return the total null model entropy   */  public final double SFPriorEntropy() {    return m_SumPriorEntropy;  }  /**   * Returns the entropy per instance for the null model   *    * @return the null model entropy per instance   */  public final double SFMeanPriorEntropy() {    return m_SumPriorEntropy / m_WithClass;  }  /**   * Returns the total entropy for the scheme   *    * @return the total scheme entropy   */  public final double SFSchemeEntropy() {    return m_SumSchemeEntropy;  }  /**   * Returns the entropy per instance for the scheme   *    * @return the scheme entropy per instance   */  public final double SFMeanSchemeEntropy() {    return m_SumSchemeEntropy / m_WithClass;  }  /**   * Returns the total SF, which is the null model entropy minus   * the scheme entropy.   *    * @return the total SF   */  public final double SFEntropyGain() {    return m_SumPriorEntropy - m_SumSchemeEntropy;  }  /**   * Returns the SF per instance, which is the null model entropy   * minus the scheme entropy, per instance.   *    * @return the SF per instance   */  public final double SFMeanEntropyGain() {        return (m_SumPriorEntropy - m_SumSchemeEntropy) / m_WithClass;  }  /**   * Output the cumulative margin distribution as a string suitable   * for input for gnuplot or similar package.   *   * @return the cumulative margin distribution   * @exception Exception if the class attribute is nominal   */  public String toCumulativeMarginDistributionString() throws Exception {    if (!m_ClassIsNominal) {      throw new Exception("Class must be nominal for margin distributions");    }    String result = "";    double cumulativeCount = 0;    double margin;    for(int i = 0; i <= k_MarginResolution; i++) {      if (m_MarginCounts[i] != 0) {	cumulativeCount += m_MarginCounts[i];	margin = (double)i * 2.0 / k_MarginResolution - 1.0;	result = result + Utils.doubleToString(margin, 7, 3) + ' ' 	+ Utils.doubleToString(cumulativeCount * 100 			       / m_WithClass, 7, 3) + '\n';      } else if (i == 0) {	result = Utils.doubleToString(-1.0, 7, 3) + ' ' 	+ Utils.doubleToString(0, 7, 3) + '\n';      }    }    return result;  }  /**   * Calls toSummaryString() with no title and no complexity stats   *   * @return a summary description of the classifier evaluation   */  public String toSummaryString() {    return toSummaryString("", false);  }  /**   * Calls toSummaryString() with a default title.   *   * @param printComplexityStatistics if true, complexity statistics are   * returned as well   */  public String toSummaryString(boolean printComplexityStatistics) {        return toSummaryString("=== Summary ===\n", printComplexityStatistics);  }  /**   * Outputs the performance statistics in summary form. Lists    * number (and percentage) of instances classified correctly,    * incorrectly and unclassified. Outputs the total number of    * instances classified, and the number of instances (if any)    * that had no class value provided.    *   * @param title the title for the statistics   * @param printComplexityStatistics if true, complexity statistics are   * returned as well   * @return the summary as a String   */  public String toSummaryString(String title, 				boolean printComplexityStatistics) {         double mae, mad = 0;    StringBuffer text = new StringBuffer();    text.append(title + "\n");    try {      if (m_WithClass > 0) {	if (m_ClassIsNominal) {	  text.append("Correctly Classified Instances     ");	  text.append(Utils.doubleToString(correct(), 12, 4) + "     " +		      Utils.doubleToString(pctCorrect(),					   12, 4) + " %\n");	  text.append("Incorrectly Classified Instances   ");	  text.append(Utils.doubleToString(incorrect(), 12, 4) + "     " +		      Utils.doubleToString(pctIncorrect(),					   12, 4) + " %\n");	  text.append("Kappa statistic                    ");	  text.append(Utils.doubleToString(kappa(), 12, 4) + "\n");	  	  if (m_CostMatrix != null) {	    text.append("Total Cost                         ");	    text.append(Utils.doubleToString(totalCost(), 12, 4) + "\n");	    text.append("Average Cost                       ");	    text.append(Utils.doubleToString(avgCost(), 12, 4) + "\n");	  }	  if (printComplexityStatistics) {	    text.append("K&B Relative Info Score            ");	    text.append(Utils.doubleToString(KBRelativeInformation(), 12, 4) 			+ " %\n");	    text.append("K&B Information Score              ");	    text.append(Utils.doubleToString(KBInformation(), 12, 4) 			+ " bits");	    text.append(Utils.doubleToString(KBMeanInformation(), 12, 4) 			+ " bits/instance\n");	  }	} else {        	  text.append("Correlation coefficient            ");	  text.append(Utils.doubleToString(correlationCoefficient(), 12 , 4) +		      "\n");	}	if (printComplexityStatistics) {	  text.append("Class complexity | order 0         ");	  text.append(Utils.doubleToString(SFPriorEntropy(), 12, 4) 		      + " bits");	  text.append(Utils.doubleToString(SFMeanPriorEntropy(), 12, 4) 		      + " bits/instance\n");	  text.append("Class complexity | scheme          ");	  text.append(Utils.doubleToString(SFSchemeEntropy(), 12, 4) 		      + " bits");	  text.append(Utils.doubleToString(SFMeanSchemeEntropy(), 12, 4) 		      + " bits/instance\n");	  text.append("Complexity improvement     (Sf)    ");	  text.append(Utils.doubleToString(SFEntropyGain(), 12, 4) + " bits");	  text.append(Utils.doubleToString(SFMeanEntropyGain(), 12, 4) 		      + " bits/instance\n");	}	text.append("Mean absolute error                ");	text.append(Utils.doubleToString(meanAbsoluteError(), 12, 4) 		    + "\n");	text.append("Root mean squared error            ");	text.append(Utils.		    doubleToString(rootMeanSquaredError(), 12, 4) 		    + "\n");	text.append("Relative absolute error            ");	text.append(Utils.doubleToString(relativeAbsoluteError(), 					 12, 4) + " %\n");	text.append("Root relative squared error        ");	text.append(Utils.doubleToString(rootRelativeSquaredError(), 					 12, 4) + " %\n");      }      if (Utils.gr(unclassified(), 0)) {	text.append("UnClassified Instances             ");	text.append(Utils.doubleToString(unclassified(), 12,4) +  "     " +		    Utils.doubleToString(pctUnclassified(),					 12, 4) + " %\n");      }      text.append("Total Number of Instances          ");      text.append(Utils.doubleToString(m_WithClass, 12, 4) + "\n");      if (m_MissingClass > 0) {	text.append("Ignored Class Unknown Instances            ");	text.append(Utils.doubleToString(m_MissingClass, 12, 4) + "\n");      }    } catch (Exception ex) {      // Should never occur since the class is known to be nominal       // here      System.err.println("Arggh - Must be a bug in Evaluation class");    }       return text.toString();   }    /**   * Calls toMatrixString() with a default title.   *   * @return the confusion matrix as a string   * @exception Exception if the class is numeric

⌨️ 快捷键说明

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