If you have a dataset with classes, which is an unusual case for unsupervised learning, Weka has a method called clustering from classes. In this method, Weka first ignores the class attribute and generates the clustering. Then during the test phase, it assigns classes to the clusters based on the majority value of the class attribute within each cluster. We will cover this method in this recipe.
In this recipe, we will use a dataset with class values for instances. We will use a
weather.nominal.arff
file, which can be found in the data directory of the installed Weka directory.In our code, we will have two instance variables. The first variable will contain the instances of our dataset and the second variable will contain an Expectation-Minimization clusterer:
Instances weather = null; EM clusterer;
Next, we will be loading our dataset, reading it, and setting the last index as its class index:
public void loadArff...