A clustering algorithm creates a division of the orginal dataset. In Java-ML this is done with the method cluster of the Clusterer interface.
Creating and running a clustering algorithm
- /* Load a dataset */
- Dataset data = FileHandler.loadDataset(new File("iris.data"), 4, ",");
- /* Create a new instance of the KMeans algorithm, with no options
- * specified. By default this will generate 4 clusters. */
- Clusterer km = new KMeans();
- /* Cluster the data, it will be returned as an array of data sets, with
- * each dataset representing a cluster. */
- Dataset clusters = km.cluster(data);
The code above will load the example iris data set. Next it creates an instance of the K-means algorithms and uses it to cluster the data. The results are returned in an array of Datasets where each Dataset represents a cluster.
Note that there is no guarantee that all original Instances will occur in the clusters or that each Instance occurs only once. Some algorithms allow overlapping clusters, some algorithms allow that 'noisy' datapoints are removed. This is algorithm specific and you can find more information on the API page for each algorithm.