WEKA Learning (Clustering Algorithm)

Source: Internet
Author: User

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. 1. Read the sample to be predicted
  2. 2. initialize the clustering algorithm (and set parameters)
  3. 3. Cluster samples using Clustering Algorithms
  4. 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.