本文整理汇总了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;
}
示例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();
}
}
示例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);
}