generate cluster

lukino
lukino New Altair Community Member
edited November 5 in Community Q&A
Hi togheter, i have a problem.
i don't know how generate the clusters.

this is my code

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());

}
I hope in your help.
Thanks a lot

Answers

  • land
    land New Altair Community Member
    Hi,
    do you want me to guess what your problem is? In general I'm not a god and thus my time is limited. You have to be more specific, otherwise I cannot help you.

    Greetings,
      Sebastian
  • lukino
    lukino New Altair Community Member
    hi sebastian, excuse me if i was unclear.
    so, hi take the attributes from a file .csv and then with this attributes i created a table.
    then with the object table i created an object ExampleSet.
    When i use the object ExampleSet to generate cluster

    // 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());
    the clusters are not generated, and i don't know how to proceed.
    i hope that i explained my problem.
    thanks
  • land
    land New Altair Community Member
    Hi,
    you still need to apply the cluster model to the example set. You have just generated the model, now use an apply model operator (ModelApplier.class) to generate the cluster assignments.

    Greetings,
      Sebastian