List of usage examples for weka.clusterers HierarchicalClusterer numberOfClusters
@Override public int numberOfClusters() throws Exception
From source file:gr.iit.demokritos.cru.cps.ai.KeyphraseClustering.java
License:Open Source License
public ArrayList<String> getClusters() throws Exception { System.out.println("Clustering......"); // int[] clusters_size = new int[clusters]; HierarchicalClusterer cl = new HierarchicalClusterer(); // EM em=new EM(); // XMeans xm = new XMeans(); no nominal attributes // DBSCAN db= new DBSCAN(); not our distance function // CascadeSimpleKMeans c = new CascadeSimpleKMeans(); not our distance function cl.setNumClusters(this.clusters); if (language.equals("en")) { // cl.setDistanceFunction(wd); //xm.setDistanceF(wd); cl.setDistanceFunction(wd);/*from w w w . j a v a 2s . co m*/ } else if (language.equals("de")) { cl.setDistanceFunction(wdde); //c.setDistanceFunction(wdde); //xm.setDistanceF(wdde); } else if (language.equals("el")) { cl.setDistanceFunction(wdel); //c.setDistanceFunction(wdel); // xm.setDistanceF(wdel); } cl.buildClusterer(data); //xm.buildClusterer(data); //c.setMaxIterations(5); ArrayList<String> clustersList = new ArrayList<String>(); for (int i = 0; i < cl.numberOfClusters(); i++) { clustersList.add(""); } //cl.buildClusterer(data); //em.buildClusterer(data); // xm.buildClusterer(data); for (int j = 0; j < data.numInstances(); j++) { //double[] prob = c.distributionForInstance(data.instance(j)); //double[] prob = cl.distributionForInstance(data.instance(j)); String clusterLine = data.instance(j).stringValue(0); int clust = cl.clusterInstance(data.instance(j)); clustersList.set(clust, clustersList.get(clust).concat(clusterLine + ";")); //take the probabilities prob[i] that it is in the coresponding cluster i /*for (int i = 0; i < prob.length; i++) { //keep the cluster that has prob>0.9, as this is the cluster that the word is in if (prob[i] > 0.9) { //keep for every cluster its terms clustersList.set(i, clustersList.get(i).concat(clusterLine + ";")); //keep the size of cluster i // clusters_size[i] = clusters_size[i] + 1; } }*/ } return clustersList; }
From source file:wekimini.InputGenerator.java
public void selectHiClusters() throws Exception { buildDataset();/*from w w w . j a v a 2s. c om*/ HierarchicalClusterer clusterer = new HierarchicalClusterer(); clusterer.setLinkType(new SelectedTag(1, HierarchicalClusterer.TAGS_LINK_TYPE)); clusterer.buildClusterer(dataset); logger.log(Level.SEVERE, "EM options: ", clusterer.getOptions()); logger.log(Level.SEVERE, "EM numCluster tip text: ", clusterer.numClustersTipText()); logger.log(Level.SEVERE, "EM debug tip text: ", clusterer.debugTipText()); logger.log(Level.SEVERE, "EM info: ", clusterer.globalInfo()); int num = clusterer.numberOfClusters(); String txt = Integer.toString(num); logger.log(Level.SEVERE, "EM numberOfClusters: ", txt); String text = Integer.toString(numClusters); logger.log(Level.SEVERE, "EM numClusters: ", text); }