def get_k(clustering, depth = 10):
"""
(ndarray, int) -> int
clustering: ndarray -- linkage matrix representing hierarchical clustering
depth: int -- the maximum depth to traverse clustering
Returns the number of clusters to extract from the hierarchical clustering
using the elbow method.
"""
last = clustering[-depth: , 2]
acceleration = np.diff(last, 2)
acceleration_rev = acceleration[::-1]
k = acceleration_rev.argmax() + 2
return k
评论列表
文章目录