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


Java RandomForest.setNumTrees方法代码示例

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


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

示例1: 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

示例2: trainModel

import weka.classifiers.trees.RandomForest; //导入方法依赖的package包/类
/**
 * Train a model and save to filesystme
 *
 * @param trainArffFileName
 */
private static void trainModel(String trainArffFileName) {
    try {
        Instances structure = new Instances(new FileReader(new File(System.getProperty("user.dir") + "/data/Arffs/" + trainArffFileName + ".arff")));
        structure.setClassIndex(structure.numAttributes() - 1);
        System.out.println("Loaded data from arff file...");

        RandomForest randomForest = new RandomForest();
        randomForest.setNumFeatures(30);
        randomForest.setNumTrees(1000);

        System.out.println("Training...");
        randomForest.buildClassifier(structure);

        System.out.println("Saving trained model to '" + trainArffFileName + "'.");

        // Write trained model to file
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream(new File(System.getProperty("user.dir") + "/data/Models/" + trainArffFileName + ".model")));
        objectOutputStream.writeObject(randomForest);
        objectOutputStream.flush();
        objectOutputStream.close();

    } catch (Exception e) {
        e.printStackTrace();
    }

}
 
开发者ID:ajaybhat,项目名称:Essay-Grading-System,代码行数:32,代码来源:Classifier.java

示例3: build

import weka.classifiers.trees.RandomForest; //导入方法依赖的package包/类
@Override
public Classifier build(List<PageWithType> trainingSet) {
    List<CompositeClassifier.ClassifierEntry> classifiers = new ArrayList<>();
    try {
        /*
        logger.info("train IBk");
        classifiers.add(new CompositeClassifier.ClassifierEntry("IBk",
                new ClassifierBuilder(new IBk()).train(pageInfos), 0.3));
        */

        logger.info("train J48");
        classifiers.add(new CompositeClassifier.ClassifierEntry("J48",
                new ClassifierBuilder(new J48()).train(trainingSet), 1));

        logger.info("train SMO");
        classifiers.add(new CompositeClassifier.ClassifierEntry("SMO",
                new ClassifierBuilder(new SMO())
                        .setExtractSummary1Grams(true)
                        .setExtractSummary2Grams(true)
                        .setExtractSummary3Grams(true)
                        .train(trainingSet), 1));

        logger.info("train RandomForest");
        RandomForest randomForest = new RandomForest(); randomForest.setNumTrees(200);
        classifiers.add(new CompositeClassifier.ClassifierEntry("RandomForest",
                new ClassifierBuilder(randomForest).train(trainingSet), 1));

        logger.info("train NaiveBayes");
        classifiers.add(new CompositeClassifier.ClassifierEntry("NaiveBayes",
                new ClassifierBuilder(new NaiveBayes()).train(trainingSet), 1));

    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return new CompositeClassifier(classifiers);
}
 
开发者ID:ArturD,项目名称:holmes,代码行数:37,代码来源:DefaultClassifierFactory.java


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