How to implement k-tool for simple grouping in java

I would like to know a simple k-mean algorithm in java. I want to use k-tools only to group a one-dimensional array, not multi. For example, before grouping, the array consists of 2,4,7,5,12,34,18,25 if we want four groups, then we got group 1: 2,4,5 group 2: 7,12 group 3: 18, 25 group 4: 34

+3
source share
4 answers

() K- Wikipedia .

( , , Java... , ).

+1
You can implement k-Means as:
SimpleKMeans kmeans = new SimpleKMeans();

kmeans.setSeed(10);

// This is the important parameter to set
kmeans.setPreserveInstancesOrder(true);
kmeans.setNumClusters(numberOfClusters);
kmeans.buildClusterer(instances);

 // This array returns the cluster number (starting with 0) for each instance
 // The array has as many elements as the number of instances
 int[] assignments = kmeans.getAssignments();

 int i=0;
 for(int clusterNum : assignments) {
System.out.printf("Instance %d -> Cluster %d", i, clusterNum);
i++;
}
+1

: SPMF.

KMeans 3 , .

. .

, KMeans .

0

Source: https://habr.com/ru/post/1736077/


All Articles