當前位置: 首頁>>代碼示例>>Java>>正文


Java Evaluation.errorRate方法代碼示例

本文整理匯總了Java中weka.classifiers.Evaluation.errorRate方法的典型用法代碼示例。如果您正苦於以下問題:Java Evaluation.errorRate方法的具體用法?Java Evaluation.errorRate怎麽用?Java Evaluation.errorRate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在weka.classifiers.Evaluation的用法示例。


在下文中一共展示了Evaluation.errorRate方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: ensembleVote

import weka.classifiers.Evaluation; //導入方法依賴的package包/類
public static double ensembleVote(Instances train, Classifier[] newCfsArray) {

		double correctRate =0;
		
		try {
			int i;
			
			Vote ensemble = new Vote();
			SelectedTag tag = new SelectedTag(Vote.MAJORITY_VOTING_RULE,
					Vote.TAGS_RULES);
			ensemble.setCombinationRule(tag);
			ensemble.setClassifiers(newCfsArray);
			ensemble.setSeed(2);
			ensemble.buildClassifier(train);
			Evaluation eval = new Evaluation(train);
			Random random = new Random(1000);
			eval.crossValidateModel(ensemble, train, 5, random);
			
			correctRate = 1 - eval.errorRate();
//			setTempMatrixString(eval.toMatrixString());
//			setTempClassDetailsString(eval.toClassDetailsString());
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return correctRate;
	}
 
開發者ID:guojiasheng,項目名稱:LibD3C-1.1,代碼行數:28,代碼來源:D3CVoter.java

示例2: findParamsByCrossValidation

import weka.classifiers.Evaluation; //導入方法依賴的package包/類
/**
  * Finds the best parameter combination. (recursive for each parameter
  * being optimised).
  * 
  * @param depth the index of the parameter to be optimised at this level
  * @param trainData the data the search is based on
  * @param random a random number generator
  * @throws Exception if an error occurs
  */
 protected void findParamsByCrossValidation(int depth, Instances trainData,
				     Random random)
   throws Exception {

   if (depth < m_CVParams.size()) {
     CVParameter cvParam = (CVParameter)m_CVParams.elementAt(depth);

     double upper;
     switch ((int)(cvParam.m_Lower - cvParam.m_Upper + 0.5)) {
     case 1:
upper = m_NumAttributes;
break;
     case 2:
upper = m_TrainFoldSize;
break;
     default:
upper = cvParam.m_Upper;
break;
     }
     double increment = (upper - cvParam.m_Lower) / (cvParam.m_Steps - 1);
     for(cvParam.m_ParamValue = cvParam.m_Lower; 
  cvParam.m_ParamValue <= upper; 
  cvParam.m_ParamValue += increment) {
findParamsByCrossValidation(depth + 1, trainData, random);
     }
   } else {
     
     Evaluation evaluation = new Evaluation(trainData);

     // Set the classifier options
     String [] options = createOptions();
     if (m_Debug) {
System.err.print("Setting options for " 
		 + m_Classifier.getClass().getName() + ":");
for (int i = 0; i < options.length; i++) {
  System.err.print(" " + options[i]);
}
System.err.println("");
     }
     ((OptionHandler)m_Classifier).setOptions(options);
     for (int j = 0; j < m_NumFolds; j++) {

       // We want to randomize the data the same way for every 
       // learning scheme.
Instances train = trainData.trainCV(m_NumFolds, j, new Random(1));
Instances test = trainData.testCV(m_NumFolds, j);
m_Classifier.buildClassifier(train);
evaluation.setPriors(train);
evaluation.evaluateModel(m_Classifier, test);
     }
     double error = evaluation.errorRate();
     if (m_Debug) {
System.err.println("Cross-validated error rate: " 
		   + Utils.doubleToString(error, 6, 4));
     }
     if ((m_BestPerformance == -99) || (error < m_BestPerformance)) {

m_BestPerformance = error;
m_BestClassifierOptions = createOptions();
     }
   }
 }
 
開發者ID:mydzigear,項目名稱:repo.kmeanspp.silhouette_score,代碼行數:72,代碼來源:CVParameterSelection.java

示例3: evaluateSubset

import weka.classifiers.Evaluation; //導入方法依賴的package包/類
/**
  * Evaluates a subset of attributes
  *
  * @param subset a bitset representing the attribute subset to be 
  * evaluated 
  * @return the error rate
  * @throws Exception if the subset could not be evaluated
  */
 public double evaluateSubset (BitSet subset)
   throws Exception {
   int i,j;
   double errorRate = 0;
   int numAttributes = 0;
   Instances trainCopy=null;
   Instances testCopy=null;

   Remove delTransform = new Remove();
   delTransform.setInvertSelection(true);
   // copy the training instances
   trainCopy = new Instances(m_trainingInstances);
   
   if (!m_useTraining) {
     if (m_holdOutInstances == null) {
throw new Exception("Must specify a set of hold out/test instances "
		    +"with -H");
     } 
     // copy the test instances
     testCopy = new Instances(m_holdOutInstances);
   }
   
   // count attributes set in the BitSet
   for (i = 0; i < m_numAttribs; i++) {
     if (subset.get(i)) {
       numAttributes++;
     }
   }
   
   // set up an array of attribute indexes for the filter (+1 for the class)
   int[] featArray = new int[numAttributes + 1];
   
   for (i = 0, j = 0; i < m_numAttribs; i++) {
     if (subset.get(i)) {
       featArray[j++] = i;
     }
   }
   
   featArray[j] = m_classIndex;
   delTransform.setAttributeIndicesArray(featArray);
   delTransform.setInputFormat(trainCopy);
   trainCopy = Filter.useFilter(trainCopy, delTransform);
   if (!m_useTraining) {
     testCopy = Filter.useFilter(testCopy, delTransform);
   }

   // build the classifier
   m_Classifier.buildClassifier(trainCopy);

   m_Evaluation = new Evaluation(trainCopy);
   if (!m_useTraining) {
     m_Evaluation.evaluateModel(m_Classifier, testCopy);
   } else {
     m_Evaluation.evaluateModel(m_Classifier, trainCopy);
   }

   if (m_trainingInstances.classAttribute().isNominal()) {
     errorRate = m_Evaluation.errorRate();
   } else {
     errorRate = m_Evaluation.meanAbsoluteError();
   }

   m_Evaluation = null;
   // return the negative of the error rate as search methods  need to
   // maximize something
   return -errorRate;
 }
 
開發者ID:williamClanton,項目名稱:jbossBA,代碼行數:76,代碼來源:ClassifierSubsetEval.java

示例4: evaluateSubset

import weka.classifiers.Evaluation; //導入方法依賴的package包/類
/**
 * Evaluates a subset of attributes
 *
 * @param subset a bitset representing the attribute subset to be 
 * evaluated 
 * @return the error rate
 * @throws Exception if the subset could not be evaluated
 */
public double evaluateSubset (BitSet subset)
  throws Exception {
  double errorRate = 0;
  double[] repError = new double[5];
  int numAttributes = 0;
  int i, j;
  Random Rnd = new Random(m_seed);
  Remove delTransform = new Remove();
  delTransform.setInvertSelection(true);
  // copy the instances
  Instances trainCopy = new Instances(m_trainInstances);

  // count attributes set in the BitSet
  for (i = 0; i < m_numAttribs; i++) {
    if (subset.get(i)) {
      numAttributes++;
    }
  }

  // set up an array of attribute indexes for the filter (+1 for the class)
  int[] featArray = new int[numAttributes + 1];

  for (i = 0, j = 0; i < m_numAttribs; i++) {
    if (subset.get(i)) {
      featArray[j++] = i;
    }
  }

  featArray[j] = m_classIndex;
  delTransform.setAttributeIndicesArray(featArray);
  delTransform.setInputFormat(trainCopy);
  trainCopy = Filter.useFilter(trainCopy, delTransform);

  // max of 5 repititions ofcross validation
  for (i = 0; i < 5; i++) {
    m_Evaluation = new Evaluation(trainCopy);
    m_Evaluation.crossValidateModel(m_BaseClassifier, trainCopy, m_folds, Rnd);
    repError[i] = m_Evaluation.errorRate();

    // check on the standard deviation
    if (!repeat(repError, i + 1)) {
      i++;
      break;
    }
  }

  for (j = 0; j < i; j++) {
    errorRate += repError[j];
  }

  errorRate /= (double)i;
  m_Evaluation = null;
  return  m_trainInstances.classAttribute().isNumeric() ? -errorRate : 1.0 - errorRate;
}
 
開發者ID:williamClanton,項目名稱:jbossBA,代碼行數:63,代碼來源:WrapperSubsetEval.java

示例5: getErrorRate

import weka.classifiers.Evaluation; //導入方法依賴的package包/類
/**
 * Returns the misclassification error of the current model on a set of
 * instances.
 * 
 * @param data the set of instances
 * @return the error rate
 * @throws Exception if something goes wrong
 */
protected double getErrorRate(Instances data) throws Exception {
  Evaluation eval = new Evaluation(data);
  eval.evaluateModel(this, data);
  return eval.errorRate();
}
 
開發者ID:mydzigear,項目名稱:repo.kmeanspp.silhouette_score,代碼行數:14,代碼來源:LogisticBase.java

示例6: getErrorRate

import weka.classifiers.Evaluation; //導入方法依賴的package包/類
/**
    * Returns the misclassification error of the current model on a set of instances.
    * @param data the set of instances
    * @return the error rate
    * @throws Exception if something goes wrong
    */
   protected double getErrorRate(Instances data) throws Exception {
Evaluation eval = new Evaluation(data);
eval.evaluateModel(this,data);
return eval.errorRate();
   }
 
開發者ID:dsibournemouth,項目名稱:autoweka,代碼行數:12,代碼來源:LogisticBase.java


注:本文中的weka.classifiers.Evaluation.errorRate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。