Example #1
0
 public static void main(String[] args) {
   int i, j;
   int n, k, dim;
   kMeans cluster;
   Scanner sc = new Scanner(System.in);
   k = sc.nextInt();
   n = sc.nextInt();
   dim = sc.nextInt();
   Point[] tmpPoints = new Point[n];
   for (i = 0; i < n; i++) {
     double[] num = new double[dim];
     for (j = 0; j < dim; j++) num[j] = sc.nextDouble();
     tmpPoints[i] = new Point(dim, num);
   }
   cluster = new kMeans(k, tmpPoints);
   cluster.getCluster();
   // calculate the sse value after clustering
   cluster.sseValue = 0.0;
   for (i = 0; i < n; i++) {
     cluster.sseValue +=
         cluster.points[i].distEuclid(cluster.centroids[cluster.points[i].clusterIndex]);
   }
   System.out.println("The SSE of after clustering is: " + cluster.sseValue);
   /*
   int[] clusterCount = new int[k];
   for(i = 0; i < k; i++){
   	clusterCount[i] = 0;
   }
   for(i = 0; i < cluster.points.length; i++){
   	clusterCount[cluster.points[i].clusterIndex]++;
   	//System.out.print(cluster.points[i].clusterIndex);
   	//System.out.print("  ");
   }
   System.out.println("  ");
   for(i = 0; i < k; i++){
   	System.out.println(clusterCount[i]);
   }
        */
 }