J48 model=new J48(); model.buildClassifier(test);
J48 j48 = new J48(); j48.buildClassifier(train); weka.core.SerializationHelper.write("/some/where/j48.model", j48);
/** * Returns the value of the named measure * * @param additionalMeasureName the name of the measure to query for its value * @return the value of the named measure * @throws IllegalArgumentException if the named measure is not supported */ @Override public double getMeasure(String additionalMeasureName) { if (additionalMeasureName.compareToIgnoreCase("measureNumRules") == 0) { return measureNumRules(); } else if (additionalMeasureName.compareToIgnoreCase("measureTreeSize") == 0) { return measureTreeSize(); } else if (additionalMeasureName.compareToIgnoreCase("measureNumLeaves") == 0) { return measureNumLeaves(); } else { throw new IllegalArgumentException(additionalMeasureName + " not supported (j48)"); } }
/** * Main method for testing this class * * @param argv the commandline options */ public static void main(String[] argv) { runClassifier(new J48(), argv); } }
public static Classifier getClassifier(WekaClassifier classifier) throws IllegalArgumentException { try { 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); } }
J48 tree = new J48(); tree.buildClassifier(dataset); tree.toSource(testt); System.out.println(tree.toString());
J48 j48 = new J48(); j48.setUnpruned(true); // using an unpruned J48 j48.buildClassifier(train); System.out.print(j48.graph());
public void testListParameterFlag() throws Exception { ListParameter listparameter = new ListParameter(); String options = "-list \"true false\" -property \"unpruned\""; listparameter.setOptions(Utils.splitOptions(options)); Vector<Performance> results = searchValuesAll(listparameter, new J48()); Map<Boolean, Boolean> expectedValues = new HashMap<Boolean, Boolean>(); for (Performance result : results) { J48 current = (J48) result.m_Classifier; expectedValues.put(current.getUnpruned(), true); } verifyExpectedValues(expectedValues, 2); assertEquals(expectedValues.size(), 2); } }
/** * Builds the classifier to generate a partition. */ @Override public void generatePartition(Instances data) throws Exception { buildClassifier(data); }
/** * Returns a string describing classifier * * @return a description suitable for displaying in the explorer/experimenter * gui */ public String globalInfo() { return "Class for generating a pruned or unpruned C4.5 decision tree. For more " + "information, see\n\n" + getTechnicalInformation().toString(); }
public void buildClassifier(Instances instances) throws Exception { getCapabilities().testWithFail(instances);
public static Classifier getClassifier(WekaClassifier classifier) throws IllegalArgumentException { try { 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); } }
/** * Main method for testing this class * * @param argv the commandline options */ public static void main(String[] argv) { runClassifier(new J48(), argv); } }
/** * Builds the classifier to generate a partition. */ @Override public void generatePartition(Instances data) throws Exception { buildClassifier(data); }
/** * Returns a string describing classifier * * @return a description suitable for displaying in the explorer/experimenter * gui */ public String globalInfo() { return "Class for generating a pruned or unpruned C4.5 decision tree. For more " + "information, see\n\n" + getTechnicalInformation().toString(); }
public void buildClassifier(Instances instances) throws Exception { getCapabilities().testWithFail(instances);
/** * Default constructor. */ public RegressionByDiscretization() { m_Classifier = new weka.classifiers.trees.J48(); }
public static Classifier getClassifier(WekaClassifier classifier) throws IllegalArgumentException { try { 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); } }
/** * Returns the value of the named measure * * @param additionalMeasureName the name of the measure to query for its value * @return the value of the named measure * @throws IllegalArgumentException if the named measure is not supported */ @Override public double getMeasure(String additionalMeasureName) { if (additionalMeasureName.compareToIgnoreCase("measureNumRules") == 0) { return measureNumRules(); } else if (additionalMeasureName.compareToIgnoreCase("measureTreeSize") == 0) { return measureTreeSize(); } else if (additionalMeasureName.compareToIgnoreCase("measureNumLeaves") == 0) { return measureNumLeaves(); } else { throw new IllegalArgumentException(additionalMeasureName + " not supported (j48)"); } }
//Learning DataSource source = new DataSource(Path); Instances data = source.getDataSet(); J48 tree = tree.buildClassifier(data); //Evaluation Evaluation eval = new Evaluation(data); eval.evaluateModel(tree, data); System.out.println((eval.correct()/data.numInstances())*100);