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

📄 classifiersplitevaluator.java

📁 Java 编写的多种数据挖掘算法 包括聚类、分类、预处理等
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    testTimeStart = System.currentTimeMillis();    if(canMeasureCPUTime)       CPUStartTime = thMonitor.getThreadUserTime(thID);    predictions = eval.evaluateModel(m_Classifier, test);    if(canMeasureCPUTime)      testCPUTimeElapsed = thMonitor.getThreadUserTime(thID) - CPUStartTime;    testTimeElapsed = System.currentTimeMillis() - testTimeStart;    thMonitor = null;        m_result = eval.toSummaryString();    // The results stored are all per instance -- can be multiplied by the    // number of instances to get absolute numbers    int current = 0;    result[current++] = new Double(train.numInstances());    result[current++] = new Double(eval.numInstances());    result[current++] = new Double(eval.correct());    result[current++] = new Double(eval.incorrect());    result[current++] = new Double(eval.unclassified());    result[current++] = new Double(eval.pctCorrect());    result[current++] = new Double(eval.pctIncorrect());    result[current++] = new Double(eval.pctUnclassified());    result[current++] = new Double(eval.kappa());        result[current++] = new Double(eval.meanAbsoluteError());    result[current++] = new Double(eval.rootMeanSquaredError());    result[current++] = new Double(eval.relativeAbsoluteError());    result[current++] = new Double(eval.rootRelativeSquaredError());        result[current++] = new Double(eval.SFPriorEntropy());    result[current++] = new Double(eval.SFSchemeEntropy());    result[current++] = new Double(eval.SFEntropyGain());    result[current++] = new Double(eval.SFMeanPriorEntropy());    result[current++] = new Double(eval.SFMeanSchemeEntropy());    result[current++] = new Double(eval.SFMeanEntropyGain());        // K&B stats    result[current++] = new Double(eval.KBInformation());    result[current++] = new Double(eval.KBMeanInformation());    result[current++] = new Double(eval.KBRelativeInformation());        // IR stats    result[current++] = new Double(eval.truePositiveRate(m_IRclass));    result[current++] = new Double(eval.numTruePositives(m_IRclass));    result[current++] = new Double(eval.falsePositiveRate(m_IRclass));    result[current++] = new Double(eval.numFalsePositives(m_IRclass));    result[current++] = new Double(eval.trueNegativeRate(m_IRclass));    result[current++] = new Double(eval.numTrueNegatives(m_IRclass));    result[current++] = new Double(eval.falseNegativeRate(m_IRclass));    result[current++] = new Double(eval.numFalseNegatives(m_IRclass));    result[current++] = new Double(eval.precision(m_IRclass));    result[current++] = new Double(eval.recall(m_IRclass));    result[current++] = new Double(eval.fMeasure(m_IRclass));    result[current++] = new Double(eval.areaUnderROC(m_IRclass));        // Timing stats    result[current++] = new Double(trainTimeElapsed / 1000.0);    result[current++] = new Double(testTimeElapsed / 1000.0);    if(canMeasureCPUTime) {      result[current++] = new Double((trainCPUTimeElapsed/1000000.0) / 1000.0);      result[current++] = new Double((testCPUTimeElapsed /1000000.0) / 1000.0);    }    else {      result[current++] = new Double(Instance.missingValue());      result[current++] = new Double(Instance.missingValue());    }        // IDs    if (getAttributeID() >= 0){      String idsString = "";      if (test.attribute(m_attID).isNumeric()){        if (test.numInstances() > 0)          idsString += test.instance(0).value(m_attID);        for(int i=1;i<test.numInstances();i++){          idsString += "|" + test.instance(i).value(m_attID);        }      } else {        if (test.numInstances() > 0)          idsString += test.instance(0).stringValue(m_attID);        for(int i=1;i<test.numInstances();i++){          idsString += "|" + test.instance(i).stringValue(m_attID);        }      }      result[current++] = idsString;    }        if (getPredTargetColumn()){      if (test.classAttribute().isNumeric()){        // Targets        if (test.numInstances() > 0){          String targetsString = "";          targetsString += test.instance(0).value(test.classIndex());          for(int i=1;i<test.numInstances();i++){            targetsString += "|" + test.instance(i).value(test.classIndex());          }          result[current++] = targetsString;        }                // Predictions        if (predictions.length > 0){          String predictionsString = "";          predictionsString += predictions[0];          for(int i=1;i<predictions.length;i++){            predictionsString += "|" + predictions[i];          }          result[current++] = predictionsString;        }      } else {        // Targets        if (test.numInstances() > 0){          String targetsString = "";          targetsString += test.instance(0).stringValue(test.classIndex());          for(int i=1;i<test.numInstances();i++){            targetsString += "|" + test.instance(i).stringValue(test.classIndex());          }          result[current++] = targetsString;        }                // Predictions        if (predictions.length > 0){          String predictionsString = "";          predictionsString += test.classAttribute().value((int) predictions[0]);          for(int i=1;i<predictions.length;i++){            predictionsString += "|" + test.classAttribute().value((int) predictions[i]);          }          result[current++] = predictionsString;        }      }    }        if (m_Classifier instanceof Summarizable) {      result[current++] = ((Summarizable)m_Classifier).toSummaryString();    } else {      result[current++] = null;    }        for (int i=0;i<addm;i++) {      if (m_doesProduce[i]) {        try {          double dv = ((AdditionalMeasureProducer)m_Classifier).          getMeasure(m_AdditionalMeasures[i]);          if (!Instance.isMissingValue(dv)) {            Double value = new Double(dv);            result[current++] = value;          } else {            result[current++] = null;          }        } catch (Exception ex) {          System.err.println(ex);        }      } else {        result[current++] = null;      }    }        if (current != overall_length) {      throw new Error("Results didn't fit RESULT_SIZE");    }    return result;  }  /**   * Returns the tip text for this property   * @return tip text for this property suitable for   * displaying in the explorer/experimenter gui   */  public String classifierTipText() {    return "The classifier to use.";  }  /**   * Get the value of Classifier.   *   * @return Value of Classifier.   */  public Classifier getClassifier() {        return m_Template;  }    /**   * Sets the classifier.   *   * @param newClassifier the new classifier to use.   */  public void setClassifier(Classifier newClassifier) {        m_Template = newClassifier;    updateOptions();  }    /**   * Get the value of ClassForIRStatistics.   * @return Value of ClassForIRStatistics.   */  public int getClassForIRStatistics() {    return m_IRclass;  }    /**   * Set the value of ClassForIRStatistics.   * @param v  Value to assign to ClassForIRStatistics.   */  public void setClassForIRStatistics(int v) {    m_IRclass = v;  }  /**   * Get the index of Attibute Identifying the instances   * @return index of outputed Attribute.   */  public int getAttributeID() {    return m_attID;  }    /**   * Set the index of Attibute Identifying the instances   * @param v index the attribute to output   */  public void setAttributeID(int v) {    m_attID = v;  }      /**   *@return true if the prediction and target columns must be outputed.   */  public boolean getPredTargetColumn(){      return m_predTargetColumn;  }  /**   * Set the flag for prediction and target output.   *@param v true if the 2 columns have to be outputed. false otherwise.   */  public void setPredTargetColumn(boolean v){      m_predTargetColumn = v;  }    /**   * Updates the options that the current classifier is using.   */  protected void updateOptions() {        if (m_Template instanceof OptionHandler) {      m_ClassifierOptions = Utils.joinOptions(((OptionHandler)m_Template)					      .getOptions());    } else {      m_ClassifierOptions = "";    }    if (m_Template instanceof Serializable) {      ObjectStreamClass obs = ObjectStreamClass.lookup(m_Template						       .getClass());      m_ClassifierVersion = "" + obs.getSerialVersionUID();    } else {      m_ClassifierVersion = "";    }  }  /**   * Set the Classifier to use, given it's class name. A new classifier will be   * instantiated.   *   * @param newClassifierName the Classifier class name.   * @throws Exception if the class name is invalid.   */  public void setClassifierName(String newClassifierName) throws Exception {    try {      setClassifier((Classifier)Class.forName(newClassifierName)		    .newInstance());    } catch (Exception ex) {      throw new Exception("Can't find Classifier with class name: "			  + newClassifierName);    }  }  /**   * Gets the raw output from the classifier   * @return the raw output from the classifier   */  public String getRawResultOutput() {    StringBuffer result = new StringBuffer();    if (m_Classifier == null) {      return "<null> classifier";    }    result.append(toString());    result.append("Classifier model: \n"+m_Classifier.toString()+'\n');    // append the performance statistics    if (m_result != null) {      result.append(m_result);            if (m_doesProduce != null) {	for (int i=0;i<m_doesProduce.length;i++) {	  if (m_doesProduce[i]) {	    try {	      double dv = ((AdditionalMeasureProducer)m_Classifier).		getMeasure(m_AdditionalMeasures[i]);	      if (!Instance.isMissingValue(dv)) {		Double value = new Double(dv);		result.append(m_AdditionalMeasures[i]+" : "+value+'\n');	      } else {		result.append(m_AdditionalMeasures[i]+" : "+'?'+'\n');	      }	    } catch (Exception ex) {	      System.err.println(ex);	    }	  } 	}      }    }    return result.toString();  }  /**   * Returns a text description of the split evaluator.   *   * @return a text description of the split evaluator.   */  public String toString() {    String result = "ClassifierSplitEvaluator: ";    if (m_Template == null) {      return result + "<null> classifier";    }    return result + m_Template.getClass().getName() + " "       + m_ClassifierOptions + "(version " + m_ClassifierVersion + ")";  }} // ClassifierSplitEvaluator

⌨️ 快捷键说明

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