List of usage examples for org.apache.mahout.classifier.df DecisionForest classify
public double classify(Dataset dataset, Random rng, Instance instance)
From source file:guipart.view.Utils.java
static void rfTestFile(Path inPath, Path outPath, DataConverter converter, DecisionForest forest, Dataset dataset, Collection<double[]> results, Random rng, FileSystem outFS, FileSystem dataFS, GUIPart guiPart) throws IOException { // create the predictions file FSDataOutputStream ofile = null;/* www . j a va2s . c o m*/ String gender; if (outPath != null) { ofile = outFS.create(outPath); } FSDataInputStream input = dataFS.open(inPath); try { Scanner scanner = new Scanner(input, "UTF-8"); while (scanner.hasNextLine()) { String line = scanner.nextLine(); if (line.isEmpty()) { continue; // skip empty lines } System.out.println(line); String[] split = line.split(","); if (split[1].contentEquals("1")) gender = "male"; else gender = "female"; Instance instance = converter.convert(line); double prediction = forest.classify(dataset, rng, instance); boolean booltemp = prediction != 0; System.out.println("Preditction: " + prediction); if (ofile != null) { ofile.writeChars(Double.toString(prediction)); // write the prediction ofile.writeChar('\n'); } Person temp = new Person(Integer.parseInt(split[0]), Integer.parseInt(split[4]), Integer.parseInt(split[7]), booltemp, gender, Integer.parseInt(split[5]), Integer.parseInt(split[6]), Integer.parseInt(split[3])); guiPart.addPerson(temp); results.add(new double[] { dataset.getLabel(instance), prediction }); } scanner.close(); } finally { Closeables.close(input, true); } }
From source file:imageClassify.TestForest.java
License:Apache License
private void testFile(Path inPath, Path outPath, DataConverter converter, DecisionForest forest, Dataset dataset, Collection<double[]> results, Random rng) throws IOException { // create the predictions file FSDataOutputStream ofile = null;/*from w ww .ja v a 2s. c o m*/ if (outPath != null) { ofile = outFS.create(outPath); } FSDataInputStream input = dataFS.open(inPath); try { Scanner scanner = new Scanner(input, "UTF-8"); while (scanner.hasNextLine()) { String line = scanner.nextLine(); if (line.isEmpty()) { continue; // skip empty lines } Instance instance = converter.convert(line); double prediction = forest.classify(dataset, rng, instance); if (ofile != null) { ofile.writeChars(Double.toString(prediction)); // write the prediction ofile.writeChar('\n'); } results.add(new double[] { dataset.getLabel(instance), prediction }); } scanner.close(); } finally { Closeables.close(input, true); } }
From source file:javaapplication3.RunRandomForestSeq.java
private static void testFile(Path inPath, Path outPath, DataConverter converter, DecisionForest forest, Dataset dataset, Collection<double[]> results, Random rng, FileSystem outFS, FileSystem dataFS) throws IOException { // create the predictions file FSDataOutputStream ofile = null;// w ww. j a v a2 s . co m if (outPath != null) { ofile = outFS.create(outPath); } FSDataInputStream input = dataFS.open(inPath); try { Scanner scanner = new Scanner(input, "UTF-8"); while (scanner.hasNextLine()) { String line = scanner.nextLine(); if (line.isEmpty()) { continue; // skip empty lines } Instance instance = converter.convert(line); double prediction = forest.classify(dataset, rng, instance); if (ofile != null) { ofile.writeChars(Double.toString(prediction)); // write the prediction ofile.writeChar('\n'); } results.add(new double[] { dataset.getLabel(instance), prediction }); } scanner.close(); } finally { Closeables.close(input, true); } }