LoginSignup
0
0

More than 1 year has passed since last update.

メモ - scipy デンドログラムのインデックスを取得する

Posted at

version

scipy: v1.6.3

コード

scipy.cluster.hierarchy.leaves_list()を使う

以下をリンクより引用
https://docs.scipy.org/doc/scipy/reference/generated/scipy.cluster.hierarchy.leaves_list.html

from scipy.cluster.hierarchy import ward, dendrogram, leaves_list
from scipy.spatial.distance import pdist
from matplotlib import pyplot as plt
X = [[0, 0], [0, 1], [1, 0],
     [0, 4], [0, 3], [1, 4],
     [4, 0], [3, 0], [4, 1],
     [4, 4], [3, 4], [4, 3]]
Z = ward(pdist(X))
leaves_list(Z)
>>> array([ 2,  0,  1,  5,  3,  4,  8,  6,  7, 11,  9, 10], 
    dtype=int32)
fig = plt.figure(figsize=(25, 10))
dn = dendrogram(Z)
plt.show()

image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0