List of usage examples for weka.classifiers.lazy KStar KStar
KStar
From source file:au.edu.usyd.it.yangpy.snp.Ensemble.java
License:Open Source License
public void ensemble(String mode) throws Exception { numInstances = test.numInstances();//from ww w .ja v a 2 s. com numClasses = test.numClasses(); givenValue = new double[numInstances]; predictDistribution = new double[numClassifiers][numInstances][numClasses]; predictValue = new double[numClassifiers][numInstances]; voteValue = new double[numInstances][numClasses]; // Setting the given class values of the test instances. for (int i = 0; i < numInstances; i++) { givenValue[i] = test.instance(i).classValue(); } // Calculating the predicted class values using each classifier respectively. // J48 coverTree1NN KStar coverTree3NN coverTree5NN J48 tree = new J48(); tree.setUnpruned(true); aucClassifiers[0] = classify(tree, 0); KStar kstar = new KStar(); aucClassifiers[1] = classify(kstar, 1); IBk ctnn1 = new IBk(1); CoverTree search = new CoverTree(); ctnn1.setNearestNeighbourSearchAlgorithm(search); aucClassifiers[2] = classify(ctnn1, 2); IBk ctnn3 = new IBk(3); ctnn3.setNearestNeighbourSearchAlgorithm(search); aucClassifiers[3] = classify(ctnn3, 3); IBk ctnn5 = new IBk(5); ctnn5.setNearestNeighbourSearchAlgorithm(search); aucClassifiers[4] = classify(ctnn5, 4); // Print the classification results if in print mode. if (mode.equals("v")) { System.out.println("J48 AUC: " + aucClassifiers[0]); System.out.println("KStar AUC: " + aucClassifiers[1]); System.out.println("CTNN1 AUC: " + aucClassifiers[2]); System.out.println("CTNN3 AUC: " + aucClassifiers[3]); System.out.println("CTNN5 AUC: " + aucClassifiers[4]); System.out.println(" - - "); } }
From source file:LeerArchivo.Leer.java
public void leerArchivoArff() { try {//from ww w . j av a 2s .co m // create J48 Classifier cls = new KStar(); // train Instances inst = new Instances(new BufferedReader(new FileReader("../datos.arff"))); inst.setClassIndex(inst.numAttributes() - 1); cls.buildClassifier(inst); // serialize model ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("./KStar.model")); oos.writeObject(cls); oos.flush(); oos.close(); } catch (IOException ex) { Logger.getLogger(Leer.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception ex) { Logger.getLogger(Leer.class.getName()).log(Level.SEVERE, null, ex); } }