List of usage examples for weka.classifiers Evaluation Evaluation
public Evaluation(Instances data) throws Exception
From source file:myclassifier.naiveBayes.java
public void TestData(Instances dataTest) throws Exception { if (data != null) { Instances train = data;//from ww w . j a v a2 s. c o m // train classifier NBClassifier.buildClassifier(train); // evaluate classifier and print some statistics Evaluation eval = new Evaluation(dataTest); System.out.println(eval.toSummaryString("\nResults\n======\n", false)); System.out.println(eval.toClassDetailsString("\n=== Detailed Accuracy By Class ===\n")); System.out.println(eval.toMatrixString()); } else { System.out.println("Data is null"); } }
From source file:myclassifier.naiveBayes.java
public void CrossValidation() throws Exception { if (data != null) { Instances train = data;/* ww w . j ava 2s. c o m*/ // train classifier NBClassifier.buildClassifier(train); // evaluate classifier and print some statistics Evaluation eval = new Evaluation(train); eval.crossValidateModel(NBClassifier, train, 10, new Random(1)); System.out.println(eval.toSummaryString("\nResults\n======\n", false)); System.out.println(eval.toClassDetailsString("\n=== Detailed Accuracy By Class ===\n")); System.out.println(eval.toMatrixString()); } else { System.out.println("Data is null"); } }
From source file:myclassifier.naiveBayes.java
public void PercentageSplit(double percent) throws Exception { // Percent split int trainSize = (int) Math.round(data.numInstances() * percent / 100); int testSize = data.numInstances() - trainSize; Instances train = new Instances(data, 0, trainSize); Instances test = new Instances(data, trainSize, testSize); // train classifier NBClassifier.buildClassifier(train); // evaluate classifier and print some statistics Evaluation eval = new Evaluation(train); eval.evaluateModel(NBClassifier, test); System.out.println(eval.toSummaryString("\nResults\n======\n", false)); System.out.println(eval.toClassDetailsString("\n=== Detailed Accuracy By Class ===\n")); System.out.println(eval.toMatrixString()); }
From source file:myclassifier.Util.java
public static void percentageSplit(Instances data, Classifier cls) throws Exception { int trainSize = (int) Math.round(data.numInstances() * 0.8); int testSize = data.numInstances() - trainSize; Instances train = new Instances(data, 0, trainSize); Instances test = new Instances(data, trainSize, testSize); Evaluation eval = new Evaluation(train); eval.evaluateModel(cls, test);/*from w w w . j ava 2 s .c o m*/ }
From source file:myclassifier.wekaCode.java
public static void testingTestSet(Instances dataSet, Classifier classifiers, Instances testSet) throws Exception { Evaluation evaluation = new Evaluation(dataSet); evaluation.evaluateModel(classifiers, testSet); //Evaluates the classifier on a given set of instances. System.out.println(evaluation.toSummaryString("\n Testing Model given Test Set ", false)); System.out.println(evaluation.toClassDetailsString()); }
From source file:myclassifier.wekaCode.java
public static void foldValidation(Instances dataSet, Classifier classifiers) throws Exception { Evaluation evaluation = new Evaluation(dataSet); evaluation.crossValidateModel(classifiers, dataSet, 10, new Random(1)); //Evaluates the classifier on a given set of instances. System.out.println(evaluation.toSummaryString("\n 10-fold cross validation", false)); System.out.println(evaluation.toMatrixString("\n Confusion Matrix")); }
From source file:myid3andc45classifier.Main.java
/** * @param args the command line arguments *///from w w w.ja va 2 s . c o m public static void main(String[] args) throws Exception { // TODO code application logic here WekaAccessor accessor = new WekaAccessor(); Instances trainset; trainset = accessor.readARFF( "D:\\Semester VII\\ML\\myID3andC45classifier\\myID3andC45classifier\\resources\\iris.arff"); Classifier j48 = new J48(); Classifier model = accessor.train(trainset, j48); //accessor.saveModel(model, "C:\\Users\\Julio Savigny\\Desktop\\myID3andC45classifier\\myID3andC45classifier\\some.model"); //Classifier loadedModel = accessor.loadModel("C:\\Users\\Julio Savigny\\Desktop\\myID3andC45classifier\\myID3andC45classifier\\some.model"); System.out.println(model); //System.out.println(loadedModel); // Coba ID3 Apoy Classifier customID3 = new MyC45(); Classifier myId3Model = accessor.train(trainset, customID3); Instances resampledTrainset = accessor.resample(trainset); System.out.println("WOY"); System.out.println(myId3Model); System.out.println(accessor.tenFoldCrossValidation(trainset, customID3).toSummaryString()); Evaluation eval = new Evaluation(trainset); eval.evaluateModel(myId3Model, trainset); //System.out.println(eval.toSummaryString()); // System.out.println(trainset); // System.out.println(resampledTrainset); // Coba C4.5 Bayu // Classifier customC45 = new myC45(); // Classifier myC45Model = accessor.train(trainset, customC45); // System.out.println(myC45Model); }
From source file:NaiveBayes.NaiveBayes.java
/** * @param args the command line arguments * @throws java.io.IOException/*w w w. j a va2 s. c om*/ */ public static void main(String[] args) throws IOException, Exception { System.out.print("1. Buat Model \n"); System.out.print("2. Load Model\n"); System.out.print("Masukkan pilihan : "); Scanner sc = new Scanner(System.in); int pil = sc.nextInt(); System.out.print("Masukkan nama file : "); String filename = sc.next(); DataSource source = new DataSource(("D:\\Program Files\\Weka-3-8\\data\\" + filename)); Instances train = source.getDataSet(); for (int i = 0; i < train.numAttributes(); i++) System.out.println(i + ". " + train.attribute(i).name()); System.out.print("Masukkan indeks kelas : "); int classIdx = sc.nextInt(); train.setClassIndex(classIdx); // MultilayerPerceptron mlp = new MultilayerPerceptron(train, 0.1, 10000, 14); // mlp.buildClassifier(train); // Evaluation eval = new Evaluation (train); //// eval.evaluateModel(mlp, train); // System.out.println(eval.toSummaryString()); NaiveBayes tb = new NaiveBayes(); Evaluation eval = new Evaluation(train); switch (pil) { case 1: // tb.buildClassifier(train); // tb.toSummaryString(); // eval.evaluateModel(tb, train); eval.crossValidateModel(tb, train, 10, new Random(1)); System.out.println(eval.toSummaryString(true)); System.out.println(eval.toMatrixString()); //saveModel(tb); break; default: tb = loadModel(); tb.toSummaryString(); eval.crossValidateModel(tb, train, 10, new Random(1)); System.out.println(eval.toSummaryString()); // System.out.println(eval.toMatrixString()); } }
From source file:naivebayes.NBRun.java
public static void main(String[] args) throws Exception { System.out.println("Naive Bayes Classifier"); Instances data = TucilWeka.readDataSet("C:\\Program Files\\Weka-3-8\\data\\mush_test.arff"); Scanner scan = new Scanner(System.in); Classifier cls;/*from ww w .j a v a2 s . c o m*/ Instances train = TucilWeka.readDataSet("C:\\Program Files\\Weka-3-8\\data\\mush.arff"); System.out.println("Read or create model? r/c"); if (scan.next().equals("c")) { cls = new NBTubesAI(); cls.buildClassifier(train); TucilWeka.saveModel(train); } else { cls = (NBTubesAI) TucilWeka.readModel(); } Evaluation eval = new Evaluation(data); System.out.println("10 fold cross validate or Full train? c/f"); if (scan.next().equals("c")) { int fold = 10; for (int i = 0; i < data.numAttributes(); i++) { System.out.println(i + ". " + data.attribute(i)); } eval.crossValidateModel(cls, data, fold, new Random(1)); } else { for (int i = 0; i < data.numAttributes(); i++) { System.out.println(i + ". " + data.attribute(i)); } data.deleteWithMissingClass(); try { eval.evaluateModel(cls, data); } catch (java.lang.Exception ex) { eval.crossValidateModel(cls, data, 11, new Random(1)); } } // Classifier cls=new NBTubesAI(); // cls.buildClassifier(data); System.out.println("Hasil evaluasi: "); System.out.println(eval.toSummaryString()); System.out.println(eval.toMatrixString()); System.out.println(eval.toClassDetailsString()); }
From source file:naivebayes.TucilWeka.java
public static Evaluation crossValidation(Instances data) { //10-fold cross validation Evaluation eval = null;/* w w w . j a v a 2 s. co m*/ try { eval = new Evaluation(data); Classifier cls = new NBTubesAI(); if (cls == null) { System.out.println("MODEL CANNOT BE USED"); } else { System.out.println("MODEL IS USED"); } cls.buildClassifier(data); //crossValidateModel: //param 1 = tipe classifier (disini J48) //param 2 = Instances data //param 3 = jumlah fold //param 4 = Randomizer (seed) eval.crossValidateModel(cls, data, 10, new Random(1)); } catch (Exception ex) { Logger.getLogger(TucilWeka.class.getName()).log(Level.SEVERE, null, ex); } return eval; }