R中的K-均值聚类分析

发布于 2025-01-29 15:00:42 字数 1081 浏览 3 评论 0原文

我正在尝试根据相对稀疏的数据框/矩阵(下图)以图形方式可视化单个群集。我不确定为什么要继续遇到以下错误:

  cannot rescale a constant/zero column to unit variance`

这是我在此分析中使用的代码段。


library(cluster)
library(factoextra)
library(gridExtra)

kmeans2 = kmeans(df, centers=1, nstart=5) # df (see table below) contains probabilities

fviz_cluster(kmeans2, data=df, scale=F) # Visualize the cluster

这是上面代码中使用的数据框(“ DF”)。您可能已经注意到,大多数值接近0。是否有任何调整/转换能够成功执行群集分析?

           a          b          c          d         e          f          g          h          i           j
 0.06906453 0.01083181 0.01627455 0.03762042 0.1144168 0.01529368 0.03265494 0.08005074 0.08902436 0.003516431
           k         l         m          n         o          p            q          r          s         t
 0.01686642 0.0410222 0.0133853 0.07202466 0.0890314 0.01146801 0.0002297176 0.04715371 0.07463133 0.1023295
           u           v          w            x          y            z
 0.02023235 0.005822369 0.02169929 0.0003092351 0.01494907 9.718769e-05

I'm trying to graphically visualize a single cluster based on a relatively sparse dataframe/matrix (below). I'm not sure why I keep getting the following error:

  cannot rescale a constant/zero column to unit variance`

Here is the code snippet that I have used in this analysis.


library(cluster)
library(factoextra)
library(gridExtra)

kmeans2 = kmeans(df, centers=1, nstart=5) # df (see table below) contains probabilities

fviz_cluster(kmeans2, data=df, scale=F) # Visualize the cluster

This is the dataframe ("df") used in the code above. As you may have noticed, most values as close to 0. Is there any adjustment/transformation that I could make to be able to successfully perform a cluster analysis ?

           a          b          c          d         e          f          g          h          i           j
 0.06906453 0.01083181 0.01627455 0.03762042 0.1144168 0.01529368 0.03265494 0.08005074 0.08902436 0.003516431
           k         l         m          n         o          p            q          r          s         t
 0.01686642 0.0410222 0.0133853 0.07202466 0.0890314 0.01146801 0.0002297176 0.04715371 0.07463133 0.1023295
           u           v          w            x          y            z
 0.02023235 0.005822369 0.02169929 0.0003092351 0.01494907 9.718769e-05

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文