Weka clustering

Clustering algorithms from Weka can be accessed in Java-ML through the WekeClusterer bridge. This class makes it easy to use a clustering algorithm from Weka in Java-ML.

In the example below, we load the iris dataset, we create a clusterer from Weka (XMeans), we wrap it in the bridge and use the bridge to do the clustering.

  1. /* Load data */
  2. Dataset data = FileHandler.loadDataset(new File("iris.data"), 4, ",");
  3. /* Create Weka classifier */
  4. XMeans xm = new XMeans();
  5. /* Wrap Weka clusterer in bridge */
  6. Clusterer jmlxm = new WekaClusterer(xm);
  7. /* Perform clustering */
  8. Dataset[] clusters = jmlxm.cluster(data);
  9. /* Output results */
  10. System.out.println(clusters.length);

[Documented source code]