In this recipe, we will be using the KMeans algorithm to cluster or group data points of a dataset together.
We will be using the cpu dataset to cluster its data points based on a simple KMeans algorithm. The cpu dataset can be found in the
data
directory of the installed folder in the Weka directory.We will be having two instance variables as in the previous recipes. The first variable will be containing the data points of the cpu dataset, and the second variable will be our Simple KMeans clusterer:
Instances cpu = null; SimpleKMeans kmeans;
Then, we will be creating a method to load the cpu dataset, and to read its contents. Please note that as clustering is an unsupervised method, we do not need to specify the class attribute of our dataset:
public void loadArff(String arffInput){ DataSource source = null; try { source = new DataSource(arffInput...