gpt4 book ai didi

python - scipy.cluster.hierarchy.dendrogram() : exactly what does truncate_mode ='level' do?

转载 作者:行者123 更新时间:2023-12-04 08:06:54 29 4
gpt4 key购买 nike

documentation表示,“显示的树状图树的级别不超过 p。“级别”包括上次合并中具有 p 合并的所有节点。” (p 是另一个参数)我搞不懂“p merges from the last merge”是什么意思。谁能解释一下?

(我使用 truncate_mode='level'truncate_mode='lastp' 创建了相同数据的树状图;我没有发现比较有启发性。)

最佳答案

以下代码演示了 truncate_mode='level'truncate_mode='lastp':

from scipy.cluster import hierarchy
import matplotlib.pyplot as plt
import numpy as np

np.random.seed(1729)
ytdist = np.random.randint(1, 1000, 36)

Z = hierarchy.linkage(ytdist, 'single')
fig, ax_rows = plt.subplots(ncols=6, nrows=2, sharey=True, figsize=(16, 5))

for ax_row, truncate_mode in zip(ax_rows, ['level', 'lastp']):
hierarchy.dendrogram(Z, ax=ax_row[0])
ax_row[0].set_title('default, no truncation')
for ind, ax in enumerate(ax_row[1:]):
if truncate_mode == 'level':
p = len(ax_row) - ind - 1
else:
p = len(ax_row) - ind
hierarchy.dendrogram(Z, truncate_mode=truncate_mode, p=p, ax=ax)
ax.set_title(f"truncate_mode='{truncate_mode}', p={p}")
plt.tight_layout()
plt.show()

comparison plot

关于python - scipy.cluster.hierarchy.dendrogram() : exactly what does truncate_mode ='level' do?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66180002/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com