R kmeans 初始化 [英] R kmeans initialization

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

问题描述

在R编程环境中,我目前使用的是kmeans算法的标准实现(类型:help(kmeans)).看来我无法初始化起始质心.我指定 kmeans 算法给我 4 个簇,我想传递起始质心的矢量坐标.

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. 是否有 kmeans 的实现允许我传递初始质心坐标?
  1. Is there an implementation of kmeans to allow me to pass initial centroid coordinates?

推荐答案

是的.您提到的实现允许您指定起始位置.您通过 centers 参数传入它们

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 kmeans 初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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