List of usage examples for weka.classifiers.meta FilteredClassifier FilteredClassifier
public FilteredClassifier()
From source file:org.vimarsha.classifier.impl.FunctionWiseClassifier.java
License:Open Source License
/** * Classifies function wise test instances in the associated with the names labels mentioned in the arraylist passed as the argument. * * @param list - labels of instances contained in the test set that need to be classified. * @return TreeMap containing the instance labels and the associated classification results. * @throws ClassificationFailedException *//*from ww w . j a v a 2 s .c om*/ @Override public LinkedHashMap<String, String> classify(LinkedList<String> list) throws ClassificationFailedException { output = new LinkedHashMap<String, String>(); J48 j48 = new J48(); Remove rm = new Remove(); rm.setAttributeIndices("1"); FilteredClassifier fc = new FilteredClassifier(); fc.setFilter(rm); fc.setClassifier(j48); try { fc.buildClassifier(trainSet); for (int i = 0; i < testSet.numInstances(); i++) { double pred = fc.classifyInstance(testSet.instance(i)); if (list.isEmpty()) { output.put(String.valueOf(i + 1), testSet.classAttribute().value((int) pred)); } else { output.put(list.get(i), testSet.classAttribute().value((int) pred)); } } } catch (Exception ex) { throw new ClassificationFailedException(); } return output; }
From source file:org.vimarsha.classifier.impl.TimeslicedClassifier.java
License:Open Source License
/** * Classifies Timesliced test data instances. * * @return Resulting linked list with timelsiced classification results. * @throws ClassificationFailedException *///from ww w . java2 s .co m @Override public Object classify() throws ClassificationFailedException { output = new LinkedList<String>(); J48 j48 = new J48(); Remove rm = new Remove(); rm.setAttributeIndices("1"); FilteredClassifier fc = new FilteredClassifier(); fc.setFilter(rm); fc.setClassifier(j48); try { fc.buildClassifier(trainSet); for (int i = 0; i < testSet.numInstances(); i++) { //System.out.println(testSet.instance(i)); double pred = fc.classifyInstance(testSet.instance(i)); output.add(testSet.classAttribute().value((int) pred)); } } catch (Exception ex) { System.out.println(ex.toString()); throw new ClassificationFailedException(); } return output; }
From source file:org.vimarsha.classifier.impl.WholeProgramClassifier.java
License:Open Source License
/** * Classifies whole program test instances, * * @return String containing the classification result of the evaluated program's dataset. * @throws ClassificationFailedException */// w w w .j a va 2 s . c o m @Override public Object classify() throws ClassificationFailedException { J48 j48 = new J48(); Remove rm = new Remove(); String output = null; rm.setAttributeIndices("1"); FilteredClassifier fc = new FilteredClassifier(); fc.setFilter(rm); fc.setClassifier(j48); try { fc.buildClassifier(trainSet); this.treeModel = j48.toString(); double pred = fc.classifyInstance(testSet.instance(0)); output = testSet.classAttribute().value((int) pred); classificationResult = output; } catch (Exception ex) { throw new ClassificationFailedException(); } return output; }
From source file:pl.nask.hsn2.service.analysis.JSWekaAnalyzer.java
License:Open Source License
private void createClassifier(String classifierName) { try {//w w w .ja va2 s.com Classifier classifier = (Classifier) Class.forName(classifierName).newInstance(); FilteredClassifier filteredClassifier = new FilteredClassifier(); filteredClassifier.setClassifier(classifier); filteredClassifier.setFilter(new StringToWordVector()); filteredClassifier.buildClassifier(trainingSet); fc = filteredClassifier; } catch (Exception e) { LOGGER.error(e.getMessage(), e); } }
From source file:prismcrossvalidation.Classifier.java
static public String crossValidationPRISM_DISCRET() throws FileNotFoundException, IOException, Exception { String prismResult = ""; String source = MainWindow.pathChooseField.getText(); Instances data = DataLoad.loadData(source.replace("\\", "/")); data.setClassIndex(data.numAttributes() - 1); Discretize filter = new Discretize(); Prism rules = new Prism(); FilteredClassifier fClassifier = new FilteredClassifier(); fClassifier.setFilter(filter); //Ustawienie aktualnego filtra fClassifier.setClassifier(rules); //Ustawienie aktualnego klasyfikatora Evaluation eval = new MyEvaluation(data); eval.crossValidateModel(fClassifier, data, fold, new Random(1)); //CV dla 10 foldow System.out.println("amount of folds: " + fold); MainWindow.logArea.append("Amount of folds: " + fold); System.out.println(eval.toSummaryString("Wyniki:", false)); MainWindow.logArea.append(eval.toSummaryString("Wyniki:", false)); return prismResult = eval.toSummaryString("Wyniki:", false); }