Package mia.classifier.ch15

Source Code of mia.classifier.ch15.ConfusionMatrixExample

package mia.classifier.ch15;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.mahout.classifier.ConfusionMatrix;

public class ConfusionMatrixExample {
  public static void main(String[] args) throws IOException {
    String inputFile = args[1];
   
    BufferedReader in = new BufferedReader(new FileReader(inputFile));
    List<String> symbols = new ArrayList<String>();
    String line = in.readLine();
    while (line != null) {
      String[] pieces = line.split(",");
      if (!symbols.contains(pieces[0])) {
        symbols.add(pieces[0]);
      }
      line = in.readLine();
    }

    ConfusionMatrix x2 = new ConfusionMatrix(symbols, "unknown");

    in = new BufferedReader(new FileReader(inputFile));
    line = in.readLine();
    while (line != null) {
      String[] pieces = line.split(",");        
      String trueValue = pieces[0];
      String estimatedValue = pieces[1];
      x2.addInstance(trueValue, estimatedValue);     
      line = in.readLine();
    }
    System.out.printf("%s\n\n", x2.toString());
  }
}
TOP

Related Classes of mia.classifier.ch15.ConfusionMatrixExample

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.