开发者

How do I find the parameters used in kmeans to create clusters?

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 m开发者_JS百科y 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?


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...


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?)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜