Wed May 20, 2015 8:15 pm
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package wekatest;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Random;
import weka.classifiers.Evaluation;
import weka.classifiers.bayes.NaiveBayes;
import weka.classifiers.trees.RandomForest;
import weka.core.Instances;
/**
*
* @author samy
*/
public class WekaTest {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
BufferedReader br = null;
int numFolds = 10;
br = new BufferedReader(new FileReader("D:\\martin\\DataSet\\Mozilla.arff"));
Instances trainData = new Instances(br);
trainData.setClassIndex(trainData.numAttributes() - 1);
br.close();
RandomForest rf = new RandomForest();
rf.setNumTrees(100);
// rf.buildClassifier(trainData);
Evaluation evaluation = new Evaluation(trainData);
evaluation.crossValidateModel(rf, trainData, numFolds, new Random(1));
System.out.println(evaluation.toSummaryString("\nResults\n======\n", true));
System.out.println(evaluation.toClassDetailsString());
System.out.println("Results For Class -1- ");
System.out.println("Precision= " + evaluation.precision(0));
System.out.println("Recall= " + evaluation.recall(0));
System.out.println("F-measure= " + evaluation.fMeasure(0));
System.out.println("Results For Class -2- ");
System.out.println("Precision= " + evaluation.precision(1));
System.out.println("Recall= " + evaluation.recall(1));
System.out.println("F-measure= " + evaluation.fMeasure(1));
}
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.