I have a dataset with each instance having a single attribute value, and need to apply clustering on it. Java-ML (Java Machine Learning Library) seemed suitable to me for this task. But I found that the class "Dataset" in it is structured as a set of instances which is structured as a set of attributes and a class label. My problem is that I have a single attribute for each instance and no class label.
Here is a sample code that I tried and unexpectedly the execution doesn't end once it starts clustering.
int k;
Dataset dataset = new DefaultDataset();
double[] val= {5,6,15,20,40,50,55,73};
for(int i = 0; i < val.length; i++) {
Instance instance= new SparseInstance(1);
instance.put(1, val[i]);
dataset.add(instance);
}
k = 3;
Clusterer km = new KMeans(k);
System.out.println(dataset);
Dataset[] clusters = km.cluster(dataset);
System.out.println(dataset);
for(int i = 0; i < k; i++) {
System.out.println(clusters[i]+"\n\n\n\n");
}
I am unable to understand the reason behind such an unexpected behavior. Is there any other library that suits my work more than Java-ML?
Thanks in advance.