List of usage examples for weka.classifiers.trees RandomForest setOptions
@Override public void setOptions(String[] options) throws Exception
From source file:de.tudarmstadt.ukp.dkpro.spelling.experiments.hoo2012.featureextraction.AllFeaturesExtractor.java
License:Apache License
private Classifier getClassifier() throws Exception { Classifier cl = null;//from ww w . jav a2 s . c o m // Build and evaluate classifier // The options given correspond to the default settings in the WEKA GUI if (classifier.equals("smo")) { SMO smo = new SMO(); smo.setOptions(Utils.splitOptions( "-C 1.0 -L 0.001 -P 1.0E-12 -N 0 -V -1 -W 1 -K \"weka.classifiers.functions.supportVector.PolyKernel -C 250007 -E 1.0\"")); cl = smo; } else if (classifier.equals("j48")) { J48 j48 = new J48(); j48.setOptions(new String[] { "-C", "0.25", "-M", "2" }); cl = j48; } else if (classifier.equals("naivebayes")) { cl = new NaiveBayes(); } else if (classifier.equals("randomforest")) { RandomForest rf = new RandomForest(); rf.setOptions(Utils.splitOptions("-I 10 -K 0 -S 1")); cl = rf; } return cl; }
From source file:my.randomforestui.RandomForestUI.java
public static double doRandomForest(Instances training, Instances testing) throws Exception { double accuracy; //inisialisasi random forest String[] options = new String[1]; // set tree random forest unpruned tree options[0] = "-U"; // new instance of tree RandomForest tree = new RandomForest(); // set the options tree.setOptions(options); // build classifier using training data tree.buildClassifier(training);/*from w w w. j av a 2 s. c om*/ Evaluation eval = new Evaluation(testing); eval.evaluateModel(tree, testing); //System.out.println((eval.correct()/56)*100); accuracy = (eval.correct() / 56) * 100; return accuracy; }
From source file:predictors.HelixIndexer.java
License:Open Source License
/** * Trains the Weka Classifer./* w w w. j a v a2s. c om*/ */ public void trainClassifier() { try { RandomForest classifier = new weka.classifiers.trees.RandomForest(); Instances data = this.dataset; if (data.classIndex() == -1) { data.setClassIndex(data.numAttributes() - 1); } data.randomize(new Random(data.size())); String[] optClassifier = weka.core.Utils.splitOptions("-I 100 -K 9 -S 1 -num-slots 3"); classifier.setOptions(optClassifier); classifier.setSeed(data.size()); classifier.buildClassifier(data); this.classifier = classifier; this.isTrained = true; } catch (Exception e) { ErrorUtils.printError(HelixIndexer.class, "Training failed", e); } }
From source file:predictors.TopologyPredictor.java
License:Open Source License
/** * Trains the Weka Classifer.//from w w w . j a v a2 s. co m */ public void trainClassifier() { try { RandomForest classifier = new weka.classifiers.trees.RandomForest(); Instances data = this.dataset; if (data.classIndex() == -1) { data.setClassIndex(data.numAttributes() - 1); } data.randomize(new Random(data.size())); String[] optClassifier = weka.core.Utils.splitOptions("-I 100 -K 7 -S 1 -num-slots 1"); classifier.setOptions(optClassifier); classifier.setSeed(data.size()); classifier.buildClassifier(data); this.classifier = classifier; this.isTrained = true; } catch (Exception e) { ErrorUtils.printError(TopologyPredictor.class, "Training failed", e); } }