I have a Java Program that will cluster coordinates into 2 groups using K-Means algorithm which I found from here. I have succeeded in getting the clustered elements in each group, but I'm not sure how to retrieve the centroid position of each cluster.
This is my program:
import java.util.List;
import com.aliasi.util.Arrays;
import java.util.ArrayList;
public class PrgMain {
public static List cent = new ArrayList();
public static void main (String args[]){
List<DataPoint> dataPoints = new ArrayList<DataPoint>();
dataPoints.add(new DataPoint(22,21,"p53"));
dataPoints.add(new DataPoint(19,20,"bcl2"));
dataPoints.add(new DataPoint(18,22,"fas"));
dataPoints.add(new DataPoint(1,3,"amylase"));
dataPoints.add(new DataPoint(2,2,"maltase"));
JCA jca = new JCA(2,1000,dataPoints);
jca.startAnalysis();
int i = 0;
Centroid cen = null;
for (List<DataPoint> tempV : jca.getClusterOutput()){
System.out.println("-----------Cluster"+(i+1)+"---------");
for (DataPoint dpTemp : tempV){
System.out.println(dpTemp.getObjName()+
"["+dpTemp.getX()+"," +dpTemp.getY()+"]");
cen = new Centroid(dpTemp.getX(), dpTemp.getY());
}
i++;
System.out.println("Centroid for cluster "+ (i)+": ");
// Here's where I want to retrieve the centroid:
System.out.println(cen.getCx()+", "+ cen.getCy());
}
}
}
Is there a way that I can retrieve the centroid position after clustering?