List of usage examples for weka.clusterers DBSCAN clusterInstance
public int clusterInstance(Instance instance) throws Exception
From source file:nlpmusic.StringClusterer.java
public ArrayList<ArrayList<String>> cluster(ArrayList<String> tem) throws Exception { Instances source = listLoad(tem);//from w w w . j a va 2s . c om StringToWordVector vect = new StringToWordVector(); vect.setWordsToKeep(to_keep); vect.setInputFormat(source); Instances datas = Filter.useFilter(source, vect); //vect.setDoNotOperateOnPerClassBasis(true); //System.out.println("ASDASD" + vect.wordsToKeepTipText()); //System.out.println(datas.numAttributes()); //System.out.println("ASDASD" + vect.getWordsToKeep()); DBSCAN clusterer = new DBSCAN(); clusterer.setEpsilon(threshold); clusterer.setMinPoints(min_points); clusterer.buildClusterer(datas); ArrayList<ArrayList<String>> ret = new ArrayList<>(); for (int i = 0; i < clusterer.numberOfClusters(); i++) { ArrayList<String> to_add = new ArrayList<>(); //System.out.println(i); for (int j = 0; j < datas.size(); j++) { try { if (clusterer.clusterInstance(datas.get(j)) == i) //System.out.println("* " + source.get(j).toString() + " *"); to_add.add(source.get(j).toString()); } catch (Exception e) { //e.printStackTrace(); } } ret.add(to_add); } return ret; }