List of usage examples for weka.classifiers Classifier buildClassifier
public abstract void buildClassifier(Instances data) throws Exception;
From source file:tr.gov.ulakbim.jDenetX.classifiers.WEKAClassifier.java
License:Open Source License
public void buildClassifier() { try {// ww w. ja v a2 s. c o m if ((classifier instanceof UpdateableClassifier) == false) { Classifier auxclassifier = AbstractClassifier.makeCopy(classifier); auxclassifier.buildClassifier(instancesBuffer); classifier = auxclassifier; isBufferStoring = false; } } catch (Exception e) { System.err.println("Building WEKA Classifier: " + e.getMessage()); } }
From source file:Tubes.Classification.java
public Evaluation runClassifier(Classifier model, Instances training, Instances testing) { try {/*w w w . ja v a 2 s . c o m*/ Evaluation eval_train = new Evaluation(training); model.buildClassifier(training); eval_train.evaluateModel(model, testing); return eval_train; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:tubes1.Main.java
public static Evaluation classify(Classifier model, Instances trainingSet, Instances testingSet) throws Exception { Evaluation evaluation = new Evaluation(trainingSet); model.buildClassifier(trainingSet); evaluation.evaluateModel(model, testingSet); return evaluation; }
From source file:tucil.dua.ai.TucilDuaAi.java
public static void fullTrainingSet() throws Exception { Classifier j48 = new J48(); j48.buildClassifier(datas); Evaluation eval = new Evaluation(datas); eval.evaluateModel(j48, datas);/*from ww w . jav a 2 s .c o m*/ System.out.println("=====Run Information======"); System.out.println("======Classifier Model======"); System.out.println(j48.toString()); System.out.println(eval.toSummaryString("====Stats======\n", false)); System.out.println(eval.toClassDetailsString("====Detailed Result=====\n")); System.out.println(eval.toMatrixString("======Confusion Matrix======\n")); }
From source file:tucil.dua.ai.TucilDuaAi.java
public static void crossValidation() throws Exception { Evaluation evaluation = new Evaluation(datas); Classifier attr_tree = new J48(); attr_tree.buildClassifier(datas); evaluation.crossValidateModel(attr_tree, datas, 10, new Random(1)); System.out.println("=====Run Information======"); System.out.println("======Classifier Model======"); System.out.println(attr_tree.toString()); System.out.println(evaluation.toSummaryString("====Stats======\n", false)); System.out.println(evaluation.toClassDetailsString("====Detailed Result=====\n")); System.out.println(evaluation.toMatrixString("======Confusion Matrix======\n")); }
From source file:tucil2ai.Tucil2AI.java
/** * * @param args//w w w. j av a 2 s .com * @throws Exception */ public static void main(String[] args) throws Exception { // TODO code application logic here DataSource source; Instances data; Instances data_filtered; Discretize filter; Classifier clsJ48 = null; source = new DataSource("res/iris.arff"); data = source.getDataSet(); data.setClassIndex(data.numAttributes() - 1); System.out.println("Data berhasil dibaca"); // filter filter = new Discretize(); filter.setInputFormat(data); data_filtered = Filter.useFilter(data, filter); System.out.println("Data berhasil difilter"); int pil = 0; while (pil != 3) { menu(); Scanner sc = new Scanner(System.in); pil = sc.nextInt(); switch (pil) { case 1: clsJ48 = loadModel(); System.out.println("Model berhasil dimuat"); break; case 2: clsJ48 = new J48(); clsJ48.buildClassifier(data_filtered); int pil3; System.out.println("Apakah Anda mau menyimpan model ini?"); System.out.println("1. Ya"); System.out.println("2. Tidak"); pil3 = sc.nextInt(); if (pil3 == 1) { saveModel(clsJ48); } break; default: break; } if (pil == 3) continue; System.out.println("Pilih metode evaluasi:"); System.out.println("1. 10-fold cross validation"); System.out.println("2. Full-test"); System.out.println("3. Klasifikasikan datatest"); int pilmethod; pilmethod = sc.nextInt(); while (pilmethod < 1 || pilmethod > 3) { System.out.println("Masukan salah!"); pilmethod = sc.nextInt(); } if (pilmethod != 3) { Evaluation eval = evalJ48(clsJ48, data_filtered, pilmethod == 1); printEval(eval); } else { ClassifyJ48(clsJ48, "res/datatest.arff", filter); System.out.println("Terbentuk 3 instance baru untuk diklasifikasi"); } } }
From source file:wekimini.learning.ModelEvaluator.java
public void evaluateAll(final List<Path> paths, final boolean isTraining, final int numFolds, PropertyChangeListener listener) { final List<Instances> data = new LinkedList<>(); for (Path p : paths) { Instances i = w.getSupervisedLearningManager().getTrainingDataForPath(p, false); data.add(i);//from w w w .jav a2 s . c o m } setResults(new String[paths.size()]); if (evalWorker != null && evalWorker.getState() != SwingWorker.StateValue.DONE) { return; } evalWorker = new SwingWorker<Integer, Void>() { //trainingWorker. @Override public Integer doInBackground() { // train(); //TODO: Add status updates int progress = 0; //setProgress(progress); int numToEvaluate = 0; for (Path p : paths) { if (p.canBuild()) { numToEvaluate++; } } int numEvaluated = 0; int numErr = 0; setEvalStatus(new EvaluationStatus(numToEvaluate, numEvaluated, numErr, false)); for (int i = 0; i < paths.size(); i++) { Path p = paths.get(i); if (p.canBuild()) { try { System.out.println("Evaluating with " + numFolds); //EVALUATE HERE: TODO Instances instances = w.getSupervisedLearningManager().getTrainingDataForPath(p, false); Evaluation eval = new Evaluation(instances); Classifier c = ((LearningModelBuilder) p.getModelBuilder()).getClassifier(); if (!isTraining) { Random r = new Random(); eval.crossValidateModel(c, instances, numFolds, r); } else { Classifier c2 = Classifier.makeCopy(c); c2.buildClassifier(instances); eval.evaluateModel(c2, instances); } String result; if (p.getModelBuilder() instanceof ClassificationModelBuilder) { result = dFormat.format(eval.pctCorrect()) + "%"; //WON"T WORK FOR NN } else { result = dFormat.format(eval.errorRate()) + " (RMS)"; } if (!isTraining) { KadenzeLogging.getLogger().crossValidationComputed(w, i, numFolds, result); } else { KadenzeLogging.getLogger().trainingAccuracyComputed(w, i, result); } setResults(i, result); finishedModel(i, result); numEvaluated++; if (isCancelled()) { cancelMe(p); setResults(i, "Cancelled"); return 0; } } catch (InterruptedException ex) { cancelMe(p); setResults(i, "Cancelled"); return 0; //Not sure this will be called... } catch (Exception ex) { numErr++; Util.showPrettyErrorPane(null, "Error encountered during evaluation " + p.getCurrentModelName() + ": " + ex.getMessage()); logger.log(Level.SEVERE, ex.getMessage()); } setEvalStatus(new EvaluationStatus(numToEvaluate, numEvaluated, numErr, false)); } else { logger.log(Level.WARNING, "Could not evaluate path"); } } wasCancelled = false; hadError = evaluationStatus.numErrorsEncountered > 0; return 0; } @Override public void done() { if (isCancelled()) { EvaluationStatus t = new EvaluationStatus(evaluationStatus.numToEvaluate, evaluationStatus.numEvaluated, evaluationStatus.numErrorsEncountered, true); setEvalStatus(t); } finished(); } }; evalWorker.addPropertyChangeListener(listener); evalWorker.execute(); }
From source file:wekimini.WekaModelBuilderHelper.java
public static Classifier build(Classifier c, Instances data) throws Exception { c.buildClassifier(data); return Classifier.makeCopy(c); //TODO: May have to do Classifier.makeCopy }