聚类排名

发布于 2025-02-04 04:38:27 字数 114 浏览 6 评论 0原文

我正在分析R中的数据,其中预测变量可用,但没有响应变量。使用无监督的学习(K-均值),我已经确定了数据中的模式。但是我需要根据集群的整体表现进行对(例如:学生在考试标记和课外标记上的数据)。聚类在R中使用什么技术?

I'm analyzing a data in R where predictor variables are available but there is no response variable. Using unsupervised learning (k-means) I have identified patterns in the data. But I need to rank the clusters according to their overall performance (example: student's data on exam marks and co-curricular marks). What technique do I use after clustering in R?

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

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

发布评论

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

评论(1

可是我不能没有你 2025-02-11 04:38:27

cluster kmeans输出的属性为您提供了每个数据点所在的群集的索引。从kmeans文档中获取的示例数据:

nclusters = 5
# a 2-dimensional example
x <- rbind(matrix(rnorm(100, sd = 0.3), ncol = 2),
           matrix(rnorm(100, mean = 1, sd = 0.3), ncol = 2))
colnames(x) <- c("x", "y")

cl <- kmeans(x, nclusters, nstart = 25)

现在,您的评估功能(例如,您的评估功能列值)可以单独应用于每个群集:

for (i in 1:nclusters){
    cat(i, apply(x[which(cl$cluster==i),],MARGIN=2,FUN=mean), '\n')
}

或者更好的是,请使用某种聚合功能,例如tapply gentreg> gentregate ,例如:

aggregate(x, by=list(cluster=cl$cluster), FUN=mean)

  cluster          x          y
1       1  1.2468266  1.1499059
2       2 -0.2787117  0.0958023
3       3  0.5360855  1.0217910
4       4  1.0997776  0.7175210
5       5  0.2472313 -0.1193551

在这一点上应该给您您能够根据需要对聚合函数的值进行排名。

The cluster attribute of the kmeans output gives you the index of which cluster each data point is in. Example data taken from kmeans documentation:

nclusters = 5
# a 2-dimensional example
x <- rbind(matrix(rnorm(100, sd = 0.3), ncol = 2),
           matrix(rnorm(100, mean = 1, sd = 0.3), ncol = 2))
colnames(x) <- c("x", "y")

cl <- kmeans(x, nclusters, nstart = 25)

Now, your evaluation function (e.g. mean of column values) can be applied to each cluster individually:

for (i in 1:nclusters){
    cat(i, apply(x[which(cl$cluster==i),],MARGIN=2,FUN=mean), '\n')
}

Or better still, use some kind of aggregation function, e.g. tapply or aggregate, e.g.:

aggregate(x, by=list(cluster=cl$cluster), FUN=mean)

which gives

  cluster          x          y
1       1  1.2468266  1.1499059
2       2 -0.2787117  0.0958023
3       3  0.5360855  1.0217910
4       4  1.0997776  0.7175210
5       5  0.2472313 -0.1193551

At this point you should be able to rank the values of the aggregation function as needed.

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