public static J48 ByARFF(string ARFF, string count) { java.io.StringReader ArffReader = new java.io.StringReader(ARFF); ArffLoader.ArffReader ARFFData = new ArffLoader.ArffReader(ArffReader, Convert.ToInt32(count), true); Instances structure = ARFFData.getStructure(); structure.setClassIndex(structure.numAttributes() - 1); Instance inst; while ((inst = ARFFData.readInstance(structure)) != null) { structure.add(inst); } //Instances data = ARFFData.getData(); //J48 cls = new J48(); //cls.buildClassifier(data); //String[] options = new String[1]; //options[0] = "-U"; // unpruned tree J48 tree = new J48(); // new instance of tree //tree.setOptions(options); // set the options tree.buildClassifier(structure); // build classifier return(tree); }
public static J48 ByHeaderAndData(string header, string dataARFF) { java.io.StringReader ArffReader = new java.io.StringReader(header); ArffLoader.ArffReader ARFFData = new ArffLoader.ArffReader(ArffReader, 100, false); Instances structure = ARFFData.getStructure(); structure.setClassIndex(structure.numAttributes() - 1); ArffReader = new java.io.StringReader(dataARFF); Instances data = ARFFData.getData(); Instance inst; while ((inst = ARFFData.readInstance(data)) != null) { structure.add(inst); } J48 tree = new J48(); // new instance of tree tree.buildClassifier(structure); // build classifier return(tree); }