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


Java RandomForest类代码示例

本文整理汇总了Java中weka.classifiers.trees.RandomForest的典型用法代码示例。如果您正苦于以下问题:Java RandomForest类的具体用法?Java RandomForest怎么用?Java RandomForest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: buildFilteredClassifier

import weka.classifiers.trees.RandomForest; //导入依赖的package包/类
public void buildFilteredClassifier(){
	rf = new RandomForest();
	Remove rm = new Remove();
	rm.setAttributeIndices("1");
	FilteredClassifier fc = new FilteredClassifier();
	fc.setFilter(rm);
	fc.setClassifier(rf);
	try{
		fc.buildClassifier(weather);
		for (int i = 0; i < weather.numInstances(); i++){
			double pred = fc.classifyInstance(weather.instance(i));
			System.out.print("given value: " + weather.classAttribute().value((int) weather.instance(i).classValue()));
			System.out.println("---predicted value: " + weather.classAttribute().value((int) pred));
		}
	} catch (Exception e) {
	}
}
 
开发者ID:PacktPublishing,项目名称:Java-Data-Science-Cookbook,代码行数:18,代码来源:WekaFilteredClassifierTest.java

示例2: useClassifier

import weka.classifiers.trees.RandomForest; //导入依赖的package包/类
/**
 * uses the meta-classifier
 */
protected static void useClassifier(Instances data) throws Exception {
    System.out.println("\n1. Meta-classfier");
    AttributeSelectedClassifier classifier = new AttributeSelectedClassifier();
    CfsSubsetEval eval = new CfsSubsetEval();
    //GreedyStepwise search = new GreedyStepwise();
    GeneticSearch search = new GeneticSearch();
    //	search.setSearchBackwards(false);
    RandomForest base = new RandomForest();
    classifier.setClassifier(base);
    System.out.println("Set the classifier : " + base.toString());
    classifier.setEvaluator(eval);
    System.out.println("Set the evaluator : " + eval.toString());
    //	classifier.setSearch( search );
    System.out.println("Set the search : " + search.toString());
    Evaluation evaluation = new Evaluation(data);
    evaluation.crossValidateModel(classifier, data, 10, new Random(1));
    System.out.println(evaluation.toSummaryString());
}
 
开发者ID:ajaybhat,项目名称:Essay-Grading-System,代码行数:22,代码来源:AttributeSelectionRunner.java

示例3: train

import weka.classifiers.trees.RandomForest; //导入依赖的package包/类
private void train(String name) {
	try {
		Classifier randomForest = new RandomForest();

		ConverterUtils.DataSource source = new ConverterUtils.DataSource(FOLDER + name);
		dataSet = source.getDataSet();

		dataSet.setClassIndex(dataSet.numAttributes() - 1);
		randomForest.buildClassifier(dataSet);

		classifier = randomForest;
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:igr,项目名称:parlo,代码行数:16,代码来源:SentenceClassifier.java

示例4: train

import weka.classifiers.trees.RandomForest; //导入依赖的package包/类
public void train() {
	try {
		Classifier randomForest = new RandomForest();

		ConverterUtils.DataSource source = new ConverterUtils.DataSource(FOLDER + "question-classifier.arff");
		dataSet = source.getDataSet();

		dataSet.setClassIndex(dataSet.numAttributes() - 1);
		randomForest.buildClassifier(dataSet);

		classifier = randomForest;
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:igr,项目名称:parlo,代码行数:16,代码来源:QuestionClassifier.java

示例5: trainRandomForest

import weka.classifiers.trees.RandomForest; //导入依赖的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

示例6: main

import weka.classifiers.trees.RandomForest; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
		
		java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF); 
		System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");
		XMLWikipediaExtractor xwe=new XMLWikipediaExtractor();
		int bestTopic=xwe.getAllArticlesUnderCategory(WikiHelper.getSpecificProperty("categoryForTraining"));
		JtopiaUsage.loadComponents();
	    URLCrawlerForTopic.loadStanfordComponents();
//	    //SummarizationSolver.loadCoreNLP();
	    SummarizationSolver.loadLM();
	    SummarizationSolver.loadStanfordComponents();
	    //Load the topic model
		//int bestTopic=40;
	    TopicInferencer inferencer=TopicModelGenerator.getBestTopicModelInferer(WikiHelper.getSpecificProperty("categoryForTraining"), bestTopic);
		RandomForest classifier=PassageClassifier.getRFBestClassifier(bestTopic, WikiHelper.getSpecificProperty("categoryForTraining"));
		ExistingArticleGenerator eag=new ExistingArticleGenerator();
		xwe.storeStubArticles(WikiHelper.getSpecificProperty("categoryToGenerate"));
		eag.chooseRandomArticlesToCreate(WikiHelper.getSpecificProperty("categoryToGenerate"),bestTopic,
				inferencer,classifier);
		
	}
 
开发者ID:siddBanPsu,项目名称:WikiKreator,代码行数:22,代码来源:ExistingArticleGenerator.java

示例7: trainModel

import weka.classifiers.trees.RandomForest; //导入依赖的package包/类
public static void trainModel(String trainingPath, String outputPath, String learner) {
        if(learner==null) {
            learner = "SMO";
        }
        
        System.out.println("Training "+ learner+" model...");
        if(learner.equals("SMO")) {
            SMO.main(new String[] {
                "-M",
                "-d", outputPath + "/pageclassifier.model",
                "-t", trainingPath + "/weka.arff",
                "-C", "0.01"
            });
        } else if(learner.equals("RandomForest")) {
            RandomForest.main(new String[] {
//              "-K", "5", // k-fold cross validation
                "-I", "100", // Number of trees to build
                "-d", outputPath + "/pageclassifier.model",
                "-t", trainingPath + "/weka.arff"
            });
        } else {
            System.out.println("Unknow learner: "+learner);
            return;
        }
    }
 
开发者ID:ViDA-NYU,项目名称:ache,代码行数:26,代码来源:WekaTargetClassifierBuilder.java

示例8: getClassifier

import weka.classifiers.trees.RandomForest; //导入依赖的package包/类
public static Classifier getClassifier(AlgorithmType type) {
	
	Classifier classifier = null;
	
	try {
		if(type == null) {
			type = AlgorithmType.RANDOM_FOREST;
		}
		
		Constructor constructor = type.getClazz().getConstructor();
		classifier = (Classifier)constructor.newInstance();
		
	} catch (InstantiationException | IllegalAccessException
			| IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
	
		logger.warn("Unable to instantiate classifier : " + type.getClazz().getName());
		classifier = (Classifier) new RandomForest();
	}

	return classifier;
}
 
开发者ID:qcri-social,项目名称:AIDR,代码行数:22,代码来源:ClassifierFactory.java

示例9: LearnRandomForest

import weka.classifiers.trees.RandomForest; //导入依赖的package包/类
@Override
public void LearnRandomForest() throws Exception 
{
	   trainedData.setClassIndex(trainedData.numAttributes()-1);
        filter=new StringToWordVector();
        classifier=new FilteredClassifier();
        classifier.setFilter(filter);
        classifier.setClassifier(new RandomForest());
        classifier.buildClassifier(trainedData);
}
 
开发者ID:unsw-cse-soc,项目名称:Data-curation-API,代码行数:11,代码来源:ExtractClassificationTextRandomForestImpl.java

示例10: getClassifierFScore

import weka.classifiers.trees.RandomForest; //导入依赖的package包/类
public static double getClassifierFScore(int numTopics, String categoryName) throws Exception
	{
		//int numTopics=40;
		int seed  = 1;
		int folds = 10;
		DataSource trainSource = new DataSource("inputFiles/rawFiles/ARFF-files/"+categoryName+"-ARFF/"
						+categoryName+"-"+numTopics+".ARFF");
		Instances trainingSet = trainSource.getDataSet();
		if (trainingSet.classIndex() == -1)
			trainingSet.setClassIndex(trainingSet.numAttributes() - 1);

		// Resample for minority class
		Resample reSample=new Resample();
		reSample.setInputFormat(trainingSet);
		//reSample.s(1);
		trainingSet=Filter.useFilter(trainingSet, reSample);
//		trainingSet=Filter.useFilter(trainingSet, reSample);
//		trainingSet=Filter.useFilter(trainingSet, reSample);
//		trainingSet=Filter.useFilter(trainingSet, reSample);
		Random rand = new Random(seed);
		trainingSet.randomize(rand);
		if (trainingSet.classAttribute().isNominal())
			trainingSet.stratify(folds);

		RandomForest classifier=new RandomForest();

		//System.out.println("Training with "+classifier.getClass().getName());
		//System.out.println(trainingSet.numInstances());
		//classifier.buildClassifier(trainingSet);
		// perform cross-validation
		//Object[] obj={"hello"};
		Evaluation eval = new Evaluation(trainingSet);
		//Object[] forPredictionsPrinting = {"a","10","true"};
		eval.crossValidateModel(classifier, trainingSet, 10, new Random(1), new Object[] { });
		return eval.weightedFMeasure();
	}
 
开发者ID:siddBanPsu,项目名称:WikiKreator,代码行数:37,代码来源:TestClassifierPerformance.java

示例11: train

import weka.classifiers.trees.RandomForest; //导入依赖的package包/类
@Override
public RandomForest train(Instances instances) {
    RandomForest randomForest = new RandomForest();
    randomForest.setNumTrees(numTrees);
    try {
        randomForest.buildClassifier(instances);
    } catch (Exception e) {
        throw new ClassifierBuildingException("Exception occured while building classifier: " + e.getMessage(), e);
    }
    return randomForest;
}
 
开发者ID:NLeSC,项目名称:eEcology-Classification,代码行数:12,代码来源:RandomForestTrainer.java

示例12: train_zeroInstancesRf_resultIsRandomForestClassifier

import weka.classifiers.trees.RandomForest; //导入依赖的package包/类
@Test
public void train_zeroInstancesRf_resultIsRandomForestClassifier() {
    trainer = createGeneralTrainer("weka.classifiers.trees.RandomForest");
    Instances instances = getTestInstances();

    // Act
    Classifier classifier = trainer.train(instances);

    // Assert
    assertTrue(classifier instanceof RandomForest);
}
 
开发者ID:NLeSC,项目名称:eEcology-Classification,代码行数:12,代码来源:GeneralTrainerTest.java

示例13: train_setForestSize_randomForestHasCorrectSetting

import weka.classifiers.trees.RandomForest; //导入依赖的package包/类
@Test
public void train_setForestSize_randomForestHasCorrectSetting() {
    // Arrange

    // Act
    GeneralTrainer randomForestTrainer = createGeneralTrainer("weka.classifiers.trees.RandomForest -I 800"); // -I for number or trees
    RandomForest randomForest = (RandomForest) randomForestTrainer.train(getTestInstances());

    // Assert
    assertEquals(800, randomForest.getNumTrees());
}
 
开发者ID:NLeSC,项目名称:eEcology-Classification,代码行数:12,代码来源:GeneralTrainerTest.java

示例14: train_zeroInstances_resultIsRfClassifier

import weka.classifiers.trees.RandomForest; //导入依赖的package包/类
@Test
public void train_zeroInstances_resultIsRfClassifier() {
    trainer = createRandomForestTrainer();
    Instances instances = getTestInstances();

    // Act                  
    Classifier classifier = trainer.train(instances);

    // Assert
    assertTrue(classifier instanceof RandomForest);
}
 
开发者ID:NLeSC,项目名称:eEcology-Classification,代码行数:12,代码来源:RandomForestTrainerTest.java

示例15: constructor_numTreeGiven_rfHasCorrectNumTree

import weka.classifiers.trees.RandomForest; //导入依赖的package包/类
@Test
public void constructor_numTreeGiven_rfHasCorrectNumTree() {
    // Arrange

    // Act
    RandomForestTrainer rfTrainer = new RandomForestTrainer(123);
    RandomForest rf = rfTrainer.train(getTestInstances());

    // Assert
    assertEquals(123, rf.getNumTrees());
}
 
开发者ID:NLeSC,项目名称:eEcology-Classification,代码行数:12,代码来源:RandomForestTrainerTest.java


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