import weka.classifiers.Classifier; import weka.classifiers.lazy.IB1; import weka.classifiers.Evaluation; import weka.core.Instances; import weka.core.converters.ConverterUtils.DataSource; /** * * WekaAPISampleClient is a simple demonstration of the Weka API * * It builds a nearest-neighbor model of Fisher's Iris dataset * * Caution: greater care should be taken in evaluation than is shown below (more on this point in class) * * @author ALVAREZ * * * */ public class WekaAPISampleClient { /** * * @param args * */ public static void main(String[] args) throws Exception { /** * * prepare instance data * */ String dataFileName = "iris.arff"; // appropriate path needed here Instances data = (new DataSource(dataFileName)).getDataSet(); data.setClassIndex(data.numAttributes() - 1); /** * * build classifier model * */ Classifier classy = new IB1(); classy.buildClassifier(data); /** * * evaluate classifier model * */ Evaluation eval = new Evaluation(data); eval.evaluateModel(classy, data); // evaluates on training data - very bad idea System.out.println("1-NN performance on " + dataFileName + ":\n" + eval.toSummaryString()); } }