List of usage examples for weka.clusterers SimpleKMeans SimpleKMeans
public SimpleKMeans()
From source file:soccer.core.ASimplePractice.java
public void evaluate() throws IOException, Exception { Instances data = loader.getInstances(); SimpleKMeans cluster = new SimpleKMeans(); cluster.setNumClusters(4);/*from w w w .ja v a2 s . c o m*/ cluster.buildClusterer(data); ClusterEvaluation eval = new ClusterEvaluation(); eval.setClusterer(cluster); eval.evaluateClusterer(data); System.out.println(eval.clusterResultsToString()); }
From source file:soccer.core.classifiers.BookKeeperConsistencyClassifier.java
public static void main(String[] args) throws Exception { BookKeeperConsistency bkc = new BookKeeperConsistency(); Instances data = bkc.getInstances(); RemoveWithValues rwv = new RemoveWithValues(); rwv.setOptions(new String[] { "-C", "4", "-S", "6", "-V" }); rwv.setInputFormat(data);//from w ww . j a va2 s . com data = Filter.useFilter(data, rwv); RemoveWithValues rwv1 = new RemoveWithValues(); rwv1.setOptions(new String[] { "-C", "6", "-S", "6", "-V" }); rwv1.setInputFormat(data); data = Filter.useFilter(data, rwv1); // Normalize nm = new Normalize(); // nm.setOptions(new String[]{ // "-S", "100" // }); // nm.setInputFormat(data); // data = Filter.useFilter(data, nm); Remove rm = new Remove(); rm.setOptions(new String[] { "-R", "2-last" }); rm.setInputFormat(data); Instances newData = Filter.useFilter(data, rm); SimpleKMeans cluster = new SimpleKMeans(); cluster.setOptions(new String[] { "-N", "2", "-A", "weka.core.ManhattanDistance" }); cluster.buildClusterer(newData); ClusterEvaluation eval = new ClusterEvaluation(); eval.setClusterer(cluster); eval.evaluateClusterer(newData); System.out.println(eval.clusterResultsToString()); // for (int i = 0; i < newData.size(); i++) { // Instance instance = newData.get(i); // if (cluster.clusterInstance(instance) == 0) { // System.out.println(data.get(i).toString()); // } // } }
From source file:soccer.core.models.PlayerModel.java
public static void main(String[] args) throws Exception { PlayerModel pm = new PlayerModel(); Instances data = pm.buildInstance(); SimpleKMeans cluster = new SimpleKMeans(); cluster.setNumClusters(4);//w w w . j ava 2 s.c o m cluster.buildClusterer(data); ClusterEvaluation eval = new ClusterEvaluation(); eval.setClusterer(cluster); eval.evaluateClusterer(data); System.out.println(eval.clusterResultsToString()); }
From source file:swm.project.mappings.UserToUserCluster.java
private void clusterUserHistoryWithKmeans() throws FileNotFoundException, IOException, Exception { Reader reader;/*from w ww . j a v a 2s . c o m*/ userToUserClusterHistory = new HashMap<>(); userClustersToUsersHistory = new HashMap<>(); reader = new FileReader(MappingConstants.USER_MOVIE_CLUSTERS); Instances instanceValues = new Instances(reader); SimpleKMeans kmeans = new SimpleKMeans(); kmeans.setNumClusters(20); kmeans.setPreserveInstancesOrder(true); kmeans.setDistanceFunction(new EuclideanDistance()); kmeans.buildClusterer(instanceValues); int[] assignments = kmeans.getAssignments(); int userid = 0; for (int clusterNo : assignments) { int user = (int) instanceValues.get(userid).value(0); userToUserClusterHistory.put(user, clusterNo); ArrayList<Integer> users = new ArrayList<>(); if (userClustersToUsersHistory.containsKey(clusterNo)) { users = userClustersToUsersHistory.get(clusterNo); users.add(user); } else { users.add(user); userClustersToUsersHistory.put(clusterNo, users); } userid++; } }
From source file:tr.gov.ulakbim.jDenetX.experiments.wrappers.EvalActiveBoostingID.java
License:Open Source License
public Instances clusteredInstances(Instances data) { if (data == null) { throw new NullPointerException("Data is null at clusteredInstances method"); }/*from w ww .j av a2 s . co m*/ Instances sampled_data = data; for (int i = 0; i < sampled_data.numInstances(); i++) { sampled_data.remove(i); } SimpleKMeans sKmeans = new SimpleKMeans(); data.setClassIndex(data.numAttributes() - 1); Remove filter = new Remove(); filter.setAttributeIndices("" + (data.classIndex() + 1)); List assignments = new ArrayList(); try { filter.setInputFormat(data); Instances dataClusterer = Filter.useFilter(data, filter); String[] options = new String[3]; options[0] = "-I"; // max. iterations options[1] = "500"; options[2] = "-O"; sKmeans.setNumClusters(data.numClasses()); sKmeans.setOptions(options); sKmeans.buildClusterer(dataClusterer); System.out.println("Kmeans\n:" + sKmeans); System.out.println(Arrays.toString(sKmeans.getAssignments())); assignments = Arrays.asList(sKmeans.getAssignments()); } catch (Exception e) { e.printStackTrace(); } System.out.println("Assignments\n: " + assignments); ClusterEvaluation eval = new ClusterEvaluation(); eval.setClusterer(sKmeans); try { eval.evaluateClusterer(data); } catch (Exception e) { e.printStackTrace(); } int classesToClustersMap[] = eval.getClassesToClusters(); for (int i = 0; i < classesToClustersMap.length; i++) { if (assignments.get(i).equals(((Integer) classesToClustersMap[(int) data.get(i).classValue()]))) { ((Instances) sampled_data).add(data.get(i)); } } return ((Instances) sampled_data); }
From source file:tubes2.Main.java
/** * @param args the command line arguments */// ww w . j av a 2 s . c o m public static void main(String[] args) throws IOException, Exception { // TODO code application logic here String filename = "weather"; //Masih belum mengerti tipe .csv yang dapat dibaca seperti apa //CsvToArff convert = new CsvToArff(filename+".csv"); //LOAD FILE BufferedReader datafile = readDataFile("data/" + filename + ".arff"); Instances data = new Instances(datafile); ArrayList<Integer> numericIdx = new ArrayList<Integer>(); for (int i = 0; i < data.numAttributes(); i++) { if (data.attribute(i).isNumeric()) { numericIdx.add(i); } } System.out.println(); System.out.println("\n----SEBELUM NORMALISASI-----"); System.out.println(data); normalizeData(data, numericIdx); System.out.println("\n----SETELAH NORMALISASI-----"); System.out.println(data); //END OF LOAD FILE SimpleKMeans simpleK = new SimpleKMeans(); simpleK.setNumClusters(4); Clusterer[] clusterers = { simpleK, new myKMeans(4), new myAgnes(4) }; boolean first = true; for (Clusterer clusterer : clusterers) { try { clusterer.buildClusterer(data); System.out.println("\n\n----HASIL CLUSTERING-----"); System.out.println(clusterer); } catch (Exception ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:wekimini.InputGenerator.java
public void selectKmClusters(int numClusters) throws Exception { buildDataset();/*from w w w . jav a2 s . c om*/ SimpleKMeans km = new SimpleKMeans(); km.setNumClusters(numClusters); km.buildClusterer(dataset); clusters = km.getClusterCentroids(); addKmClustersToTraining(); }