Java examples for Machine Learning AI:weka
do Cluster with Weka
import weka.clusterers.ClusterEvaluation; import weka.clusterers.EM; import weka.core.Instances; import weka.core.Utils; import weka.core.converters.ConverterUtils.DataSource; public class WekaCluster { public static void main(String[] args) throws Exception { DataSource source = new DataSource( "bank-train.arff"); Instances instancesTrain = source.getDataSet(); source = new DataSource( "bank-test.arff"); Instances instancesTest = source.getDataSet(); String[] options = Utils.splitOptions("-I 100"); EM cluster = new EM(); cluster.setOptions(options);/*from w ww. ja v a 2 s. c o m*/ cluster.buildClusterer(instancesTrain); ClusterEvaluation eval = new ClusterEvaluation(); eval.setClusterer(cluster); eval.evaluateClusterer(instancesTest); System.out.println(eval.getNumClusters()); System.out.println(eval.clusterResultsToString()); } }