A program to recognize and reward our most engaged community members
public void example() throws NumberFormatException, IOException, ClassNotFoundException, OperatorException{ BufferedReader input = new BufferedReader(new FileReader("patternss.csv")); while ((line = input.readLine()) != null) { split = line.split(","); pattern = split[0]; supp = new double[4]; for (int i = 1; i < split.length; i++ ) { supp[i-1] = Double.parseDouble(split); } mapPattern.put(pattern, supp); } int j=0; attributes = new LinkedList<Attribute>(); for (String namePattern : mapPattern.keySet()) { for ( int a = 1; a < split.length; a++) { attributes.add(AttributeFactory.createAttribute ("supp["+j+"]" + " : " + mapPattern.get(namePattern)[a-1], Ontology.REAL)); j++; } } label = AttributeFactory.createAttribute ("label", Ontology.NOMINAL); attributes.add(label); // create table MemoryExampleTable table = new MemoryExampleTable(attributes); for (int i=1; i<split.length; i++) { for (String namePattern : mapPattern.keySet()) { data = new double[attributes.size()]; for ( int a = 1; a < attributes.size(); a++) { // fill with proper data here data = mapPattern.get(namePattern)[i-1]; } // maps the nominal classification to a double value data[data.length - 1] = label.getMapping().mapString(namePattern); // add data row table.addDataRow(new DoubleArrayDataRow(data)); } } // create example set ExampleSet exampleSet = table.createExampleSet(label); exampleSet.getAttributes().setId(label); System.out.println(exampleSet.getAttributes().getId()); System.out.println(exampleSet.getAttributes()); OperatorDescription opDesc = new OperatorDescription(CreatingExampleTables.class.getClassLoader(), "Cluster", CreatingExampleTables.class.getName(), "Clustering with DBScan", null, "gruppi", null, null); DBScan scan = new DBScan(opDesc); scan.setParameter("min_points", Double.toString(5));scan.setParameter("epsilon", Double.toString(0.1)); ClusterModel cluster = scan.generateClusterModel(exampleSet); System.out.println(cluster.getClusters()); }
// create example set ExampleSet exampleSet = table.createExampleSet(label); exampleSet.getAttributes().setId(label);OperatorDescription opDesc = new OperatorDescription(CreatingExampleTables.class.getClassLoader(), "Cluster", CreatingExampleTables.class.getName(), "Clustering with DBScan", null, "gruppi", null, null); DBScan scan = new DBScan(opDesc); scan.setParameter("min_points", Integer.toString(5));scan.setParameter("epsilon", Double.toString(0.1)); ClusterModel cluster = scan.generateClusterModel(exampleSet); System.out.println(cluster.getClusters());