R k-means算法定制中心 [英] R k-means algorithm custom centers

查看:105
本文介绍了R k-means算法定制中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个以R-(x,y)坐标导入的2D数据集.我想对该数据集执行k均值聚类,但我想将具体坐标设置为初始中心.例如,我想从5个中心开始,其值为(5, 10), (3, 8), (46, 22), (87, 66), (39, 41).

I have a 2D dataset imported in R - (x,y) coordinates. I want to perform k-means clustering on this dataset, but I would like to set concrete coordinates to be initial centers. For example, I would like to start with 5 centers with their values to be (5, 10), (3, 8), (46, 22), (87, 66), (39, 41) .

我在kmeans函数中看到了一个center参数,但是我不明白如何将我的值设置为centeres.

I saw a centers parameter in kmeans function, but I do not understand how to set my values to be centeres.

kmeans(data, centers = ...) # what to set here?

推荐答案

centers参数采用整数k,在这种情况下,选择data中的k随机点作为初始中心,或者初始中心的矩阵,其列与data一样多.试试这个:

The centers parameter takes either an integer k, in which case k random points from data are chosen as initial centers, or a matrix of initial centers, with as many columns as data. Try this:

x <- rbind(matrix(rnorm(100, sd = 0.3), ncol = 2),
                 matrix(rnorm(100, mean = 1, sd = 0.3), ncol = 2))
kmeans(x,centers=3)
kmeans(x,centers=x[1:3,])

这篇关于R k-means算法定制中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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