- [R K均值初始化 [英] R kmeans initialization

查看:198
本文介绍了 - [R K均值初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在R编程环境,我目前使用的标准实施 k均值算法(类型:帮助(k均值))。看来,我不能初始化开始重心。我指定了 k均值算法,给我4簇,我想通过起始质心的向量的坐标。

  1. k均值的实现,让我渡过最初的质心坐标?
解决方案

是的。你提到的实现允许你指定起始位置。您可以通过中心通过他们在参数

 >的DAT&所述;  -  data.frame(X = RNORM(99,平均= C(-5,0,5))中,y = RNORM(99,平均= C(-5,0,5)))
>图(DAT)
>开始&所述;  - 矩阵(三(-5,0,5,-5,0,5),3,2)
> K均值(DAT,开始)
K-均值聚类3簇大小的33,33,33

集群方式:
           X Y
1 -5.0222798 -5.06545689
2 -0.1297747 -0.02890204
3 4.8006581 5.00315151

集群载体:
 [1] 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2
[51] 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3

在广场通过集群的集群和:
[1] 58.05137 73.81878 52.45732
 (between_SS / total_SS = 94.7%)

组件:

[1]集群,中心,totsswithinsstot.withinssbetweenss
[7]大小
 

In the R programming environment, I am currently using the standard implementation of the kmeans algorithm (type: help(kmeans)). It appears that I cannot initialize the starting centroids. I specify the kmeans algorithm to give me 4 clusters and I would like to pass the vector coordinates of the starting centroids.

  1. Is there an implementation of kmeans to allow me to pass initial centroid coordinates?

解决方案

Yes. The implementation you mention allows you to specify starting positions. You pass them in through the centers parameter

> dat <- data.frame(x = rnorm(99, mean = c(-5, 0 , 5)), y = rnorm(99, mean = c(-5, 0, 5)))
> plot(dat)
> start <- matrix(c(-5, 0, 5, -5, 0, 5), 3, 2)
> kmeans(dat, start)
K-means clustering with 3 clusters of sizes 33, 33, 33

Cluster means:
           x           y
1 -5.0222798 -5.06545689
2 -0.1297747 -0.02890204
3  4.8006581  5.00315151

Clustering vector:
 [1] 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2
[51] 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3

Within cluster sum of squares by cluster:
[1] 58.05137 73.81878 52.45732
 (between_SS / total_SS =  94.7 %)

Available components:

[1] "cluster"      "centers"      "totss"        "withinss"     "tot.withinss" "betweenss"   
[7] "size"  

这篇关于 - [R K均值初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆