List of usage examples for weka.classifiers.trees RandomForest setNumIterations
public void setNumIterations(int numIterations)
From source file:KFST.featureSelection.embedded.TreeBasedMethods.RandomForestMethod.java
License:Open Source License
/** * {@inheritDoc }/*from ww w . jav a 2 s .c o m*/ */ @Override protected String buildClassifier(Instances dataTrain) { try { RandomForest decisionTreeRandomForest = new RandomForest(); decisionTreeRandomForest.setNumFeatures(randomForestNumFeatures); decisionTreeRandomForest.setMaxDepth(randomForestMaxDepth); decisionTreeRandomForest.setNumIterations(randomForestNumIterations); decisionTreeRandomForest.setComputeAttributeImportance(true); decisionTreeRandomForest.buildClassifier(dataTrain); /** * Creating an array of indices of the features based on descending * order of features' importance */ double[] nodeCounts = new double[numFeatures + 1]; double[] impurityScores = decisionTreeRandomForest .computeAverageImpurityDecreasePerAttribute(nodeCounts); int[] sortedIndices = Utils.sort(impurityScores); String sortedIndicesToString = ""; for (int i = sortedIndices.length - 1; i >= 0; i--) { if (sortedIndices[i] != numFeatures) { sortedIndicesToString += String.valueOf(sortedIndices[i]) + " "; } } return sortedIndicesToString.trim(); //return decisionTreeRandomForest.toString(); } catch (Exception ex) { Logger.getLogger(RandomForestMethod.class.getName()).log(Level.SEVERE, null, ex); } return ""; }