我正在处理一组来自几个不同采样站(站)的物种计数(计数)。我使用scikit bio的pw_距离函数计算了每对可能的样本站之间的Bray-Curtis相似性。这将生成一个值在0和1之间的距离矩阵。到现在为止,一直都还不错。在
我想用这个距离矩阵来生成一个树状图,显示样本站是如何聚集在一起的。我用的是西皮的等级联系函数查找树状图的链接,然后用层次结构图. 在
我的代码是:
from skbio.diversity.beta import pw_distances
from scipy.cluster import hierarchy
bc_dm = pw_distances(counts, stations, metric = "braycurtis")
# use (1 - bc_dm) to get similarity rather than dissimilarity
sim = 1 - bc_dm.data
Z = hierarchy.linkage(sim, 'ward')
hierarchy.dendrogram(
Z,
leaf_rotation=0., # rotates the x axis labels
leaf_font_size=10., # font size for the x axis labels
labels=bc_dm.ids,
orientation="left"
)
here is a link to the dendrogram produced by the above code
据我所知,树状图上的距离应该对应于Bray-Curtis的相似性(类似于距离),但是我的树状图上的距离值最大值超过30。这是对的吗?如果没有,我如何调整我的距离以符合样本站之间的布雷-柯蒂斯相似性?如果是正确的,那么树状图上的距离到底对应什么?在
当他们回答你的问题时,请查看评论中共享的链接。在
这些链接中没有涉及的}上调用链接。这将获得您所需格式的输入。如果你传递一个二维矩阵,
scikit-bio
步骤是您应该在bc_dm.condensed_form()
上调用链接,而不是在bc_dm
或{linkage
假设它是你的counts
矩阵,并根据这些数据计算样本之间的欧几里德距离。在另外,一定要注意
method
参数到scipy.cluster.hierarchy.linkage
,因为这将影响对树状图中分支长度的解释。scipy.cluster.hierarchy.linkage
的doc字符串包含有关如何为不同方法计算这些值的详细信息。在相关问题 更多 >
编程相关推荐