List of usage examples for weka.classifiers.trees J48 J48
J48
From source file:org.dkpro.similarity.algorithms.ml.ClassifierSimilarityMeasure.java
License:Open Source License
public static Classifier getClassifier(WekaClassifier classifier) throws IllegalArgumentException { try {/*from w w w . ja va 2 s . com*/ switch (classifier) { case NAIVE_BAYES: return new NaiveBayes(); case J48: J48 j48 = new J48(); j48.setOptions(new String[] { "-C", "0.25", "-M", "2" }); return j48; case SMO: SMO smo = new SMO(); smo.setOptions(Utils.splitOptions( "-C 1.0 -L 0.001 -P 1.0E-12 -N 0 -V -1 -W 1 -K \"weka.classifiers.functions.supportVector.PolyKernel -C 250007 -E 1.0\"")); return smo; case LOGISTIC: Logistic logistic = new Logistic(); logistic.setOptions(Utils.splitOptions("-R 1.0E-8 -M -1")); return logistic; default: throw new IllegalArgumentException("Classifier " + classifier + " not found!"); } } catch (Exception e) { throw new IllegalArgumentException(e); } }
From source file:org.mcennis.graphrat.algorithm.machinelearning.MultiInstanceSVM.java
License:Open Source License
protected Classifier getClassifier() { if (((String) parameter[8].getValue()).contentEquals("J48")) { return new J48(); } else if (((String) parameter[8].getValue()).contentEquals("IBk")) { return new weka.classifiers.lazy.IBk(); } else if (((String) parameter[8].getValue()).contentEquals("PART")) { return new weka.classifiers.rules.PART(); } else if (((String) parameter[8].getValue()).contentEquals("NaiveBayes")) { return new weka.classifiers.bayes.NaiveBayes(); } else if (((String) parameter[8].getValue()).contentEquals("OneR")) { return new weka.classifiers.rules.OneR(); } else if (((String) parameter[8].getValue()).contentEquals("SMO")) { return new weka.classifiers.functions.SMO(); } else if (((String) parameter[8].getValue()).contentEquals("Logistir")) { return new weka.classifiers.functions.Logistic(); } else {// www. ja v a 2s . co m System.out.println("ERROR: Classifer '" + (String) parameter[8].getValue() + "' does not exist"); return null; } }
From source file:org.processmining.analysis.clusteranalysis.ClusterJ48Analyzer.java
License:Open Source License
/** * Default constructor./*from w ww . j av a 2s . c om*/ */ public ClusterJ48Analyzer() { myClassifier = new J48(); // create algorithm properties from the default values unprunedTree = new GUIPropertyBoolean("Use unpruned tree", ((J48) myClassifier).unprunedTipText(), ((J48) myClassifier).getUnpruned()); confidence = new GUIPropertyFloat("Confidence treshold for pruning", ((J48) myClassifier).confidenceFactorTipText(), ((J48) myClassifier).getConfidenceFactor(), (float) 0.0, (float) 1.0, (float) 0.01); minNoInstances = new GUIPropertyInteger("Minimun number of instances in any leaf", ((J48) myClassifier).minNumObjTipText(), ((J48) myClassifier).getMinNumObj(), 0, 1000); reducedPruning = new GUIPropertyBoolean("Use reduced-error pruning", ((J48) myClassifier).reducedErrorPruningTipText(), ((J48) myClassifier).getReducedErrorPruning()); numberFolds = new GUIPropertyInteger("Number of folds for reduced-error pruning", ((J48) myClassifier).numFoldsTipText(), ((J48) myClassifier).getNumFolds(), 1, 100); binarySplits = new GUIPropertyBoolean("Use binary splits only", ((J48) myClassifier).binarySplitsTipText(), ((J48) myClassifier).getBinarySplits()); subtreeRaising = new GUIPropertyBoolean("Perform subtree raising", ((J48) myClassifier).subtreeRaisingTipText(), ((J48) myClassifier).getSubtreeRaising()); retainInstanceInfo = new GUIPropertyBoolean("Retain instance information", ((J48) myClassifier).saveInstanceDataTipText(), ((J48) myClassifier).getSaveInstanceData()); smoothing = new GUIPropertyBoolean("Smooth the probability estimates using Laplace smoothing", ((J48) myClassifier).useLaplaceTipText(), ((J48) myClassifier).getUseLaplace()); seed = new GUIPropertyInteger("Seed for shuffling data", ((J48) myClassifier).seedTipText(), ((J48) myClassifier).getSeed(), 0, 100); }
From source file:org.processmining.analysis.clusteranalysis.ClusterJ48Analyzer.java
License:Open Source License
/** * Initializes data mining classifier to be used for analysis as a J48 * classifier (corresponds to the weka implementation of the C4.5 * algorithm)./*w w w . ja v a 2 s . c o m*/ */ protected void initClassifier() { myClassifier = new J48(); applyOptionalParameters(); }
From source file:org.processmining.analysis.decisionmining.J48Analyser.java
License:Open Source License
/** * Default constructor.//from w ww . java 2 s .c o m */ public J48Analyser() { myClassifier = new J48(); // create algorithm properties from the default values unprunedTree = new GUIPropertyBoolean("Use unpruned tree", ((J48) myClassifier).unprunedTipText(), ((J48) myClassifier).getUnpruned()); confidence = new GUIPropertyFloat("Confidence treshold for pruning", ((J48) myClassifier).confidenceFactorTipText(), ((J48) myClassifier).getConfidenceFactor(), (float) 0.0, (float) 1.0, (float) 0.01); minNoInstances = new GUIPropertyInteger("Minimun number of instances in any leaf", ((J48) myClassifier).minNumObjTipText(), ((J48) myClassifier).getMinNumObj(), 0, 1000); reducedPruning = new GUIPropertyBoolean("Use reduced-error pruning", ((J48) myClassifier).reducedErrorPruningTipText(), ((J48) myClassifier).getReducedErrorPruning()); numberFolds = new GUIPropertyInteger("Number of folds for reduced-error pruning", ((J48) myClassifier).numFoldsTipText(), ((J48) myClassifier).getNumFolds(), 1, 100); binarySplits = new GUIPropertyBoolean("Use binary splits only", ((J48) myClassifier).binarySplitsTipText(), ((J48) myClassifier).getBinarySplits()); subtreeRaising = new GUIPropertyBoolean("Perform subtree raising", ((J48) myClassifier).subtreeRaisingTipText(), ((J48) myClassifier).getSubtreeRaising()); retainInstanceInfo = new GUIPropertyBoolean("Retain instance information", ((J48) myClassifier).saveInstanceDataTipText(), ((J48) myClassifier).getSaveInstanceData()); smoothing = new GUIPropertyBoolean("Smooth the probability estimates using Laplace smoothing", ((J48) myClassifier).useLaplaceTipText(), ((J48) myClassifier).getUseLaplace()); seed = new GUIPropertyInteger("Seed for shuffling data", ((J48) myClassifier).seedTipText(), ((J48) myClassifier).getSeed(), 0, 100); }
From source file:org.processmining.analysis.decisionmining.J48AnalyserForAuLdg.java
License:Open Source License
/** * Default constructor./*from w ww. ja v a2s. c om*/ */ public J48AnalyserForAuLdg() { myClassifier = new J48(); // create algorithm properties from the default values unprunedTree = new GUIPropertyBoolean("Use unpruned tree", ((J48) myClassifier).unprunedTipText(), ((J48) myClassifier).getUnpruned()); confidence = new GUIPropertyFloat("Confidence treshold for pruning", ((J48) myClassifier).confidenceFactorTipText(), ((J48) myClassifier).getConfidenceFactor(), (float) 0.0, (float) 1.0, (float) 0.01); minNoInstances = new GUIPropertyInteger("Minimun number of instances in any leaf", ((J48) myClassifier).minNumObjTipText(), ((J48) myClassifier).getMinNumObj(), 0, 1000); reducedPruning = new GUIPropertyBoolean("Use reduced-error pruning", ((J48) myClassifier).reducedErrorPruningTipText(), ((J48) myClassifier).getReducedErrorPruning()); numberFolds = new GUIPropertyInteger("Number of folds for reduced-error pruning", ((J48) myClassifier).numFoldsTipText(), ((J48) myClassifier).getNumFolds(), 1, 100); binarySplits = new GUIPropertyBoolean("Use binary splits only", ((J48) myClassifier).binarySplitsTipText(), ((J48) myClassifier).getBinarySplits()); subtreeRaising = new GUIPropertyBoolean("Perform subtree raising", ((J48) myClassifier).subtreeRaisingTipText(), ((J48) myClassifier).getSubtreeRaising()); retainInstanceInfo = new GUIPropertyBoolean("Retain instance information", ((J48) myClassifier).saveInstanceDataTipText(), ((J48) myClassifier).getSaveInstanceData()); smoothing = new GUIPropertyBoolean("Smooth the probability estimates using Laplace smoothing", ((J48) myClassifier).useLaplaceTipText(), ((J48) myClassifier).getUseLaplace()); seed = new GUIPropertyInteger("Seed for shuffling data", ((J48) myClassifier).seedTipText(), ((J48) myClassifier).getSeed(), 0, 100); }
From source file:org.scify.NewSumServer.Server.MachineLearning.labelTagging.java
License:Apache License
/** * Find the recommend labels from classifier * * @return the recommend labels//www . j a v a2s . c o m */ public static String recommendation(INSECTDB file, String text) { String labelList = "-none-"; //create IVector String Ivector = vector.labellingVector(text, file); // take the similarity vectors for each class graph try { Instances dataTrainSet = dataSets.trainingSet(file); //take the train dataset Instances dataLabelSet = dataSets.labelingSet(file, Ivector);//take tha labe dataset ArffSaver saver = new ArffSaver(); saver.setInstances(dataTrainSet); saver.setFile(new File("./data/dataTrainSet.arff")); saver.writeBatch(); ArffSaver saver2 = new ArffSaver(); saver2.setInstances(dataLabelSet); saver2.setFile(new File("./data/dataLabelSet.arff")); saver2.writeBatch(); File temp = File.createTempFile("exportFile", null); //TODO: creat classifier // String option = "-S 2 -K 2 -D 3 -G 0.0 -R 0.0 -N 0.5 -M 40.0 -C 1.0 -E 0.001 -P 0.1"; // classifier options // String[] options = option.split("\\s+"); if (dataTrainSet.classIndex() == -1) { dataTrainSet.setClassIndex(dataTrainSet.numAttributes() - 1); } // Create a classifier LibSVM // NaiveBayes nb = new NaiveBayes(); // RandomForest nb = new RandomForest(); J48 nb = new J48(); // nb.setOptions(options); nb.buildClassifier(dataTrainSet); // End train method if (dataLabelSet.classIndex() == -1) { dataLabelSet.setClassIndex(dataLabelSet.numAttributes() - 1); } StringBuffer writer = new StringBuffer(); PlainText output = new PlainText(); output.setBuffer(writer); output.setHeader(dataLabelSet); output.printClassifications(nb, dataLabelSet); // PrintStream ps2 = new PrintStream(classGname); // ps2.print(writer.toString()); // ps2.close(); PrintStream ps = new PrintStream(temp); //Add to temp file the results of classifying ps.print(writer.toString()); ps.close(); //TODO: export result // labelList = result(temp); //if result is true adds the current class graph name in label list labelList = result(temp) + " --------->> " + text; //if result is true adds the current class graph name in label list Utilities.appendToFile(labelList); } catch (Exception ex) { Logger.getLogger(labelTagging.class.getName()).log(Level.SEVERE, null, ex); } return labelList; }
From source file:org.uclab.mm.kcl.ddkat.modellearner.ModelLearner.java
License:Apache License
/** * Method to compute the classification accuracy. * * @param algo the algorithm name// w w w . j a v a 2s . c o m * @param data the data instances * @param datanature the dataset nature (i.e. original or processed data) * @throws Exception the exception */ protected String[] modelAccuracy(String algo, Instances data, String datanature) throws Exception { String modelResultSet[] = new String[4]; String modelStr = ""; Classifier classifier = null; // setting class attribute if the data format does not provide this information if (data.classIndex() == -1) data.setClassIndex(data.numAttributes() - 1); String decisionAttribute = data.attribute(data.numAttributes() - 1).toString(); String res[] = decisionAttribute.split("\\s+"); decisionAttribute = res[1]; if (algo.equals("BFTree")) { // Use BFTree classifiers BFTree BFTreeclassifier = new BFTree(); BFTreeclassifier.buildClassifier(data); modelStr = BFTreeclassifier.toString(); classifier = BFTreeclassifier; } else if (algo.equals("FT")) { // Use FT classifiers FT FTclassifier = new FT(); FTclassifier.buildClassifier(data); modelStr = FTclassifier.toString(); classifier = FTclassifier; } else if (algo.equals("J48")) { // Use J48 classifiers J48 J48classifier = new J48(); J48classifier.buildClassifier(data); modelStr = J48classifier.toString(); classifier = J48classifier; System.out.println("Model String: " + modelStr); } else if (algo.equals("J48graft")) { // Use J48graft classifiers J48graft J48graftclassifier = new J48graft(); J48graftclassifier.buildClassifier(data); modelStr = J48graftclassifier.toString(); classifier = J48graftclassifier; } else if (algo.equals("RandomTree")) { // Use RandomTree classifiers RandomTree RandomTreeclassifier = new RandomTree(); RandomTreeclassifier.buildClassifier(data); modelStr = RandomTreeclassifier.toString(); classifier = RandomTreeclassifier; } else if (algo.equals("REPTree")) { // Use REPTree classifiers REPTree REPTreeclassifier = new REPTree(); REPTreeclassifier.buildClassifier(data); modelStr = REPTreeclassifier.toString(); classifier = REPTreeclassifier; } else if (algo.equals("SimpleCart")) { // Use SimpleCart classifiers SimpleCart SimpleCartclassifier = new SimpleCart(); SimpleCartclassifier.buildClassifier(data); modelStr = SimpleCartclassifier.toString(); classifier = SimpleCartclassifier; } modelResultSet[0] = algo; modelResultSet[1] = decisionAttribute; modelResultSet[2] = modelStr; // Collect every group of predictions for J48 model in a FastVector FastVector predictions = new FastVector(); Evaluation evaluation = new Evaluation(data); int folds = 10; // cross fold validation = 10 evaluation.crossValidateModel(classifier, data, folds, new Random(1)); // System.out.println("Evaluatuion"+evaluation.toSummaryString()); System.out.println("\n\n" + datanature + " Evaluatuion " + evaluation.toMatrixString()); // ArrayList<Prediction> predictions = evaluation.predictions(); predictions.appendElements(evaluation.predictions()); System.out.println("\n\n 11111"); // Calculate overall accuracy of current classifier on all splits double correct = 0; for (int i = 0; i < predictions.size(); i++) { NominalPrediction np = (NominalPrediction) predictions.elementAt(i); if (np.predicted() == np.actual()) { correct++; } } System.out.println("\n\n 22222"); double accuracy = 100 * correct / predictions.size(); String accString = String.format("%.2f%%", accuracy); modelResultSet[3] = accString; System.out.println(datanature + " Accuracy " + accString); String modelFileName = algo + "-DDKA.model"; System.out.println("\n\n 33333"); ObjectOutputStream oos = new ObjectOutputStream( new FileOutputStream("D:\\DDKAResources\\" + modelFileName)); oos.writeObject(classifier); oos.flush(); oos.close(); return modelResultSet; }
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 */// w w w .ja v a 2 s . c o m @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 w w w. j a va2 s . c o 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; }