如何找到 kmeans 中用于创建集群的参数?
从之前 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
kmeans
帮助页面的 Value 部分列出了函数返回的对象的格式:一般来说,您还可以使用
names
函数直接从您的kmeans
对象列出这些值:根据帮助页面中值的描述,我会说使用的参数聚类结果不存储在结果对象中。因此,如果您只能访问结果
kmeans
对象,而不能访问原始函数调用,那么不幸的是,我会说这些参数丢失了......The Value section of the
kmeans
help page lists the format of the object returned byt he function :In general you can also list these values directly from your
kmeans
object with thenames
function :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...如果您输入
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?)