Creating a List of Clusters. This can be done manually (e.g. create a set of randomly placed clusters). A convenience function initialClusters exists that takes in the list of Instances already created and randomly generates clusters from the instances such that instances more distant to the previous cluster are more likely to seed the next cluster.

List<Cluster> clusters = initialClusters(3, instances, seed: 0);

Running the algorithm using the kmeans function. This is a side-effect heavy function that iteratively shifts the clusters towards the mean position of the associated instances and reassigns instances to the nearest cluster.