从Rpy2向R聚类的进给距离矩阵 [英] feeding distance matrix to R clustering from Rpy2
本文介绍了从Rpy2向R聚类的进给距离矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在numpy/scipy中具有以下定制的NxN距离矩阵:
I have the following custom made NxN distance matrix in numpy/scipy:
dist_matrix = array([array([5, 4, 2, 3, 2, 3]),
array([4, 5, 2, 3, 2, 2]),
array([2, 2, 5, 2, 2, 1]),
array([3, 3, 2, 5, 4, 2]),
array([2, 2, 2, 4, 5, 1]),
array([3, 2, 1, 2, 1, 5])])
如何使用此矩阵进行分层聚类并在R/ggplot2中绘制树状图?如果我尝试通过rpy2将此距离矩阵输入R:
how can I use this matrix to do hierarchical clustering and plot dendrograms in R / ggplot2? If I try to feed this distance matrix into R via rpy2 as:
r.hclust(dist_matrix)
我得到了错误:
res = super(Function, self).__call__(*new_args, **new_kwargs)
rpy2.rinterface.RRuntimeError: Error in if (is.na(n) || n > 65536L) stop("size cannot be NA nor exceed 65536") :
missing value where TRUE/FALSE needed
推荐答案
R函数 hclust()
正在获取距离"对象:
The R function hclust()
is taking "distance" objects:
from rpy2.robjects.packages import importr
stats = importr("stats")
d = stats.as_dist(m)
hc = r.hclust(d)
[注意:错误消息也暗示rpy2中可能存在转换错误.您可以提交错误报告吗?谢谢]
[note: the error message is also hinting at a possible conversion bug in rpy2. Can you file a bug report ? Thanks]
这篇关于从Rpy2向R聚类的进给距离矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文