I have read many examples of using this library in Java, and clustering is possible from the ARFF data file, and it works.
But I have my data in the List of double, which is generated when working with my program, and I do not know how to use this k-means algorithm to cluster my data. This is a one-dimensional list.
This is my code:
Instances dataa = DataSource.read("C:\\Users\\Ew\\Documents\\iris.arff");
kMeans = new SimpleKMeans();
kMeans.setNumClusters(3);
kMeans.buildClusterer(dataa);
Instances centroids = kMeans.getClusterCentroids();
for (int i = 0; i < centroids.numInstances(); i++) {
System.out.println( "Centroid " + i+1 + ": " + centroids.instance(i));
}
for (int i = 0; i < dataa.numInstances(); i++) {
System.out.println( dataa.instance(i) + " is in cluster " + kMeans.clusterInstance(dataa.instance(i)) + 1);
}
I am reading data from iris.arff file and it works. Now I want to specify the k-value of my List of double as a parameter. How can i do this?
Thanks in advance for your answers.
Sincerely.
source
share