Java kmeans implementation (jar package download and use + algorithm introduction + Source Code Introduction)

Source: Internet
Author: User

Data mining jobs need to be clustered. The kmeans function of OpenCV is used to generate various random results. It is easy to write kmeans on your own, so you have written a kmeans jar package, which can take the initial cluster center randomly or in order, output parameter information, clustering of each vertex, and central coordinates of each clustering. The parameter structure is a bit similar to the kmeans of OpenCV. I think the architecture is good and I posted it for sharing.

1. download and use kmeans. jar
2. Introduction to kmeans Algorithms
3. Source Code Introduction

1. download and use kmeans. jar
: Https://sourceforge.net/projects/yuanboshekmeans/files/
Kmeans. jar is the application package, kmeans_src.jar is the source code package, and kmeans_full.jar contains both.

Create a java project, introduce the kmeans. jar package (reference without reference), add the class with the main function, and then add the test code to the main function.

1 import kmeans. *; 2 3 public class jmain {4 public static void main (String [] args) {5 double [] [] points = {0, 0}, {4, 10 },{ 1, 1 },{ 5, 8 }}; // test data, four 2D points 6 kmeans_data data = new kmeans_data (points, 4, 2 ); // initialize the data structure 7 kmeans_param param = new kmeans_param (); // initialize the parameter structure 8 param. initcentermehtodd = kmeans_param.CENTER_RANDOM; // set the initialization mode of the cluster center to random mode 9 10 // perform kmeans calculation. There are two types of 11 kmeans. doKmeans (2, data, param); 12 13 // view the cluster ID of each vertex 14 System. out. print ("The labels of points is:"); 15 for (int lable: data. labels) {16 System. out. print (lable + ""); 17} 18} 19}

The running result is:

k=2attempts=2criteriaBreakCondition=0.0The number of each classes are: 2 2 The labels of points is: 0  1  0  1  

It indicates that the two clusters are divided into two categories and are iterated twice. Each of the two clusters contains two vertices. the last row indicates that the first and 3rd vertices are clusters of No. 0, the second and fourth vertices are cluster 1.
For more information and usage, see the source code section.

[Go Top]

Ii. kmeans Algorithm
(To be continued)

[Go Top]

Iii. Source Code Introduction

(To be continued)

[Go Top]

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.