如何在java中实现k-means进行简单分组

发布于 2024-08-24 08:48:10 字数 155 浏览 6 评论 0原文

我想知道java中的简单k-means算法。我只想使用 k-means 来对一维数组而不是多维数组进行分组。 例如, 分组前数组由 2,4,7,5,12,34,18,25 组成 如果我们想要四组然后我们得到 第 1 组:2,4,5 第 2 组:7,12 第 3 组:18,25 第 4 组:34

I would like to know simple k-means algorithm in java. I want to use k-means only for grouping 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 group then we got
group 1: 2,4,5
group 2: 7,12
group 3: 18,25
group 4: 34

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

猫卆 2024-08-31 08:48:10

您可以查看 Weka 实现 或直接使用 Weka如果您需要的只是集群而不是实现,则使用 API。

You can take a look at the Weka implementation or simply use the Weka API if all you need are the clusters and not the implementation.

静谧 2024-08-31 08:48:10

维基百科页面上提供了 K-means 聚类的标准(启发式)算法,以及变体和一些现有实现的链接。

(这是编程论坛,因此可以合理地假设您有能力自己编写 Java 代码......如果您找不到合适的现有实现。)

The standard (heuristic) algorithm for K-means clustering is presented on the Wikipedia page, together with links to variations and some existing implementations.

(This is programming forum, so it is reasonable to assume that you are capable of writing Java code yourself ... if you cannot find an existing implementation that it is suitable.)

回首观望 2024-08-31 08:48:10
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++;
}
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++;
}
阳光下慵懒的猫 2024-08-31 08:48:10

你可以查看我的软件:SPMF数据挖掘软件

它仅用 3 个文件就提供了 KMeans 的高效实现,因此应该很容易理解。

该软件还提供许多其他算法。但你不需要它们。

但另一件事是,还有一个图形用户界面用于启动 KMeans 和其他算法。

You can check my software : SPMF data mining software.

It offers an efficient implementation of KMeans in just 3 files so it should be easy to understand.

The software also offers many other algorithms. But you don't need them.

But another thing is that there is also a graphical user interface for launching KMeans and the other algorithms.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文