当前位置: 首页>>代码示例>>Java>>正文


Java Evaluation.evaluateModel方法代码示例

本文整理汇总了Java中weka.classifiers.Evaluation.evaluateModel方法的典型用法代码示例。如果您正苦于以下问题:Java Evaluation.evaluateModel方法的具体用法?Java Evaluation.evaluateModel怎么用?Java Evaluation.evaluateModel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在weka.classifiers.Evaluation的用法示例。


在下文中一共展示了Evaluation.evaluateModel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: crossValidate

import weka.classifiers.Evaluation; //导入方法依赖的package包/类
/**
  * Utility method for fast 5-fold cross validation of a naive bayes
  * model
  *
  * @param fullModel a <code>NaiveBayesUpdateable</code> value
  * @param trainingSet an <code>Instances</code> value
  * @param r a <code>Random</code> value
  * @return a <code>double</code> value
  * @exception Exception if an error occurs
  */
 public static double crossValidate(NaiveBayesUpdateable fullModel,
		       Instances trainingSet,
		       Random r) throws Exception {
   // make some copies for fast evaluation of 5-fold xval
   Classifier [] copies = AbstractClassifier.makeCopies(fullModel, 5);
   Evaluation eval = new Evaluation(trainingSet);
   // make some splits
   for (int j = 0; j < 5; j++) {
     Instances test = trainingSet.testCV(5, j);
     // unlearn these test instances
     for (int k = 0; k < test.numInstances(); k++) {
test.instance(k).setWeight(-test.instance(k).weight());
((NaiveBayesUpdateable)copies[j]).updateClassifier(test.instance(k));
// reset the weight back to its original value
test.instance(k).setWeight(-test.instance(k).weight());
     }
     eval.evaluateModel(copies[j], test);
   }
   return eval.incorrect();
 }
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:31,代码来源:NBTreeNoSplit.java

示例2: trainRandomForest

import weka.classifiers.Evaluation; //导入方法依赖的package包/类
public static void trainRandomForest(final Instances trainingSet) throws Exception {
        // Create a classifier
        final RandomForest tree = new RandomForest();
        tree.buildClassifier(trainingSet);

        // Test the model
        final Evaluation eval = new Evaluation(trainingSet);
//        eval.crossValidateModel(tree, trainingSet, 10, new Random(1));
        eval.evaluateModel(tree, trainingSet);

        // Print the result à la Weka explorer:
        logger.info(eval.toSummaryString());
        logger.info(eval.toMatrixString());
        logger.info(tree.toString());
    }
 
开发者ID:cobr123,项目名称:VirtaMarketAnalyzer,代码行数:16,代码来源:RetailSalePrediction.java

示例3: modelErrors

import weka.classifiers.Evaluation; //导入方法依赖的package包/类
/**
    *Updates the numIncorrectModel field for all nodes. This is needed for calculating the alpha-values. 
    */
   public void modelErrors() throws Exception{
	
Evaluation eval = new Evaluation(m_train);
	
if (!m_isLeaf) {
    m_isLeaf = true;
    eval.evaluateModel(this, m_train);
    m_isLeaf = false;
    m_numIncorrectModel = eval.incorrect();
    for (int i = 0; i < m_sons.length; i++) m_sons[i].modelErrors();
} else {
    eval.evaluateModel(this, m_train);
    m_numIncorrectModel = eval.incorrect();
}
   }
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:19,代码来源:LMTNode.java

示例4: crossValidate

import weka.classifiers.Evaluation; //导入方法依赖的package包/类
/**
  * Utility method for fast 5-fold cross validation of a naive bayes
  * model
  *
  * @param fullModel a <code>NaiveBayesUpdateable</code> value
  * @param trainingSet an <code>Instances</code> value
  * @param r a <code>Random</code> value
  * @return a <code>double</code> value
  * @exception Exception if an error occurs
  */
 public static double crossValidate(NaiveBayesUpdateable fullModel,
		       Instances trainingSet,
		       Random r) throws Exception {
   // make some copies for fast evaluation of 5-fold xval
   Classifier [] copies = Classifier.makeCopies(fullModel, 5);
   Evaluation eval = new Evaluation(trainingSet);
   // make some splits
   for (int j = 0; j < 5; j++) {
     Instances test = trainingSet.testCV(5, j);
     // unlearn these test instances
     for (int k = 0; k < test.numInstances(); k++) {
test.instance(k).setWeight(-test.instance(k).weight());
((NaiveBayesUpdateable)copies[j]).updateClassifier(test.instance(k));
// reset the weight back to its original value
test.instance(k).setWeight(-test.instance(k).weight());
     }
     eval.evaluateModel(copies[j], test);
   }
   return eval.incorrect();
 }
 
开发者ID:williamClanton,项目名称:jbossBA,代码行数:31,代码来源:NBTreeNoSplit.java

示例5: Main

import weka.classifiers.Evaluation; //导入方法依赖的package包/类
public Main() {
    try {
        BufferedReader datafile;
        datafile = readDataFile("camping.txt");
        Instances data = new Instances(datafile);
        data.setClassIndex(data.numAttributes() - 1);

        Instances trainingData = new Instances(data, 0, 14);
        Instances testingData = new Instances(data, 14, 5);
        Evaluation evaluation = new Evaluation(trainingData);

        SMO smo = new SMO();
        smo.buildClassifier(data);

        evaluation.evaluateModel(smo, testingData);
        System.out.println(evaluation.toSummaryString());

        // Test instance 
        Instance instance = new DenseInstance(3);
        instance.setValue(data.attribute("age"), 78);
        instance.setValue(data.attribute("income"), 125700);
        instance.setValue(data.attribute("camps"), 1);            
        instance.setDataset(data);
        System.out.println("The instance: " + instance);
        System.out.println(smo.classifyInstance(instance));
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
 
开发者ID:PacktPublishing,项目名称:Machine-Learning-End-to-Endguide-for-Java-developers,代码行数:30,代码来源:Main-SVG.java

示例6: evaluate

import weka.classifiers.Evaluation; //导入方法依赖的package包/类
public static void evaluate(Classifier clf, Instances data, double minPerfomance)
    throws Exception {
  Instances[] split = TestUtil.splitTrainTest(data);

  Instances train = split[0];
  Instances test = split[1];

  clf.buildClassifier(train);
  Evaluation trainEval = new Evaluation(train);
  trainEval.evaluateModel(clf, train);

  Evaluation testEval = new Evaluation(train);
  testEval.evaluateModel(clf, test);

  final double testPctCorrect = testEval.pctCorrect();
  final double trainPctCorrect = trainEval.pctCorrect();

  log.info("Train: {}, Test: {}", trainPctCorrect, testPctCorrect);
  boolean success =
      testPctCorrect > minPerfomance && trainPctCorrect > minPerfomance;
  Assert.assertTrue(success);
}
 
开发者ID:Waikato,项目名称:wekaDeeplearning4j,代码行数:23,代码来源:StabilityTest.java

示例7: holdout

import weka.classifiers.Evaluation; //导入方法依赖的package包/类
/**
 * Perform simple holdout with a given percentage
 *
 * @param clf Classifier
 * @param data Full dataset
 * @param p Split percentage
 * @throws Exception
 */
public static void holdout(Classifier clf, Instances data, double p) throws Exception {
  Instances[] split = splitTrainTest(data, p);

  Instances train = split[0];
  Instances test = split[1];

  clf.buildClassifier(train);
  Evaluation trainEval = new Evaluation(train);
  trainEval.evaluateModel(clf, train);
  logger.info("Weka Train Evaluation:");
  logger.info(trainEval.toSummaryString());
  if (!data.classAttribute().isNumeric()) {
    logger.info(trainEval.toMatrixString());
  }

  Evaluation testEval = new Evaluation(train);
  logger.info("Weka Test Evaluation:");
  testEval.evaluateModel(clf, test);
  logger.info(testEval.toSummaryString());
  if (!data.classAttribute().isNumeric()) {
    logger.info(testEval.toMatrixString());
  }
}
 
开发者ID:Waikato,项目名称:wekaDeeplearning4j,代码行数:32,代码来源:TestUtil.java

示例8: getErrorPercent

import weka.classifiers.Evaluation; //导入方法依赖的package包/类
@Override
public double getErrorPercent() {
    this.splitInstances();

    try {
        this.getClassifier().buildClassifier(getTrainInstances());

        Evaluation eval = new Evaluation(getTestInstances());
        eval.evaluateModel(getClassifier(), getTestInstances());

        return eval.pctIncorrect();

    } catch (Exception e) {
        e.printStackTrace();
        return -1;
    }
}
 
开发者ID:garciparedes,项目名称:java-examples,代码行数:18,代码来源:AbstractSplitEstimator.java

示例9: trainRandomCommittee

import weka.classifiers.Evaluation; //导入方法依赖的package包/类
public static void trainRandomCommittee(final Instances trainingSet) throws Exception {
        logger.info("Create a classifier");
        final RandomTree classifier = new RandomTree();
        classifier.setKValue(0);
        classifier.setMaxDepth(0);
        classifier.setMinNum(0.001);
        classifier.setAllowUnclassifiedInstances(false);
        classifier.setNumFolds(0);

        final RandomCommittee tree = new RandomCommittee();
        tree.setClassifier(classifier);
        tree.setNumIterations(10);
        tree.buildClassifier(trainingSet);

        logger.info("Test the model");
        final Evaluation eval = new Evaluation(trainingSet);
//        eval.crossValidateModel(tree, trainingSet, 10, new Random(1));
        eval.evaluateModel(tree, trainingSet);

        // Print the result à la Weka explorer:
        logger.info(eval.toSummaryString());
        logger.info(tree.toString());
        logger.info(eval.toMatrixString());
        logger.info(eval.toClassDetailsString());
        logger.info(eval.toCumulativeMarginDistributionString());

//        logger.info("coefficients");
//        for(int i = 0; i < tree.coefficients().length; ++i){
//            logger.info("{} | {}", trainingSet.attribute(i).name(), tree.coefficients()[i]);
//        }

//        try {
//            final File file = new File(GitHubPublisher.localPath + RetailSalePrediction.predict_retail_sales + File.separator + "prediction_set_script.js");
//            FileUtils.writeStringToFile(file, ClassifierToJs.compress(ClassifierToJs.toSource(tree, "predictCommonBySet")), "UTF-8");
//        } catch (final Exception e) {
//            logger.error(e.getLocalizedMessage(), e);
//        }
    }
 
开发者ID:cobr123,项目名称:VirtaMarketAnalyzer,代码行数:39,代码来源:RetailSalePrediction.java

示例10: trainDecisionTable

import weka.classifiers.Evaluation; //导入方法依赖的package包/类
public static void trainDecisionTable(final Instances trainingSet) throws Exception {
        // Create a classifier
        final DecisionTable tree = new DecisionTable();
        tree.buildClassifier(trainingSet);

        // Test the model
        final Evaluation eval = new Evaluation(trainingSet);
//        eval.crossValidateModel(tree, trainingSet, 10, new Random(1));
        eval.evaluateModel(tree, trainingSet);

        // Print the result à la Weka explorer:
        logger.info(eval.toSummaryString());
        logger.info(tree.toString());

//        try {
//            final File file = new File(GitHubPublisher.localPath + RetailSalePrediction.predict_retail_sales + File.separator + "prediction_set_script.js");
//            FileUtils.writeStringToFile(file, ClassifierToJs.compress(ClassifierToJs.toSource(tree, "predictCommonBySet")), "UTF-8");
//        } catch (final Exception e) {
//            logger.error(e.getLocalizedMessage(), e);
//        }
    }
 
开发者ID:cobr123,项目名称:VirtaMarketAnalyzer,代码行数:22,代码来源:RetailSalePrediction.java

示例11: testModel

import weka.classifiers.Evaluation; //导入方法依赖的package包/类
/**
 * Loads the model stored in the given file and evaluates it against the current test data. 
 * The void returns and error if no test data is presents.  
 * 
 * @param model
 * @throws Exception 
 */
public void testModel(String model) throws Exception
{
	if ((testdata == null) || testdata.isEmpty())
	{
		System.err.println("WekaWrapper: testModel() - no test data available, model won't be evaluated");
		System.exit(9);
	}
	
	// check model file
	//if (! FileUtilsElh.checkFile(modelPath))
	//{
	//	System.err.println("WekaWrapper: testModel() - model couldn't be loaded");
	//	System.exit(8);
	//}

	// deserialize model
	this.MLclass = (Classifier) weka.core.SerializationHelper.readAll(model)[0];		
	System.err.println("WekaWrapper: testModel() - Classifier ready.");
			
	Evaluation eTest = new Evaluation(this.testdata);
	eTest.evaluateModel(this.MLclass, this.testdata);
	System.err.println("WekaWrapper: testModel() - Test ready.");
		
	printClassifierResults (eTest);      
}
 
开发者ID:Elhuyar,项目名称:Elixa,代码行数:33,代码来源:WekaWrapper.java

示例12: modelErrors

import weka.classifiers.Evaluation; //导入方法依赖的package包/类
/**
  * Updates the numIncorrectModel field for all nodes when subtree (to be 
  * pruned) is rooted. This is needed for calculating the alpha-values.
  * 
  * @throws Exception 	if something goes wrong
  */
 public void modelErrors() throws Exception{
   Evaluation eval = new Evaluation(m_train);

   if (!m_isLeaf) {
     m_isLeaf = true; //temporarily make leaf

     // calculate distribution for evaluation
     eval.evaluateModel(this, m_train);
     m_numIncorrectModel = eval.incorrect();

     m_isLeaf = false;

     for (int i = 0; i < m_Successors.length; i++)
m_Successors[i].modelErrors();

   } else {
     eval.evaluateModel(this, m_train);
     m_numIncorrectModel = eval.incorrect();
   }       
 }
 
开发者ID:williamClanton,项目名称:jbossBA,代码行数:27,代码来源:SimpleCart.java

示例13: test

import weka.classifiers.Evaluation; //导入方法依赖的package包/类
public void test(String trainFile, String testFile) {
	try {
		// load the files
		loadTrainFile(trainFile);
		loadTestFile(testFile);

		// build the classifier
		Classifier cls = new J48();
		cls.buildClassifier(train);

		// evaluate the classifier
		Evaluation eval = new Evaluation(train);
		eval.evaluateModel(cls, test);

		// print the results
		Logger.log(LogLevel.Classification,
				eval.toSummaryString("\nResults\n======\n", false));

	} catch (Exception e) {
		Logger.log(LogLevel.Error, e.toString());
	}
}
 
开发者ID:mbraeunlein,项目名称:ExtendedHodoku,代码行数:23,代码来源:Analyzer.java

示例14: getCrossValidation

import weka.classifiers.Evaluation; //导入方法依赖的package包/类
/**
 * @param cls
 * @param data
 * @param folds
 * @return [0] = pctCorrect, [1] = pctIncorrect
 * @throws Exception
 */
public double[] getCrossValidation(Classifier cls, Instances data, int folds) throws Exception {

	cls.buildClassifier(data);

	Classifier copy = Classifier.makeCopy(cls);
	double[] results = new double[2];
	for (int n = 0; n < folds; n++) {
		Instances train = data.trainCV(folds, n);
		Instances test = data.testCV(folds, n);

		// CSVSaver saver = new CSVSaver();
		// saver.setInstances(train);
		// saver.setFile(new File("../data.csv"));
		// saver.writeBatch();

		cls.buildClassifier(train);
		Evaluation eval = new Evaluation(data);
		eval.evaluateModel(cls, test);
		results[0] = results[0] + (eval.pctCorrect() / 100);
		results[1] = results[1] + (eval.pctIncorrect() / 100);
	}

	cls = copy;
	results[0] = results[0] / folds;
	results[1] = results[1] / folds;
	return results;
}
 
开发者ID:gsi-upm,项目名称:BARMAS,代码行数:35,代码来源:ClassifiersValidation.java

示例15: main

import weka.classifiers.Evaluation; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    // Declare numeric attributes
    attrs = new FastVector(6);
    attrs.addElement(new Attribute("houseSize"));
    attrs.addElement(new Attribute("lotSize"));
    attrs.addElement(new Attribute("bedrooms"));

    attrs.addElement(new Attribute("granite"));
    attrs.addElement(new Attribute("bathroom"));
    attrs.addElement(new Attribute("sellingPrice"));

    // add the instance
    createTrainingSet();

    // Create a LinearRegression classifier
    Classifier cModel = new LinearRegression();
    cModel.buildClassifier(isTrainingSet);
    // Print the result à la Weka explorer:
    System.out.println(cModel.toString());

    // TestWeka the model
    Evaluation eTest = new Evaluation(isTrainingSet);
    eTest.evaluateModel(cModel, isTrainingSet);

    // Print the result à la Weka explorer:
    System.out.println(eTest.toSummaryString());

    // Specify that the instance belong to the training set
    // in order to inherit from the set description
    Instance iUse = createInstance(3198, 9669, 5, 0, 1, 0);
    iUse.setDataset(isTrainingSet);

    // Get the likelihood of each classes
    double[] fDistribution = cModel.distributionForInstance(iUse);
    System.out.println(fDistribution[0]);
}
 
开发者ID:cobr123,项目名称:VirtaMarketAnalyzer,代码行数:37,代码来源:TestWeka.java


注:本文中的weka.classifiers.Evaluation.evaluateModel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。