如何找到 kmeans 中用于创建集群的参数?

发布于 2024-10-21 13:19:08 字数 387 浏览 3 评论 0原文

从之前 R 列表中的问题来看,我看到了两种检查加载的包的方法:

ls("package:ts") 
lsf.str("package:ts")

在我的例子中,我想检查 kmeans 的输出是什么,它是 stats 包中的一个函数,所以我使用:

lsf.str("package:stats")

但是,我不知道如何检查此命令返回的内容。我想识别先前聚类中使用的参数,以便我可以将它们应用到另一个数据集。在哪里可以找到作为该函数的一部分存储的参数?

From a previous question on the R-list, I saw two approaches for examining packages that are loaded in:

ls("package:ts") 
lsf.str("package:ts")

In my case, I want to examine what the output of kmeans is, which is a function in the stats package, so I used:

lsf.str("package:stats")

However, I don't know how to examine what is returned from this command. I want to identify the parameters used in a previous clustering, so that I can apply them to another dataset. Where I can find the parameters that are stored as part of this function?

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

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

发布评论

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

评论(2

宣告ˉ结束 2024-10-28 13:19:09

kmeans 帮助页面的 Value 部分列出了函数返回的对象的格式:

“kmeans”类的对象,具有“print”方法,并且是
包含组件的列表:

簇:整数向量(来自
'1:k') 指示集群
每个点都被分配。

centers:聚类中心矩阵。

withinss:簇内总和
每个簇的正方形。

totss:簇内总和
正方形。

tot.withinss:簇内总和
的正方形,即
'总和(withinss)'。

Betweenss:簇间总和
正方形。

大小:每个簇中的点数。

一般来说,您还可以使用 names 函数直接从您的 kmeans 对象列出这些值:

R> names(km)
[1] "cluster"      "centers"      "totss"        "withinss"    
[5] "tot.withinss" "betweenss"    "size"      

根据帮助页面中值的描述,我会说使用的参数聚类结果不存储在结果对象中。因此,如果您只能访问结果 kmeans 对象,而不能访问原始函数调用,那么不幸的是,我会说这些参数丢失了......

The Value section of the kmeans help page lists the format of the object returned byt he function :

An object of class ‘"kmeans"’ which has a ‘print’ method and is a
list with components:

cluster: A vector of integers (from
‘1:k’) indicating the cluster to
which each point is allocated.

centers: A matrix of cluster centres.

withinss: The within-cluster sum of
squares for each cluster.

totss: The total within-cluster sum
of squares.

tot.withinss: Total within-cluster sum
of squares, i.e.,
‘sum(withinss)’.

betweenss: The between-cluster sum of
squares.

size: The number of points in each cluster.

In general you can also list these values directly from your kmeans object with the names function :

R> names(km)
[1] "cluster"      "centers"      "totss"        "withinss"    
[5] "tot.withinss" "betweenss"    "size"      

From the description of the values in the help page, I would say that the parameters used for the clustering are not stored in the resulting object. So if you only have access to the resulting kmeans object and not to the original function call, I would say that these parameters are lost, unfortunately...

泼猴你往哪里跑 2024-10-28 13:19:09

如果您输入 kmeans,您将获得该方法的源代码,可在位于 http:// /pastebin.com/6VnnhU7J 。我不确定你对参数的意思,因为这些参数是作为参数传入的 (x, center, iter.max = 10, nstart = 1, algorithm = c("Hartigan-Wong", "Lloyd", "Forgy" 、“MacQueen”)并且您可以轻松访问它们(您最初用什么来称呼 kmeans ?)

If you type in kmeans you'll get the sourcecode of the method, available in pastebin at http://pastebin.com/6VnnhU7J . I'm not sure what you mean about the parameters as those are passed in as arguments (x, centers, iter.max = 10, nstart = 1, algorithm = c("Hartigan-Wong", "Lloyd", "Forgy", "MacQueen") and you have easy access to them (what did you call kmeans with originally?)

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