K-Means Program
K-Means Program
}
}
ksets[j][p] = cluster[i];
break;
}
}
}
System.out.println("================= ksets ============");
for (int i = 0; i < k; i++) {
System.out.println("for set k" + (i + 1));
for (int j = 0; j < n; j++) {
if (ksets[i][j] > 0) {
System.out.print(ksets[i][j] + ",");
}
}
System.out.println(" ");
}
int count = 0;
double temp = 0.0;
for (int i = 0; i < k; i++) {
for (int j = 0; j < n; j++) {
if (ksets[i][j] > 0.0) {
count = count + 1;
}
}
for (int j = 0; j < n; j++) {
Output
run:
enter number of items in the cluster9
enter the item in the cluster
2
enter the item in the cluster
4
enter the item in the cluster
10
enter the item in the cluster
12
enter the item in the cluster
3
enter the item in the cluster
20
enter the item in the cluster
30
enter the item in the cluster
11
enter the item in the cluster
25
enter k value
2
the means are
2.0
4.0
================= ksets ============
for set k1
2.0,3.0,
for set k2
4.0,10.0,12.0,20.0,30.0,11.0,25.0,
means are 2.5means are 16.0================================
================= ksets ============
for set k1
2.0,4.0,3.0,
for set k2
10.0,12.0,20.0,30.0,11.0,25.0,
means are 3.0means are 18.0================================
================= ksets ============
for set k1
2.0,4.0,10.0,3.0,
for set k2
12.0,20.0,30.0,11.0,25.0,
means are 4.75means are 19.6================================
================= ksets ============
for set k1
2.0,4.0,10.0,12.0,3.0,11.0,
for set k2
20.0,30.0,25.0,
means are 7.0means are 25.0================================
================= ksets ============
for set k1
2.0,4.0,10.0,12.0,3.0,11.0,
for set k2
20.0,30.0,25.0,
means are 7.0means are 25.0================================
BUILD SUCCESSFUL (total time: 7 minutes 13 seconds)