Example usage for weka.classifiers.trees RandomForest setNumIterations

List of usage examples for weka.classifiers.trees RandomForest setNumIterations

Introduction

In this page you can find the example usage for weka.classifiers.trees RandomForest setNumIterations.

Prototype

public void setNumIterations(int numIterations) 

Source Link

Document

Sets the number of bagging iterations

Usage

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 "";
}