Clustering Algorithms are called unsupervised learning in data mining, which is opposite to supervised learning. Semi-Supervised Learning)
The general process of clustering algorithms is divided:
- 1. Read the sample to be predicted
- 2. initialize the clustering algorithm (and set parameters)
- 3. Cluster samples using Clustering Algorithms
- 4. Print the clustering result
Instance:
Package weka2; import Java. io. file; import WEKA. clusterers. simplekmeans; import WEKA. core. distancefunction; import WEKA. core. euclideandistance; import WEKA. core. instances; import WEKA. core. converters. arffloader; public class simplecluster {public static void main (string [] ARGs) {// todo auto-generated method stub instances ins = NULL; instances tempins = NULL; simplekmeans Km = NULL; distancefunction disfun = NULL; try {/** 1. read sample */file = new file ("D: \ work \ WEKA-3-6 \ data \ contact-lenses.arff"); arffloader loader = new arffloader (); loader. setfile (File); ins = loader. getdataset ();/** 2. initialize the clustering tool * in version 3.6, you can use setdistancefunction (distancefunction DF) * function setting the distance calculation method within the clustering algorithm * in version 3.5, the default Euclidean distance */Km = new simplekmeans () is used (); // set the number of categories to be obtained for clustering. setnumclusters (2);/** 3. use a clustering algorithm to cluster samples */km. buildclusterer (INS);/** 4. print the clustering result */tempins = km. getclustercentroids (); system. out. println ("centroids:" + tempins);} catch (exception e) {e. printstacktrace ();}}}
Simplekmean is the simplest kmeans algorithm, because the core of the clustering algorithm is to get classes by distance (classes are different and similar within classes ), therefore, we need a formula for calculating the distance. The common formula is Euclidean distance. In WEKA 3.5, other distance formulas are not considered. The simplekmean distance calculation method defaults to Euclidean distance. In WEKA 3.6, we provided the setdistancefunction (distancefunction DF) interface for us to set our own distance calculation method.
In this paper: http://anqiang1900.blog.163.com/blog/static/11418886420093631322170/
WEKA Learning (Clustering Algorithm)